scene.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #include "scene.h"
  2. #include "project.h"
  3. #include "../core.h"
  4. #include "../fs/utils.h"
  5. using namespace wp::core;
  6. scene::scene (
  7. scenes::camera* camera,
  8. irr::video::SColorf ambientColor,
  9. bool bloom,
  10. irr::f64 bloomStrength,
  11. irr::f64 bloomThreshold,
  12. bool cameraFade,
  13. bool cameraParallax,
  14. irr::f64 cameraParallaxAmount,
  15. irr::f64 cameraParallaxDelay,
  16. irr::f64 cameraParallaxMouseInfluence,
  17. bool cameraPreview,
  18. bool cameraShake,
  19. irr::f64 cameraShakeAmplitude,
  20. irr::f64 cameraShakeRoughness,
  21. irr::f64 cameraShakeSpeed,
  22. irr::video::SColorf clearColor,
  23. scenes::projection* orthogonalProjection,
  24. irr::video::SColorf skylightColor) :
  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. scene* scene::fromFile (const irr::io::path& filename)
  46. {
  47. json content = json::parse (wp::fs::utils::loadFullFile (filename));
  48. json::const_iterator camera_it = content.find ("camera");
  49. json::const_iterator general_it = content.find ("general");
  50. if (camera_it == content.end ())
  51. {
  52. throw std::runtime_error ("Scenes must have a defined camera");
  53. }
  54. if (general_it == content.end ())
  55. {
  56. throw std::runtime_error ("Scenes must have a general section");
  57. }
  58. json::const_iterator ambientcolor_it = (*general_it).find ("ambientcolor");
  59. json::const_iterator bloom_it = (*general_it).find ("bloom");
  60. json::const_iterator bloomstrength_it = (*general_it).find ("bloomstrength");
  61. json::const_iterator bloomthreshold_it = (*general_it).find ("bloomthreshold");
  62. json::const_iterator camerafade_it = (*general_it).find ("camerafade");
  63. json::const_iterator cameraparallax_it = (*general_it).find ("cameraparallax");
  64. json::const_iterator cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount");
  65. json::const_iterator cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay");
  66. json::const_iterator cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence");
  67. json::const_iterator camerapreview_it = (*general_it).find ("camerapreview");
  68. json::const_iterator camerashake_it = (*general_it).find ("camerashake");
  69. json::const_iterator camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude");
  70. json::const_iterator camerashakeroughness_it = (*general_it).find ("camerashakeroughness");
  71. json::const_iterator camerashakespeed_it = (*general_it).find ("camerashakespeed");
  72. json::const_iterator clearcolor_it = (*general_it).find ("clearcolor");
  73. json::const_iterator orthogonalprojection_it = (*general_it).find ("orthogonalprojection");
  74. json::const_iterator skylightcolor_it = (*general_it).find ("skylightcolor");
  75. if (ambientcolor_it == (*general_it).end ())
  76. {
  77. throw std::runtime_error ("General section must have ambient color");
  78. }
  79. if (bloom_it == (*general_it).end ())
  80. {
  81. throw std::runtime_error ("General section must have bloom flag");
  82. }
  83. if (bloomstrength_it == (*general_it).end ())
  84. {
  85. throw std::runtime_error ("General section must have bloom strength");
  86. }
  87. if (bloomthreshold_it == (*general_it).end ())
  88. {
  89. throw std::runtime_error ("General section must have bloom threshold");
  90. }
  91. if (camerafade_it == (*general_it).end ())
  92. {
  93. throw std::runtime_error ("General section must have camera fade");
  94. }
  95. if (cameraparallax_it == (*general_it).end ())
  96. {
  97. throw std::runtime_error ("General section must have camera parallax");
  98. }
  99. if (cameraparallaxamount_it == (*general_it).end ())
  100. {
  101. throw std::runtime_error ("General section must have camera parallax amount");
  102. }
  103. if (cameraparallaxdelay_it == (*general_it).end ())
  104. {
  105. throw std::runtime_error ("General section must have camera parallax delay");
  106. }
  107. if (cameraparallaxmouseinfluence_it == (*general_it).end ())
  108. {
  109. throw std::runtime_error ("General section must have camera parallax mouse influence");
  110. }
  111. if (camerapreview_it == (*general_it).end ())
  112. {
  113. throw std::runtime_error ("General section must have camera preview");
  114. }
  115. if (camerashake_it == (*general_it).end ())
  116. {
  117. throw std::runtime_error ("General section must have camera shake");
  118. }
  119. if (camerashakeamplitude_it == (*general_it).end ())
  120. {
  121. throw std::runtime_error ("General section must have camera shake amplitude");
  122. }
  123. if (camerashakeroughness_it == (*general_it).end ())
  124. {
  125. throw std::runtime_error ("General section must have camera shake roughness");
  126. }
  127. if (camerashakespeed_it == (*general_it).end ())
  128. {
  129. throw std::runtime_error ("General section must have camera shake speed");
  130. }
  131. if (clearcolor_it == (*general_it).end ())
  132. {
  133. throw std::runtime_error ("General section must have clear color");
  134. }
  135. if (orthogonalprojection_it == (*general_it).end ())
  136. {
  137. throw std::runtime_error ("General section must have orthogonal projection info");
  138. }
  139. if (skylightcolor_it == (*general_it).end ())
  140. {
  141. throw std::runtime_error ("General section must have skylight color");
  142. }
  143. return new scene (
  144. scenes::camera::fromJSON (*camera_it),
  145. wp::core::atoSColorf (*ambientcolor_it),
  146. *bloom_it,
  147. *bloomstrength_it,
  148. *bloomthreshold_it,
  149. *camerafade_it,
  150. *cameraparallax_it,
  151. *cameraparallaxamount_it,
  152. *cameraparallaxdelay_it,
  153. *cameraparallaxmouseinfluence_it,
  154. *camerapreview_it,
  155. *camerashake_it,
  156. *camerashakeamplitude_it,
  157. *camerashakeroughness_it,
  158. *camerashakespeed_it,
  159. wp::core::atoSColorf (*clearcolor_it),
  160. scenes::projection::fromJSON (*orthogonalprojection_it),
  161. wp::core::atoSColorf (*skylightcolor_it)
  162. );
  163. }
  164. project* scene::getProject ()
  165. {
  166. return this->m_project;
  167. }
  168. void scene::setProject (project* project)
  169. {
  170. this->m_project = project;
  171. }
  172. scenes::camera* scene::getCamera ()
  173. {
  174. return this->m_camera;
  175. }
  176. const irr::video::SColorf &scene::getAmbientColor() const
  177. {
  178. return this->m_ambientColor;
  179. }
  180. bool scene::isBloom () const
  181. {
  182. return this->m_bloom;
  183. }
  184. irr::f64 scene::getBloomStrength () const
  185. {
  186. return this->m_bloomStrength;
  187. }
  188. irr::f64 scene::getBloomThreshold () const
  189. {
  190. return this->m_bloomThreshold;
  191. }
  192. bool scene::isCameraFade () const
  193. {
  194. return this->m_cameraFade;
  195. }
  196. bool scene::isCameraParallax () const
  197. {
  198. return this->m_cameraParallax;
  199. }
  200. irr::f64 scene::getCameraParallaxAmount () const
  201. {
  202. return this->m_cameraParallaxAmount;
  203. }
  204. irr::f64 scene::getCameraParallaxDelay () const
  205. {
  206. return this->m_cameraParallaxDelay;
  207. }
  208. irr::f64 scene::getCameraParallaxMouseInfluence () const
  209. {
  210. return this->m_cameraParallaxMouseInfluence;
  211. }
  212. bool scene::isCameraPreview () const
  213. {
  214. return this->m_cameraPreview;
  215. }
  216. bool scene::isCameraShake () const
  217. {
  218. return this->m_cameraShake;
  219. }
  220. irr::f64 scene::getCameraShakeAmplitude () const
  221. {
  222. return this->m_cameraShakeAmplitude;
  223. }
  224. irr::f64 scene::getCameraShakeRoughness () const
  225. {
  226. return this->m_cameraShakeRoughness;
  227. }
  228. irr::f64 scene::getCameraShakeSpeed () const
  229. {
  230. return this->m_cameraShakeSpeed;
  231. }
  232. const irr::video::SColorf &scene::getClearColor () const
  233. {
  234. return this->m_clearColor;
  235. }
  236. scenes::projection *scene::getOrthogonalProjection () const
  237. {
  238. return this->m_orthogonalProjection;
  239. }
  240. const irr::video::SColorf &scene::getSkylightColor () const
  241. {
  242. return this->m_skylightColor;
  243. }