Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

223 Zeilen
6.6 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  5. // (c) 2013 Sam Hocevar <sam@hocevar.net>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #pragma once
  12. //
  13. // The Scene setup class
  14. // ----------------
  15. //
  16. namespace lol
  17. {
  18. //-----------------------------------------------------------------------------
  19. class SceneSetup
  20. {
  21. friend class SceneSetupLuaLoader;
  22. friend class SceneSetupLuaObject;
  23. public:
  24. //CTor/DTor
  25. SceneSetup() : SceneSetup("default") { }
  26. SceneSetup(String const& name);
  27. ~SceneSetup();
  28. static char const *GetName() { return "<scenesetup>"; }
  29. //--
  30. bool Startup();
  31. bool Shutdown(bool destroy=false);
  32. //-- Setup command
  33. void AddLight(LightType type);
  34. void SetupScene();
  35. //-- main funcs
  36. void SetPosition(vec3 const& v);
  37. void SetLookAt(vec3 const& v);
  38. void SetColor(vec4 const& c);
  39. //-------------------------------------------------------------------------
  40. struct DisplayBase : public StructSafeEnum
  41. {
  42. enum Type
  43. {
  44. Gizmo,
  45. Light,
  46. Max
  47. };
  48. protected:
  49. virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
  50. {
  51. enum_map[Gizmo] = "Gizmo";
  52. enum_map[Light] = "Light";
  53. return true;
  54. }
  55. };
  56. typedef SafeEnum<DisplayBase> Display;
  57. void Show(Display const& d);
  58. void Hide(Display const& d);
  59. void Toggle(Display const& d);
  60. protected:
  61. void Set(Display const& d, DisplayFlag const& f);
  62. protected:
  63. //-------------------------------------------------------------------------
  64. struct CommandBase : public StructSafeEnum
  65. {
  66. enum Type
  67. {
  68. AddLight,
  69. SetupScene,
  70. Max
  71. };
  72. protected:
  73. virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
  74. {
  75. enum_map[AddLight] = "AddLight";
  76. enum_map[SetupScene] = "SetupScene";
  77. return true;
  78. }
  79. };
  80. typedef SafeEnum<CommandBase> Command;
  81. public:
  82. //--
  83. String m_name;
  84. Command m_last_cmd;
  85. vec4 m_clear_color;
  86. array<Light *> m_lights;
  87. array<String, String> m_custom_cmd;
  88. bool m_show_gizmo;
  89. bool m_show_lights;
  90. };
  91. //-----------------------------------------------------------------------------
  92. class SceneSetupLuaObject : public LuaObject
  93. {
  94. public:
  95. //-------------------------------------------------------------------------
  96. SceneSetupLuaObject(String& name);
  97. virtual ~SceneSetupLuaObject();
  98. //-------------------------------------------------------------------------
  99. static SceneSetupLuaObject* New(lua_State* l, int arg_nb);
  100. static const LuaObjectLibrary* GetLib();
  101. //-------------------------------------------------------------------------
  102. public:
  103. //-- Setup command
  104. static int AddLight(lua_State* l);
  105. static int SetupScene(lua_State* l);
  106. //-- main funcs
  107. static int SetPosition(lua_State* l);
  108. static int SetLookAt(lua_State* l);
  109. static int SetColor(lua_State* l);
  110. static int Show(lua_State* l);
  111. static int Hide(lua_State* l);
  112. static int Toggle(lua_State* l);
  113. //-- Setup command
  114. void AddLight(LightType type);
  115. void SetupScene();
  116. //-- main funcs
  117. void SetPosition(vec3& v);
  118. void SetLookAt(vec3& v);
  119. void SetColor(vec4& c);
  120. void Show(SceneSetup::Display const& d);
  121. void Hide(SceneSetup::Display const& d);
  122. void Toggle(SceneSetup::Display const& d);
  123. private:
  124. SceneSetup* m_setup = nullptr;
  125. };
  126. //-----------------------------------------------------------------------------
  127. class SceneSetupLuaLoader : public LuaLoader
  128. {
  129. friend class SceneSetupLuaObject;
  130. public:
  131. SceneSetupLuaLoader();
  132. virtual ~SceneSetupLuaLoader();
  133. //Virtual Store lua object ------------------------------------------------
  134. virtual void Store(LuaObject* obj);
  135. array<SceneSetupLuaObject*>& GetInstances();
  136. //-------------------------------------------------------------------------
  137. protected:
  138. static void RegisterSetup(SceneSetup* setup);
  139. static bool GetRegisteredSetups(map<String, SceneSetup*>& setups);
  140. public:
  141. bool GetLoadedSetups(map<String, SceneSetup*>& setups);
  142. private:
  143. static map<String, SceneSetup*> m_setups;
  144. };
  145. /*
  146. addlight { return token::T_ADDLIGHT; }
  147. position { return token::T_OBJPOSITION; }
  148. lookat { return token::T_OBJLOOKAT; }
  149. color { return token::T_OBJCOLOR; }
  150. clearcolor { return token::T_CLEARCOLOR; }
  151. showgizmo { return token::T_SHOWGIZMO; }
  152. showlight { return token::T_SHOWLIGHT; }
  153. custom { return token::T_CUSTOMCMD; }
  154. custom { return token::T_CUSTOMCMD; }
  155. light_command:
  156. T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; }
  157. | T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
  158. uc.m_sstp.m_lights.last()->SetType(LightType($2)); }
  159. | T_ADDLIGHT svv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
  160. uc.m_sstp.m_lights.last()->SetType(FindValue<LightType>($2)); }
  161. ;
  162. setup_command:
  163. T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT")
  164. uc.m_sstp.m_lights.last()->SetPosition(vec3($2[0], $2[1], $2[2])); }
  165. | T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT")
  166. {
  167. } }
  168. | T_OBJCOLOR v4{ if (uc.m_last_cmd == "ADDLIGHT")
  169. uc.m_sstp.m_lights.last()->SetColor(vec4($2[0], $2[1], $2[2], $2[3])); }
  170. | T_OBJCOLOR COLOR{ uint32_t x = $2;
  171. ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
  172. vec4 vv = vec4(v) * (1.f / 255.f);
  173. if (uc.m_last_cmd == "ADDLIGHT")
  174. uc.m_sstp.m_lights.last()->SetColor(vv); }
  175. ;
  176. scene_command:
  177. T_CLEARCOLOR v4{ uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], $2[3]); }
  178. T_CLEARCOLOR v3{ uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], 1.f); }
  179. | T_CLEARCOLOR COLOR{ uint32_t x = $2; ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
  180. uc.m_sstp.m_clear_color = vec4(v) * (1.f / 255.f); }
  181. | T_SHOWGIZMO bv{ uc.m_sstp.m_show_gizmo = $2; }
  182. | T_SHOWLIGHT bv{ uc.m_sstp.m_show_lights = $2; }
  183. ;
  184. custom_command:
  185. T_CUSTOMCMD svv sv{ uc.m_sstp.m_custom_cmd.push($2, $3); }
  186. ;
  187. */
  188. } /* namespace lol */