You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

341 rivejä
8.2 KiB

  1. //
  2. // Lol Engine — EasyMesh tutorial
  3. //
  4. // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. namespace lol
  14. {
  15. enum
  16. {
  17. IPT_MV_KBOARD = 0,
  18. IPT_MV_MOUSE,
  19. INPUT_MAX
  20. };
  21. enum MVKeyboardList
  22. {
  23. KEY_CAM_RESET = 0,
  24. KEY_CAM_POS,
  25. KEY_CAM_FOV,
  26. KEY_CAM_UP,
  27. KEY_CAM_DOWN,
  28. KEY_CAM_LEFT,
  29. KEY_CAM_RIGHT,
  30. KEY_MESH_NEXT,
  31. KEY_MESH_PREV,
  32. KEY_F1,
  33. KEY_F2,
  34. KEY_F3,
  35. KEY_F4,
  36. KEY_F5,
  37. KEY_ESC,
  38. KEY_MAX
  39. };
  40. enum MVMouseKeyList
  41. {
  42. MSE_CAM_ROT = KEY_MAX,
  43. MSE_CAM_POS,
  44. MSE_CAM_FOV,
  45. MSE_FOCUS,
  46. MSE_MAX
  47. };
  48. enum MVMouseAxisList
  49. {
  50. MSEX_CAM_Y = 0,
  51. MSEX_CAM_X,
  52. MSEX_MAX
  53. };
  54. #define MAX_KEYS MSE_MAX
  55. #define MAX_AXIS MSEX_MAX
  56. //MeshViewerInput ---------------------------------------------------------
  57. struct MeshViewerKeyInputBase : public StructSafeEnum
  58. {
  59. enum Type
  60. {
  61. KBD_BEG = 0,
  62. Exit = KBD_BEG,
  63. KBD_END,
  64. MSE_BEG = KBD_END,
  65. LeftClick = MSE_BEG,
  66. RightClick,
  67. MiddleClick,
  68. Focus,
  69. MSE_END,
  70. MAX = MSE_END,
  71. };
  72. protected:
  73. virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
  74. {
  75. enum_map[Exit] = g_name_key_Escape;
  76. enum_map[LeftClick] = g_name_mouse_key_left;
  77. enum_map[RightClick] = g_name_mouse_key_right;
  78. enum_map[MiddleClick] = g_name_mouse_key_middle;
  79. enum_map[Focus] = g_name_mouse_key_in_screen;
  80. return true;
  81. }
  82. };
  83. typedef SafeEnum<MeshViewerKeyInputBase> MeshViewerKeyInput;
  84. #define ALL_FEATURES 1
  85. #define NO_SC_SETUP 0
  86. enum GizmoType
  87. {
  88. GZ_Editor = 0,
  89. GZ_LightPos,
  90. GZ_LightDir,
  91. GZ_MAX
  92. };
  93. struct LightData
  94. {
  95. LightData(vec3 pos, vec4 col)
  96. {
  97. m_pos = pos;
  98. m_col = col;
  99. }
  100. vec3 m_pos;
  101. vec4 m_col;
  102. };
  103. //ViewerObject ----------------------------------------------------------------
  104. class ViewerObject
  105. {
  106. public:
  107. ViewerObject() { }
  108. ViewerObject(String const& name) : m_name(name) { }
  109. virtual ~ViewerObject() { }
  110. virtual void TickDraw(float seconds, Scene &scene) { }
  111. String GetName() { return m_name; }
  112. protected:
  113. String m_name;
  114. };
  115. //EasyMeshViewerObject --------------------------------------------------------
  116. class EasyMeshViewerObject : public ViewerObject
  117. {
  118. typedef ViewerObject super;
  119. public:
  120. EasyMeshViewerObject()
  121. : ViewerObject() { }
  122. EasyMeshViewerObject(String const& name, EasyMesh const& mesh)
  123. : ViewerObject(name)
  124. {
  125. Init(name, mesh);
  126. }
  127. virtual ~EasyMeshViewerObject() { }
  128. virtual void TickDraw(float seconds, Scene &scene);
  129. void Init(String const& name, EasyMesh const& mesh)
  130. {
  131. m_name = name;
  132. m_mesh = mesh;
  133. }
  134. protected:
  135. EasyMesh m_mesh;
  136. };
  137. //MeshViewerLoadJob -----------------------------------------------------------
  138. class MeshViewerLoadJob : public ThreadJob
  139. {
  140. friend class BaseThreadManager;
  141. typedef ThreadJob super;
  142. public:
  143. inline MeshViewerLoadJob() : ThreadJob() { }
  144. inline MeshViewerLoadJob(String const& path)
  145. : ThreadJob(ThreadJobType::WORK_TODO), m_path(path) { }
  146. virtual ~MeshViewerLoadJob() { }
  147. virtual void RetrieveResult(class MeshViewer* app) { }
  148. protected:
  149. virtual bool DoWork() { return super::DoWork(); }
  150. protected:
  151. String m_path;
  152. };
  153. //EasyMeshLoadJob -------------------------------------------------------------
  154. class EasyMeshLoadJob : public MeshViewerLoadJob
  155. {
  156. friend class BaseThreadManager;
  157. typedef EasyMeshLoadJob super;
  158. public:
  159. inline EasyMeshLoadJob() : MeshViewerLoadJob() { }
  160. inline EasyMeshLoadJob(String const& path)
  161. : MeshViewerLoadJob(path) { }
  162. virtual ~EasyMeshLoadJob() { }
  163. static MeshViewerLoadJob* GetInstance(String const& path);
  164. virtual void RetrieveResult(class MeshViewer* app);
  165. protected:
  166. static bool Check(String const& path) { return path.contains(".easymesh"); }
  167. virtual bool DoWork();
  168. protected:
  169. EasyMeshLuaLoader m_loader;
  170. array<EasyMeshViewerObject*> m_meshes;
  171. };
  172. //MeshViewer ------------------------------------------------------------------
  173. class MeshViewer : public WorldEntity
  174. {
  175. typedef WorldEntity super;
  176. public:
  177. MeshViewer(char const *file_name = "../data/meshviewer.easymesh.lua");
  178. ~MeshViewer();
  179. void Start();
  180. void Stop();
  181. void UpdateSceneSetup(bool only_destroy = false);
  182. MeshViewerLoadJob* GetLoadJob(String const& path);
  183. void AddViewerObj(ViewerObject* obj) { m_objs << obj; }
  184. virtual void TickGame(float seconds);
  185. virtual void TickDraw(float seconds, Scene &scene);
  186. bool KeyReleased(MVKeyboardList index);
  187. bool KeyPressed(MVKeyboardList index);
  188. bool KeyDown(MVKeyboardList index);
  189. bool KeyReleased(MVMouseKeyList index);
  190. bool KeyPressed(MVMouseKeyList index);
  191. bool KeyDown(MVMouseKeyList index);
  192. float AxisValue(MVMouseAxisList index);
  193. void Prepare();
  194. void Unprepare();
  195. void Update(float seconds);
  196. void Draw(float seconds, Scene &scene);
  197. private:
  198. //Main stuff --------------------------------------------------------------
  199. bool m_init = false;
  200. bool m_first_tick = false;
  201. InputProfile m_profile;
  202. Camera* m_camera = nullptr;
  203. Text* m_text = nullptr;
  204. //ImGui stuff
  205. bool m_menu_cam_useage = true;
  206. float m_menu_cam_fov = radians(40.f);
  207. vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f);
  208. int m_menu_mesh_idx = 0;
  209. array<char*> m_menu_mesh_names_char;
  210. array<String> m_menu_mesh_names_str;
  211. //Scene setup data
  212. SceneSetupLuaLoader m_ssetup_loader;
  213. FileUpdateStatus* m_ssetup_file_status = nullptr;
  214. String m_ssetup_file_name;
  215. String m_ssetup_name;
  216. map<String, SceneSetup*> m_ssetups;
  217. //File data
  218. String m_file_name;
  219. FileUpdateStatus* m_file_status;
  220. //Object data
  221. array<ViewerObject*> m_objs;
  222. //Entities listing
  223. array<Entity*> m_entities;
  224. //Input
  225. Controller* m_controller = nullptr;
  226. //Thread stuff
  227. FileUpdateTester* m_file_check = nullptr;
  228. DefaultThreadManager* m_file_loader = nullptr;
  229. //OLD ---------------------------------------------------------------------
  230. SceneSetup* m_ssetup = nullptr;
  231. array<LightData> m_light_datas;
  232. short m_input_usage;
  233. mat4 m_mat;
  234. mat4 m_mat_prev;
  235. //Camera Setup
  236. float m_reset_timer;
  237. float m_fov;
  238. float m_fov_mesh;
  239. float m_fov_speed;
  240. float m_zoom;
  241. float m_zoom_mesh;
  242. float m_zoom_speed;
  243. vec2 m_rot;
  244. vec2 m_rot_mesh;
  245. vec2 m_rot_speed;
  246. vec2 m_pos;
  247. vec2 m_pos_mesh;
  248. vec2 m_pos_speed;
  249. vec2 m_hist_scale;
  250. vec2 m_hist_scale_mesh;
  251. vec2 m_hist_scale_speed;
  252. vec2 m_screen_offset;
  253. //Mesh update timer
  254. float m_build_timer;
  255. float m_build_time;
  256. //Mesh infos
  257. vec2 m_render_max;
  258. int m_mesh_render;
  259. int m_mesh_id;
  260. float m_mesh_id1;
  261. array<EasyMesh*, EasyMesh*> m_meshes;
  262. array<EasyMesh*> m_gizmos;
  263. //File data
  264. array<String> m_cmdlist;
  265. float m_stream_update_time;
  266. float m_stream_update_timer;
  267. //misc datas
  268. Shader * m_texture_shader;
  269. TileSet * m_default_texture;
  270. Texture * m_texture;
  271. ShaderUniform m_texture_uni;
  272. };
  273. } /* namespace lol */