CScene.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include "CScene.h"
  2. #include "CProject.h"
  3. #include "WallpaperEngine/FileSystem/FileSystem.h"
  4. using namespace WallpaperEngine::Core;
  5. CScene::CScene (
  6. Scenes::CCamera* camera,
  7. irr::video::SColorf ambientColor,
  8. bool bloom,
  9. irr::f64 bloomStrength,
  10. irr::f64 bloomThreshold,
  11. bool cameraFade,
  12. bool cameraParallax,
  13. irr::f64 cameraParallaxAmount,
  14. irr::f64 cameraParallaxDelay,
  15. irr::f64 cameraParallaxMouseInfluence,
  16. bool cameraPreview,
  17. bool cameraShake,
  18. irr::f64 cameraShakeAmplitude,
  19. irr::f64 cameraShakeRoughness,
  20. irr::f64 cameraShakeSpeed,
  21. irr::video::SColorf clearColor,
  22. Scenes::CProjection* orthogonalProjection,
  23. irr::video::SColorf skylightColor) :
  24. CWallpaper (Type),
  25. m_camera (camera),
  26. m_ambientColor (ambientColor),
  27. m_bloom (bloom),
  28. m_bloomStrength (bloomStrength),
  29. m_bloomThreshold (bloomThreshold),
  30. m_cameraFade (cameraFade),
  31. m_cameraParallax (cameraParallax),
  32. m_cameraParallaxAmount (cameraParallaxAmount),
  33. m_cameraParallaxDelay (cameraParallaxDelay),
  34. m_cameraParallaxMouseInfluence (cameraParallaxMouseInfluence),
  35. m_cameraPreview (cameraPreview),
  36. m_cameraShake (cameraShake),
  37. m_cameraShakeAmplitude (cameraShakeAmplitude),
  38. m_cameraShakeRoughness (cameraShakeRoughness),
  39. m_cameraShakeSpeed (cameraShakeSpeed),
  40. m_clearColor (clearColor),
  41. m_orthogonalProjection (orthogonalProjection),
  42. m_skylightColor (skylightColor)
  43. {
  44. }
  45. CScene* CScene::fromFile (const irr::io::path& filename)
  46. {
  47. json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename));
  48. auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
  49. auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
  50. auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display");
  51. auto ambientcolor_it = jsonFindRequired (*general_it, "ambientcolor", "General section must have ambient color");
  52. auto bloom_it = jsonFindRequired (*general_it, "bloom", "General section must have bloom flag");
  53. auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength");
  54. auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold");
  55. auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade");
  56. auto cameraparallax_it = jsonFindRequired (*general_it, "cameraparallax", "General section must have camera parallax");
  57. auto cameraparallaxamount_it = jsonFindRequired (*general_it, "cameraparallaxamount", "General section must have camera parallax amount");
  58. auto cameraparallaxdelay_it = jsonFindRequired (*general_it, "cameraparallaxdelay", "General section must have camera parallax delay");
  59. auto cameraparallaxmouseinfluence_it = jsonFindRequired (*general_it, "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence");
  60. auto camerapreview_it = jsonFindRequired (*general_it, "camerapreview", "General section must have camera preview");
  61. auto camerashake_it = jsonFindRequired (*general_it, "camerashake", "General section must have camera shake");
  62. auto camerashakeamplitude_it = jsonFindRequired (*general_it, "camerashakeamplitude", "General section must have camera shake amplitude");
  63. auto camerashakeroughness_it = jsonFindRequired (*general_it, "camerashakeroughness", "General section must have camera shake roughness");
  64. auto camerashakespeed_it = jsonFindRequired (*general_it, "camerashakespeed", "General section must have camera shake speed");
  65. auto clearcolor_it = jsonFindRequired (*general_it, "clearcolor", "General section must have clear color");
  66. auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info");
  67. auto skylightcolor_it = jsonFindRequired (*general_it, "skylightcolor", "General section must have skylight color");
  68. CScene* scene = new CScene (
  69. Scenes::CCamera::fromJSON (*camera_it),
  70. WallpaperEngine::Core::atoSColorf (*ambientcolor_it),
  71. *bloom_it,
  72. *bloomstrength_it,
  73. *bloomthreshold_it,
  74. *camerafade_it,
  75. *cameraparallax_it,
  76. *cameraparallaxamount_it,
  77. *cameraparallaxdelay_it,
  78. *cameraparallaxmouseinfluence_it,
  79. *camerapreview_it,
  80. *camerashake_it,
  81. *camerashakeamplitude_it,
  82. *camerashakeroughness_it,
  83. *camerashakespeed_it,
  84. WallpaperEngine::Core::atoSColorf (*clearcolor_it),
  85. Scenes::CProjection::fromJSON (*orthogonalprojection_it),
  86. WallpaperEngine::Core::atoSColorf (*skylightcolor_it)
  87. );
  88. auto cur = (*objects_it).begin ();
  89. auto end = (*objects_it).end ();
  90. for (; cur != end; cur ++)
  91. {
  92. scene->insertObject (
  93. CObject::fromJSON (*cur)
  94. );
  95. }
  96. return scene;
  97. }
  98. const std::vector<CObject*>& CScene::getObjects () const
  99. {
  100. return this->m_objects;
  101. }
  102. void CScene::insertObject (CObject* object)
  103. {
  104. /// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
  105. if (object != nullptr)
  106. this->m_objects.push_back (object);
  107. }
  108. const Scenes::CCamera* CScene::getCamera () const
  109. {
  110. return this->m_camera;
  111. }
  112. const irr::video::SColorf &CScene::getAmbientColor() const
  113. {
  114. return this->m_ambientColor;
  115. }
  116. const bool CScene::isBloom () const
  117. {
  118. return this->m_bloom;
  119. }
  120. const irr::f64 CScene::getBloomStrength () const
  121. {
  122. return this->m_bloomStrength;
  123. }
  124. const irr::f64 CScene::getBloomThreshold () const
  125. {
  126. return this->m_bloomThreshold;
  127. }
  128. const bool CScene::isCameraFade () const
  129. {
  130. return this->m_cameraFade;
  131. }
  132. const bool CScene::isCameraParallax () const
  133. {
  134. return this->m_cameraParallax;
  135. }
  136. const irr::f64 CScene::getCameraParallaxAmount () const
  137. {
  138. return this->m_cameraParallaxAmount;
  139. }
  140. const irr::f64 CScene::getCameraParallaxDelay () const
  141. {
  142. return this->m_cameraParallaxDelay;
  143. }
  144. const irr::f64 CScene::getCameraParallaxMouseInfluence () const
  145. {
  146. return this->m_cameraParallaxMouseInfluence;
  147. }
  148. const bool CScene::isCameraPreview () const
  149. {
  150. return this->m_cameraPreview;
  151. }
  152. const bool CScene::isCameraShake () const
  153. {
  154. return this->m_cameraShake;
  155. }
  156. const irr::f64 CScene::getCameraShakeAmplitude () const
  157. {
  158. return this->m_cameraShakeAmplitude;
  159. }
  160. const irr::f64 CScene::getCameraShakeRoughness () const
  161. {
  162. return this->m_cameraShakeRoughness;
  163. }
  164. const irr::f64 CScene::getCameraShakeSpeed () const
  165. {
  166. return this->m_cameraShakeSpeed;
  167. }
  168. const irr::video::SColorf& CScene::getClearColor () const
  169. {
  170. return this->m_clearColor;
  171. }
  172. const Scenes::CProjection* CScene::getOrthogonalProjection () const
  173. {
  174. return this->m_orthogonalProjection;
  175. }
  176. const irr::video::SColorf& CScene::getSkylightColor () const
  177. {
  178. return this->m_skylightColor;
  179. }
  180. const std::string CScene::Type = "scene";