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.
 
 
 

339 line
8.1 KiB

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