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.

преди 9 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. //ImGui stuff
  202. bool m_menu_cam_useage = true;
  203. float m_menu_cam_fov = 40.f;
  204. vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f);
  205. int m_menu_mesh_idx = 0;
  206. array<char*> m_menu_mesh_names_char;
  207. array<String> m_menu_mesh_names_str;
  208. //Scene setup data
  209. SceneSetupLuaLoader m_ssetup_loader;
  210. FileUpdateStatus* m_ssetup_file_status = nullptr;
  211. String m_ssetup_file_name;
  212. String m_ssetup_name;
  213. map<String, SceneSetup*> m_ssetups;
  214. //File data
  215. String m_file_name;
  216. FileUpdateStatus* m_file_status;
  217. //Object data
  218. array<ViewerObject*> m_objs;
  219. //Entities listing
  220. array<Entity*> m_entities;
  221. //Input
  222. Controller* m_controller = nullptr;
  223. //Thread stuff
  224. FileUpdateTester* m_file_check = nullptr;
  225. DefaultThreadManager* m_file_loader = nullptr;
  226. //OLD ---------------------------------------------------------------------
  227. SceneSetup* m_ssetup = nullptr;
  228. array<LightData> m_light_datas;
  229. short m_input_usage;
  230. mat4 m_mat;
  231. mat4 m_mat_prev;
  232. //Camera Setup
  233. float m_reset_timer;
  234. float m_fov;
  235. float m_fov_mesh;
  236. float m_fov_speed;
  237. float m_zoom;
  238. float m_zoom_mesh;
  239. float m_zoom_speed;
  240. vec2 m_rot;
  241. vec2 m_rot_mesh;
  242. vec2 m_rot_speed;
  243. vec2 m_pos;
  244. vec2 m_pos_mesh;
  245. vec2 m_pos_speed;
  246. vec2 m_hist_scale;
  247. vec2 m_hist_scale_mesh;
  248. vec2 m_hist_scale_speed;
  249. vec2 m_screen_offset;
  250. //Mesh update timer
  251. float m_build_timer;
  252. float m_build_time;
  253. //Mesh infos
  254. vec2 m_render_max;
  255. int m_mesh_render;
  256. int m_mesh_id;
  257. float m_mesh_id1;
  258. array<EasyMesh*, EasyMesh*> m_meshes;
  259. array<EasyMesh*> m_gizmos;
  260. //File data
  261. array<String> m_cmdlist;
  262. float m_stream_update_time;
  263. float m_stream_update_timer;
  264. //misc datas
  265. Shader * m_texture_shader;
  266. TileSet * m_default_texture;
  267. Texture * m_texture;
  268. ShaderUniform m_texture_uni;
  269. };
  270. } /* namespace lol */