您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

312 行
7.2 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. virtual ~ViewerObject() { }
  107. protected:
  108. };
  109. //EasyMeshViewerObject --------------------------------------------------------
  110. class EasyMeshViewerObject : public ViewerObject
  111. {
  112. public:
  113. EasyMeshViewerObject()
  114. : ViewerObject() { }
  115. EasyMeshViewerObject(EasyMesh const& mesh)
  116. : EasyMeshViewerObject()
  117. {
  118. Init(mesh);
  119. }
  120. virtual ~EasyMeshViewerObject() { }
  121. void Init(EasyMesh const& mesh)
  122. {
  123. m_mesh = mesh;
  124. }
  125. protected:
  126. EasyMesh m_mesh;
  127. };
  128. //MeshViewerLoadJob -----------------------------------------------------------
  129. class MeshViewerLoadJob : public ThreadJob
  130. {
  131. friend class BaseThreadManager;
  132. typedef ThreadJob super;
  133. public:
  134. inline MeshViewerLoadJob() : ThreadJob() { }
  135. inline MeshViewerLoadJob(String const& path)
  136. : ThreadJob(ThreadJobType::WORK_TODO), m_path(path) { }
  137. virtual ~MeshViewerLoadJob() { }
  138. virtual void RetrieveResult(class MeshViewer* app) { }
  139. protected:
  140. virtual bool DoWork() { return super::DoWork(); }
  141. protected:
  142. String m_path;
  143. };
  144. //EasyMeshLoadJob -------------------------------------------------------------
  145. class EasyMeshLoadJob : public MeshViewerLoadJob
  146. {
  147. friend class BaseThreadManager;
  148. typedef EasyMeshLoadJob super;
  149. public:
  150. inline EasyMeshLoadJob() : MeshViewerLoadJob() { }
  151. inline EasyMeshLoadJob(String const& path)
  152. : MeshViewerLoadJob(path) { }
  153. virtual ~EasyMeshLoadJob() { }
  154. static MeshViewerLoadJob* GetInstance(String const& path);
  155. virtual void RetrieveResult(class MeshViewer* app);
  156. protected:
  157. static bool Check(String const& path) { return path.contains(".easymesh"); }
  158. virtual bool DoWork();
  159. protected:
  160. EasyMeshLuaLoader m_loader;
  161. array<EasyMeshViewerObject*> m_meshes;
  162. };
  163. //MeshViewer ------------------------------------------------------------------
  164. class MeshViewer : public WorldEntity
  165. {
  166. typedef WorldEntity super;
  167. public:
  168. MeshViewer(char const *file_name = "data/meshviewer.easymesh.lua");
  169. ~MeshViewer();
  170. void Start();
  171. void Stop();
  172. MeshViewerLoadJob* GetLoadJob(String const& path);
  173. void AddViewerObj(ViewerObject* obj) { m_objs << obj; }
  174. virtual void TickGame(float seconds);
  175. virtual void TickDraw(float seconds, Scene &scene);
  176. bool KeyReleased(MVKeyboardList index);
  177. bool KeyPressed(MVKeyboardList index);
  178. bool KeyDown(MVKeyboardList index);
  179. bool KeyReleased(MVMouseKeyList index);
  180. bool KeyPressed(MVMouseKeyList index);
  181. bool KeyDown(MVMouseKeyList index);
  182. float AxisValue(MVMouseAxisList index);
  183. void Prepare();
  184. void Unprepare();
  185. void Update(float seconds);
  186. void Draw(float seconds, Scene &scene);
  187. private:
  188. //Main stuff --------------------------------------------------------------
  189. bool m_init = false;
  190. bool m_first_tick = false;
  191. InputProfile m_profile;
  192. Camera * m_camera = nullptr;
  193. SceneSetup* m_ssetup = nullptr;
  194. SceneSetupLuaLoader m_setup_loader;
  195. //File data
  196. String m_file_name;
  197. FileUpdateStatus* m_file_status;
  198. //Object data
  199. array<ViewerObject*> m_objs;
  200. //Entities listing
  201. array<Entity*> m_entities;
  202. //Input
  203. Controller* m_controller = nullptr;
  204. //Thread stuff
  205. FileUpdateTester* m_file_check = nullptr;
  206. DefaultThreadManager* m_file_loader = nullptr;
  207. //OLD ---------------------------------------------------------------------
  208. array<LightData> m_light_datas;
  209. short m_input_usage;
  210. mat4 m_mat;
  211. mat4 m_mat_prev;
  212. //Camera Setup
  213. float m_reset_timer;
  214. float m_fov;
  215. float m_fov_mesh;
  216. float m_fov_speed;
  217. float m_zoom;
  218. float m_zoom_mesh;
  219. float m_zoom_speed;
  220. vec2 m_rot;
  221. vec2 m_rot_mesh;
  222. vec2 m_rot_speed;
  223. vec2 m_pos;
  224. vec2 m_pos_mesh;
  225. vec2 m_pos_speed;
  226. vec2 m_hist_scale;
  227. vec2 m_hist_scale_mesh;
  228. vec2 m_hist_scale_speed;
  229. vec2 m_screen_offset;
  230. //Mesh update timer
  231. float m_build_timer;
  232. float m_build_time;
  233. //Mesh infos
  234. vec2 m_render_max;
  235. int m_mesh_render;
  236. int m_mesh_id;
  237. float m_mesh_id1;
  238. array<EasyMesh*, EasyMesh*> m_meshes;
  239. array<EasyMesh*> m_gizmos;
  240. //File data
  241. array<String> m_cmdlist;
  242. float m_stream_update_time;
  243. float m_stream_update_timer;
  244. //misc datas
  245. Shader * m_texture_shader;
  246. TileSet * m_default_texture;
  247. Texture * m_texture;
  248. ShaderUniform m_texture_uni;
  249. };
  250. } /* namespace lol */