custom_particle_system.cpp 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  1. // SuperTux
  2. // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "object/custom_particle_system.hpp"
  17. #include <assert.h>
  18. #include <math.h>
  19. #include "collision/collision.hpp"
  20. #include "editor/particle_editor.hpp"
  21. #include "gui/menu_manager.hpp"
  22. #include "math/aatriangle.hpp"
  23. #include "math/easing.hpp"
  24. #include "math/random.hpp"
  25. #include "math/util.hpp"
  26. #include "object/camera.hpp"
  27. #include "object/tilemap.hpp"
  28. #include "supertux/fadetoblack.hpp"
  29. #include "supertux/game_session.hpp"
  30. #include "supertux/screen_manager.hpp"
  31. #include "supertux/sector.hpp"
  32. #include "supertux/tile.hpp"
  33. #include "util/reader.hpp"
  34. #include "util/reader_document.hpp"
  35. #include "util/reader_mapping.hpp"
  36. #include "video/drawing_context.hpp"
  37. #include "video/surface.hpp"
  38. #include "video/surface_batch.hpp"
  39. #include "video/video_system.hpp"
  40. #include "video/viewport.hpp"
  41. CustomParticleSystem::CustomParticleSystem() :
  42. texture_sum_odds(0.f),
  43. time_last_remaining(0.f),
  44. script_easings(),
  45. m_textures(),
  46. custom_particles(),
  47. m_particle_main_texture("/images/engine/editor/particle.png"),
  48. m_max_amount(25),
  49. m_delay(0.1f),
  50. m_particle_lifetime(5.f),
  51. m_particle_lifetime_variation(0.f),
  52. m_particle_birth_time(0.f),
  53. m_particle_birth_time_variation(0.f),
  54. m_particle_death_time(0.f),
  55. m_particle_death_time_variation(0.f),
  56. m_particle_birth_mode(),
  57. m_particle_death_mode(),
  58. m_particle_birth_easing(),
  59. m_particle_death_easing(),
  60. m_particle_speed_x(0.f),
  61. m_particle_speed_y(0.f),
  62. m_particle_speed_variation_x(0.f),
  63. m_particle_speed_variation_y(0.f),
  64. m_particle_acceleration_x(0.f),
  65. m_particle_acceleration_y(0.f),
  66. m_particle_friction_x(0.f),
  67. m_particle_friction_y(0.f),
  68. m_particle_feather_factor(0.f),
  69. m_particle_rotation(0.f),
  70. m_particle_rotation_variation(0.f),
  71. m_particle_rotation_speed(0.f),
  72. m_particle_rotation_speed_variation(0.f),
  73. m_particle_rotation_acceleration(0.f),
  74. m_particle_rotation_decceleration(0.f),
  75. m_particle_rotation_mode(),
  76. m_particle_collision_mode(),
  77. m_particle_offscreen_mode(),
  78. m_cover_screen(true)
  79. {
  80. reinit_textures();
  81. }
  82. CustomParticleSystem::CustomParticleSystem(const ReaderMapping& reader) :
  83. ParticleSystem_Interactive(reader),
  84. texture_sum_odds(0.f),
  85. time_last_remaining(0.f),
  86. script_easings(),
  87. m_textures(),
  88. custom_particles(),
  89. m_particle_main_texture("/images/engine/editor/particle.png"),
  90. m_max_amount(25),
  91. m_delay(0.1f),
  92. m_particle_lifetime(5.f),
  93. m_particle_lifetime_variation(0.f),
  94. m_particle_birth_time(0.f),
  95. m_particle_birth_time_variation(0.f),
  96. m_particle_death_time(0.f),
  97. m_particle_death_time_variation(0.f),
  98. m_particle_birth_mode(),
  99. m_particle_death_mode(),
  100. m_particle_birth_easing(),
  101. m_particle_death_easing(),
  102. m_particle_speed_x(0.f),
  103. m_particle_speed_y(0.f),
  104. m_particle_speed_variation_x(0.f),
  105. m_particle_speed_variation_y(0.f),
  106. m_particle_acceleration_x(0.f),
  107. m_particle_acceleration_y(0.f),
  108. m_particle_friction_x(0.f),
  109. m_particle_friction_y(0.f),
  110. m_particle_feather_factor(0.f),
  111. m_particle_rotation(0.f),
  112. m_particle_rotation_variation(0.f),
  113. m_particle_rotation_speed(0.f),
  114. m_particle_rotation_speed_variation(0.f),
  115. m_particle_rotation_acceleration(0.f),
  116. m_particle_rotation_decceleration(0.f),
  117. m_particle_rotation_mode(),
  118. m_particle_collision_mode(),
  119. m_particle_offscreen_mode(),
  120. m_cover_screen(true)
  121. {
  122. reader.get("main-texture", m_particle_main_texture, "/images/engine/editor/particle.png");
  123. // FIXME: Is there a cleaner way to get a list of textures?
  124. auto iter = reader.get_iter();
  125. while (iter.next())
  126. {
  127. if (iter.get_key() == "texture")
  128. {
  129. ReaderMapping mapping = iter.as_mapping();
  130. std::string tex;
  131. if (!mapping.get("surface", tex))
  132. {
  133. log_warning << "Texture without surface data ('surface') in " <<
  134. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  135. continue;
  136. }
  137. float color_r, color_g, color_b, color_a;
  138. if (!mapping.get("color_r", color_r))
  139. {
  140. log_warning << "Texture without red color field ('color_r') in " <<
  141. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  142. continue;
  143. }
  144. if (!mapping.get("color_g", color_g))
  145. {
  146. log_warning << "Texture without green color field ('color_g') in " <<
  147. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  148. continue;
  149. }
  150. if (!mapping.get("color_b", color_b))
  151. {
  152. log_warning << "Texture without blue color field ('color_b') in " <<
  153. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  154. continue;
  155. }
  156. if (!mapping.get("color_a", color_a))
  157. {
  158. log_warning << "Texture without alpha channel field ('color_a') in " <<
  159. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  160. continue;
  161. }
  162. float likeliness;
  163. if (!mapping.get("likeliness", likeliness))
  164. {
  165. log_warning << "Texture without likeliness field in " <<
  166. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  167. continue;
  168. }
  169. float scale_x, scale_y;
  170. if (!mapping.get("scale_x", scale_x))
  171. {
  172. log_warning << "Texture without horizontal scale ('scale_x') field in " <<
  173. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  174. continue;
  175. }
  176. if (!mapping.get("scale_y", scale_y))
  177. {
  178. log_warning << "Texture without vertical scale ('scale_y') field in " <<
  179. mapping.get_doc().get_filename() << ", skipping" << std::endl;
  180. continue;
  181. }
  182. auto props = SpriteProperties(Surface::from_file(tex));
  183. props.likeliness = likeliness;
  184. props.color = Color(color_r, color_g, color_b, color_a);
  185. props.scale = Vector(scale_x, scale_y);
  186. m_textures.push_back(props);
  187. }
  188. }
  189. reader.get("amount", m_max_amount, 25);
  190. reader.get("delay", m_delay, 0.1f);
  191. reader.get("lifetime", m_particle_lifetime, 5.f);
  192. reader.get("lifetime-variation", m_particle_lifetime_variation, 0.f);
  193. reader.get("birth-time", m_particle_birth_time, 0.f);
  194. reader.get("birth-time-variation", m_particle_birth_time_variation, 0.f);
  195. reader.get("death-time", m_particle_death_time, 0.f);
  196. reader.get("death-time-variation", m_particle_death_time_variation, 0.f);
  197. reader.get("speed-x", m_particle_speed_x, 0.f);
  198. reader.get("speed-y", m_particle_speed_y, 0.f);
  199. reader.get("speed-var-x", m_particle_speed_variation_x, 0.f);
  200. reader.get("speed-var-y", m_particle_speed_variation_y, 0.f);
  201. reader.get("acceleration-x", m_particle_acceleration_x, 0.f);
  202. reader.get("acceleration-y", m_particle_acceleration_y, 0.f);
  203. reader.get("friction-x", m_particle_friction_x, 0.f);
  204. reader.get("friction-y", m_particle_friction_y, 0.f);
  205. reader.get("feather-factor", m_particle_feather_factor, 0.f);
  206. reader.get("rotation", m_particle_rotation, 0.f);
  207. reader.get("rotation-variation", m_particle_rotation_variation, 0.f);
  208. reader.get("rotation-speed", m_particle_rotation_speed, 0.f);
  209. reader.get("rotation-speed-variation", m_particle_rotation_speed_variation, 0.f);
  210. reader.get("rotation-acceleration", m_particle_rotation_acceleration, 0.f);
  211. reader.get("rotation-decceleration", m_particle_rotation_decceleration, 0.f);
  212. reader.get("cover-screen", m_cover_screen, true);
  213. std::string rotation_mode;
  214. if (reader.get("rotation-mode", rotation_mode))
  215. {
  216. if (rotation_mode == "wiggling")
  217. {
  218. m_particle_rotation_mode = RotationMode::Wiggling;
  219. }
  220. else if (rotation_mode == "facing")
  221. {
  222. m_particle_rotation_mode = RotationMode::Facing;
  223. }
  224. else
  225. {
  226. m_particle_rotation_mode = RotationMode::Fixed;
  227. }
  228. }
  229. else
  230. {
  231. m_particle_rotation_mode = RotationMode::Fixed;
  232. }
  233. std::string birth_mode;
  234. if (reader.get("birth-mode", birth_mode))
  235. {
  236. if (birth_mode == "shrink")
  237. {
  238. m_particle_birth_mode = FadeMode::Shrink;
  239. }
  240. else if (birth_mode == "fade")
  241. {
  242. m_particle_birth_mode = FadeMode::Fade;
  243. }
  244. else
  245. {
  246. m_particle_birth_mode = FadeMode::None;
  247. }
  248. }
  249. else
  250. {
  251. m_particle_birth_mode = FadeMode::None;
  252. }
  253. std::string death_mode;
  254. if (reader.get("death-mode", death_mode))
  255. {
  256. if (death_mode == "shrink")
  257. {
  258. m_particle_death_mode = FadeMode::Shrink;
  259. }
  260. else if (death_mode == "fade")
  261. {
  262. m_particle_death_mode = FadeMode::Fade;
  263. }
  264. else
  265. {
  266. m_particle_death_mode = FadeMode::None;
  267. }
  268. }
  269. else
  270. {
  271. m_particle_death_mode = FadeMode::None;
  272. }
  273. std::string birth_easing;
  274. if (reader.get("birth-easing", birth_easing))
  275. {
  276. m_particle_birth_easing = EasingMode_from_string(birth_easing);
  277. }
  278. else
  279. {
  280. m_particle_birth_easing = EasingMode_from_string("");
  281. }
  282. std::string death_easing;
  283. if (reader.get("death-easing", death_easing))
  284. {
  285. m_particle_death_easing = EasingMode_from_string(death_easing);
  286. }
  287. else
  288. {
  289. m_particle_death_easing = EasingMode_from_string("");
  290. }
  291. std::string collision_mode;
  292. if (reader.get("collision-mode", collision_mode))
  293. {
  294. if (collision_mode == "stick")
  295. {
  296. m_particle_collision_mode = CollisionMode::Stick;
  297. }
  298. else if (collision_mode == "stick-forever")
  299. {
  300. m_particle_collision_mode = CollisionMode::StickForever;
  301. }
  302. else if (collision_mode == "bounce-heavy")
  303. {
  304. m_particle_collision_mode = CollisionMode::BounceHeavy;
  305. }
  306. else if (collision_mode == "bounce-light")
  307. {
  308. m_particle_collision_mode = CollisionMode::BounceLight;
  309. }
  310. else if (collision_mode == "destroy")
  311. {
  312. m_particle_collision_mode = CollisionMode::Destroy;
  313. }
  314. else if (collision_mode == "fade-out")
  315. {
  316. m_particle_collision_mode = CollisionMode::FadeOut;
  317. }
  318. else
  319. {
  320. m_particle_collision_mode = CollisionMode::Ignore;
  321. }
  322. }
  323. else
  324. {
  325. m_particle_collision_mode = CollisionMode::Ignore;
  326. }
  327. std::string offscreen_mode;
  328. if (reader.get("offscreen-mode", offscreen_mode))
  329. {
  330. if (offscreen_mode == "always")
  331. {
  332. m_particle_offscreen_mode = OffscreenMode::Always;
  333. }
  334. else if (offscreen_mode == "only-on-exit")
  335. {
  336. m_particle_offscreen_mode = OffscreenMode::OnlyOnExit;
  337. }
  338. else
  339. {
  340. m_particle_offscreen_mode = OffscreenMode::Never;
  341. }
  342. }
  343. else
  344. {
  345. m_particle_offscreen_mode = OffscreenMode::Never;
  346. }
  347. reinit_textures();
  348. }
  349. CustomParticleSystem::~CustomParticleSystem()
  350. {
  351. }
  352. void
  353. CustomParticleSystem::reinit_textures()
  354. {
  355. if (!m_textures.size())
  356. {
  357. auto props = SpriteProperties(Surface::from_file(m_particle_main_texture));
  358. props.likeliness = 1.f;
  359. props.color = Color(1.f, 1.f, 1.f, 1.f);
  360. props.scale = Vector(1.f, 1.f);
  361. m_textures.push_back(props);
  362. }
  363. texture_sum_odds = 0.f;
  364. for (const auto& texture : m_textures)
  365. {
  366. texture_sum_odds += texture.likeliness;
  367. }
  368. }
  369. void
  370. CustomParticleSystem::save(Writer& writer)
  371. {
  372. for (const auto& tex : m_textures)
  373. {
  374. writer.start_list("texture");
  375. writer.write("surface", tex.texture->get_filename());
  376. writer.write("color_r", tex.color.red);
  377. writer.write("color_g", tex.color.green);
  378. writer.write("color_b", tex.color.blue);
  379. writer.write("color_a", tex.color.alpha);
  380. writer.write("likeliness", tex.likeliness);
  381. writer.write("scale_x", tex.scale.x);
  382. writer.write("scale_y", tex.scale.y);
  383. writer.end_list("texture");
  384. }
  385. GameObject::save(writer);
  386. }
  387. ObjectSettings
  388. CustomParticleSystem::get_settings()
  389. {
  390. ObjectSettings result = ParticleSystem::get_settings();
  391. result.add_surface(_("Texture"), &m_particle_main_texture, "main-texture");
  392. result.add_int(_("Amount"), &m_max_amount, "amount", 25);
  393. result.add_float(_("Delay"), &m_delay, "delay", 0.1f);
  394. result.add_float(_("Lifetime"), &m_particle_lifetime, "lifetime", 5.f);
  395. result.add_float(_("Lifetime variation"), &m_particle_lifetime_variation, "lifetime-variation", 0.f);
  396. result.add_enum(_("Birth mode"), reinterpret_cast<int*>(&m_particle_birth_mode),
  397. {_("None"), _("Fade"), _("Shrink")},
  398. {"none", "fade", "shrink"},
  399. static_cast<int>(FadeMode::None),
  400. "birth-mode");
  401. result.add_enum(_("Birth easing"), reinterpret_cast<int*>(&m_particle_birth_easing),
  402. {
  403. _("No easing"),
  404. _("Quad in"), _("Quad out"), _("Quad in/out"),
  405. _("Cubic in"), _("Cubic out"), _("Cubic in/out"),
  406. _("Quart in"), _("Quart out"), _("Quart in/out"),
  407. _("Quint in"), _("Quint out"), _("Quint in/out"),
  408. _("Sine in"), _("Sine out"), _("Sine in/out"),
  409. _("Circular in"), _("Circular out"), _("Circular in/out"),
  410. _("Exponential in"), _("Exponential out"), _("Exponential in/out"),
  411. _("Elastic in"), _("Elastic out"), _("Elastic in/out"),
  412. _("Back in"), _("Back out"), _("Back in/out"),
  413. _("Bounce in"), _("Bounce out"), _("Bounce in/out")
  414. },
  415. {
  416. "EaseNone",
  417. "EaseQuadIn", "EaseQuadOut", "EaseQuadInOut",
  418. "EaseCubicIn", "EaseCubicOut", "EaseCubicInOut",
  419. "EaseQuartIn", "EaseQuartOut", "EaseQuartInOut",
  420. "EaseQuintIn", "EaseQuintOut", "EaseQuintInOut",
  421. "EaseSineIn", "EaseSineOut", "EaseSineInOut",
  422. "EaseCircularIn", "EaseCircularOut", "EaseCircularInOut",
  423. "EaseExponentialIn", "EaseExponentialOut", "EaseExponentialInOut",
  424. "EaseElasticIn", "EaseElasticOut", "EaseElasticInOut",
  425. "EaseBackIn", "EaseBackOut", "EaseBackInOut",
  426. "EaseBounceIn", "EaseBounceOut", "EaseBounceInOut"
  427. },
  428. 0, "birth-easing");
  429. result.add_float(_("Birth time"), &m_particle_birth_time, "birth-time", 5.f);
  430. result.add_float(_("Birth time variation"), &m_particle_birth_time_variation, "birth-time-variation", 0.f);
  431. result.add_enum(_("Death mode"), reinterpret_cast<int*>(&m_particle_death_mode),
  432. {_("None"), _("Fade"), _("Shrink")},
  433. {"none", "fade", "shrink"},
  434. static_cast<int>(FadeMode::None),
  435. "death-mode");
  436. result.add_enum(_("Death easing"), reinterpret_cast<int*>(&m_particle_death_easing),
  437. {
  438. _("No easing"),
  439. _("Quad in"), _("Quad out"), _("Quad in/out"),
  440. _("Cubic in"), _("Cubic out"), _("Cubic in/out"),
  441. _("Quart in"), _("Quart out"), _("Quart in/out"),
  442. _("Quint in"), _("Quint out"), _("Quint in/out"),
  443. _("Sine in"), _("Sine out"), _("Sine in/out"),
  444. _("Circular in"), _("Circular out"), _("Circular in/out"),
  445. _("Exponential in"), _("Exponential out"), _("Exponential in/out"),
  446. _("Elastic in"), _("Elastic out"), _("Elastic in/out"),
  447. _("Back in"), _("Back out"), _("Back in/out"),
  448. _("Bounce in"), _("Bounce out"), _("Bounce in/out")
  449. },
  450. {
  451. "EaseNone",
  452. "EaseQuadIn", "EaseQuadOut", "EaseQuadInOut",
  453. "EaseCubicIn", "EaseCubicOut", "EaseCubicInOut",
  454. "EaseQuartIn", "EaseQuartOut", "EaseQuartInOut",
  455. "EaseQuintIn", "EaseQuintOut", "EaseQuintInOut",
  456. "EaseSineIn", "EaseSineOut", "EaseSineInOut",
  457. "EaseCircularIn", "EaseCircularOut", "EaseCircularInOut",
  458. "EaseExponentialIn", "EaseExponentialOut", "EaseExponentialInOut",
  459. "EaseElasticIn", "EaseElasticOut", "EaseElasticInOut",
  460. "EaseBackIn", "EaseBackOut", "EaseBackInOut",
  461. "EaseBounceIn", "EaseBounceOut", "EaseBounceInOut"
  462. },
  463. 0, "death-easing");
  464. result.add_float(_("Death time"), &m_particle_death_time, "death-time", 5.f);
  465. result.add_float(_("Death time variation"), &m_particle_death_time_variation, "death-time-variation", 0.f);
  466. result.add_float(_("Speed X"), &m_particle_speed_x, "speed-x", 0.f);
  467. result.add_float(_("Speed Y"), &m_particle_speed_y, "speed-y", 0.f);
  468. result.add_float(_("Speed X (variation)"), &m_particle_speed_variation_x, "speed-var-x", 0.f);
  469. result.add_float(_("Speed Y (variation)"), &m_particle_speed_variation_y, "speed-var-y", 0.f);
  470. result.add_float(_("Acceleration X"), &m_particle_acceleration_x, "acceleration-x", 0.f);
  471. result.add_float(_("Acceleration Y"), &m_particle_acceleration_y, "acceleration-y", 0.f);
  472. result.add_float(_("Friction X"), &m_particle_friction_x, "friction-x", 0.f);
  473. result.add_float(_("Friction Y"), &m_particle_friction_y, "friction-y", 0.f);
  474. result.add_float(_("Feather factor"), &m_particle_feather_factor, "feather-factor", 0.f);
  475. result.add_float(_("Rotation"), &m_particle_rotation, "rotation", 0.f);
  476. result.add_float(_("Rotation (variation)"), &m_particle_rotation_variation, "rotation-variation", 0.f);
  477. result.add_float(_("Rotation speed"), &m_particle_rotation_speed, "rotation-speed", 0.f);
  478. result.add_float(_("Rotation speed (variation)"), &m_particle_rotation_speed_variation, "rotation-speed-variation", 0.f);
  479. result.add_float(_("Rotation acceleration"), &m_particle_rotation_acceleration, "rotation-acceleration", 0.f);
  480. result.add_float(_("Rotation friction"), &m_particle_rotation_decceleration, "rotation-decceleration", 0.f);
  481. result.add_enum(_("Rotation mode"), reinterpret_cast<int*>(&m_particle_rotation_mode),
  482. {_("Fixed"), _("Facing"), _("Wiggling")},
  483. {"fixed", "facing", "wiggling"},
  484. static_cast<int>(RotationMode::Fixed),
  485. "rotation-mode");
  486. result.add_enum(_("Collision mode"), reinterpret_cast<int*>(&m_particle_collision_mode),
  487. {_("None (pass through)"), _("Stick"), _("Stick Forever"), _("Bounce (heavy)"), _("Bounce (light)"), _("Kill particle"), _("Fade out particle")},
  488. {"ignore", "stick", "stick-forever", "bounce-heavy", "bounce-light", "destroy", "fade-out"},
  489. static_cast<int>(CollisionMode::Ignore),
  490. "collision-mode");
  491. result.add_enum(_("Delete if off-screen"), reinterpret_cast<int*>(&m_particle_offscreen_mode),
  492. {_("Never"), _("Only on exit"), _("Always")},
  493. {"never", "only-on-exit", "always"},
  494. static_cast<int>(OffscreenMode::Never),
  495. "offscreen-mode");
  496. result.add_bool(_("Cover screen"), &m_cover_screen, "cover-screen", true);
  497. //result.reorder({"amount", "delay", "lifetime", "lifetime-variation", "enabled", "name"});
  498. result.add_particle_editor();
  499. return result;
  500. }
  501. void
  502. CustomParticleSystem::update(float dt_sec)
  503. {
  504. // The "enabled" flag being false only indicates that new particles shouldn't spawn.
  505. // However, we still need to update the existing particles, if any.
  506. // Handle script-based easings.
  507. for (auto& req : script_easings)
  508. {
  509. req.time_remain -= dt_sec;
  510. if (req.time_remain <= 0)
  511. {
  512. req.time_remain = 0;
  513. *(req.value) = req.end;
  514. }
  515. else
  516. {
  517. float progress = 1.f - (req.time_remain / req.time_total);
  518. progress = static_cast<float>(req.func(static_cast<double>(progress)));
  519. *(req.value) = req.begin + progress * (req.end - req.begin);
  520. }
  521. }
  522. // Update existing particles.
  523. for (auto& it : custom_particles) {
  524. auto particle = dynamic_cast<CustomParticle*>(it.get());
  525. assert(particle);
  526. if (particle->birth_time > dt_sec) {
  527. switch(particle->birth_mode) {
  528. case FadeMode::Shrink:
  529. particle->scale = static_cast<float>(
  530. getEasingByName(particle->birth_easing)(
  531. static_cast<double>(
  532. 1.f - (particle->birth_time / particle->total_birth)
  533. )
  534. ));
  535. break;
  536. case FadeMode::Fade:
  537. particle->props = SpriteProperties(particle->original_props,
  538. 1.f - (particle->birth_time /
  539. particle->total_birth));
  540. break;
  541. default:
  542. break;
  543. }
  544. particle->birth_time -= dt_sec;
  545. } else if (particle->birth_time > 0.f) {
  546. particle->birth_time = 0.f;
  547. switch(particle->birth_mode) {
  548. case FadeMode::Shrink:
  549. particle->scale = 1.f;
  550. break;
  551. case FadeMode::Fade:
  552. particle->props = particle->original_props;
  553. break;
  554. default:
  555. break;
  556. }
  557. }
  558. particle->lifetime -= dt_sec;
  559. if (particle->lifetime < 0.f) {
  560. particle->lifetime = 0.f;
  561. }
  562. if (particle->birth_time <= 0.f && particle->lifetime <= 0.f) {
  563. if (particle->death_time > dt_sec) {
  564. switch(particle->death_mode) {
  565. case FadeMode::Shrink:
  566. particle->scale = 1.f - static_cast<float>(
  567. getEasingByName(particle->death_easing)(
  568. static_cast<double>(
  569. 1.f - (particle->death_time / particle->total_death)
  570. )
  571. ));
  572. break;
  573. case FadeMode::Fade:
  574. particle->props = SpriteProperties(particle->original_props,
  575. (particle->death_time /
  576. particle->total_death));
  577. break;
  578. default:
  579. break;
  580. }
  581. particle->death_time -= dt_sec;
  582. } else {
  583. particle->death_time = 0.f;
  584. switch(particle->death_mode) {
  585. case FadeMode::Shrink:
  586. particle->scale = 0.f;
  587. break;
  588. case FadeMode::Fade:
  589. particle->props = SpriteProperties(particle->original_props, 0.f);
  590. break;
  591. default:
  592. break;
  593. }
  594. particle->ready_for_deletion = true;
  595. }
  596. }
  597. float abs_x = get_abs_x();
  598. float abs_y = get_abs_y();
  599. if (!particle->has_been_on_screen) {
  600. if (particle->pos.y <= static_cast<float>(SCREEN_HEIGHT) + abs_y
  601. && particle->pos.y >= abs_y
  602. && particle->pos.x <= static_cast<float>(SCREEN_WIDTH) + abs_x
  603. && particle->pos.x >= abs_x) {
  604. particle->has_been_on_screen = true;
  605. }
  606. }
  607. switch(particle->offscreen_mode) {
  608. case OffscreenMode::Always:
  609. if (particle->pos.y > static_cast<float>(SCREEN_HEIGHT) + abs_y
  610. || particle->pos.y < abs_y
  611. || particle->pos.x > static_cast<float>(SCREEN_WIDTH) + abs_x
  612. || particle->pos.x < abs_x) {
  613. particle->ready_for_deletion = true;
  614. }
  615. break;
  616. case OffscreenMode::OnlyOnExit:
  617. if ((particle->pos.y > static_cast<float>(SCREEN_HEIGHT) + abs_y
  618. || particle->pos.y < abs_y
  619. || particle->pos.x > static_cast<float>(SCREEN_WIDTH) + abs_x
  620. || particle->pos.x < abs_x)
  621. && particle->has_been_on_screen) {
  622. particle->ready_for_deletion = true;
  623. }
  624. break;
  625. case OffscreenMode::Never:
  626. break;
  627. }
  628. bool is_in_life_zone = false;
  629. for (auto& zone : get_zones()) {
  630. if (zone.get_rect().contains(particle->pos) && zone.get_particle_name() == m_name) {
  631. switch(zone.get_type()) {
  632. case ParticleZone::ParticleZoneType::Killer:
  633. particle->lifetime = 0.f;
  634. particle->birth_time = 0.f;
  635. break;
  636. case ParticleZone::ParticleZoneType::Destroyer:
  637. particle->ready_for_deletion = true;
  638. break;
  639. case ParticleZone::ParticleZoneType::LifeClear:
  640. particle->last_life_zone_required_instakill = true;
  641. particle->has_been_in_life_zone = true;
  642. is_in_life_zone = true;
  643. break;
  644. case ParticleZone::ParticleZoneType::Life:
  645. particle->last_life_zone_required_instakill = false;
  646. particle->has_been_in_life_zone = true;
  647. is_in_life_zone = true;
  648. break;
  649. // This case is intentionally empty; it serves as a placeholder to prevent a warning.
  650. case ParticleZone::ParticleZoneType::Spawn:
  651. break;
  652. }
  653. }
  654. } // For each ParticleZone object.
  655. if (!is_in_life_zone && particle->has_been_in_life_zone) {
  656. if (particle->last_life_zone_required_instakill) {
  657. particle->ready_for_deletion = true;
  658. } else {
  659. particle->lifetime = 0.f;
  660. particle->birth_time = 0.f;
  661. }
  662. }
  663. if (!particle->stuck) {
  664. particle->speedX += graphicsRandom.randf(-particle->feather_factor,
  665. particle->feather_factor) * dt_sec * 1000.f;
  666. particle->speedY += graphicsRandom.randf(-particle->feather_factor,
  667. particle->feather_factor) * dt_sec * 1000.f;
  668. particle->speedX += particle->accX * dt_sec;
  669. particle->speedY += particle->accY * dt_sec;
  670. particle->speedX *= 1.f - particle->frictionX * dt_sec;
  671. particle->speedY *= 1.f - particle->frictionY * dt_sec;
  672. if (Sector::current() && collision(particle,
  673. Vector(particle->speedX,particle->speedY) * dt_sec) > 0) {
  674. switch(particle->collision_mode) {
  675. case CollisionMode::Ignore:
  676. particle->pos.x += particle->speedX * dt_sec;
  677. particle->pos.y += particle->speedY * dt_sec;
  678. break;
  679. case CollisionMode::Stick:
  680. // Just don't move
  681. break;
  682. case CollisionMode::StickForever:
  683. particle->stuck = true;
  684. break;
  685. case CollisionMode::BounceHeavy:
  686. case CollisionMode::BounceLight:
  687. {
  688. auto c = get_collision(particle, Vector(particle->speedX, particle->speedY) * dt_sec);
  689. float speed_angle = atanf(-particle->speedY / particle->speedX);
  690. if (c.slope_normal.x == 0.f && c.slope_normal.y == 0.f) {
  691. auto cX = get_collision(particle, Vector(particle->speedX, 0) * dt_sec);
  692. if (cX.left != cX.right)
  693. particle->speedX *= -1;
  694. auto cY = get_collision(particle, Vector(0, particle->speedY) * dt_sec);
  695. if (cY.top != cY.bottom)
  696. particle->speedY *= -1;
  697. } else {
  698. float face_angle = atanf(c.slope_normal.y / c.slope_normal.x);
  699. float dest_angle = face_angle * 2.f - speed_angle; // Reflect the angle around face_angle.
  700. float dX = cosf(dest_angle),
  701. dY = sinf(dest_angle);
  702. float true_speed = static_cast<float>(sqrt(pow(particle->speedY, 2)
  703. + pow(particle->speedX, 2)));
  704. particle->speedX = dX * true_speed;
  705. particle->speedY = dY * true_speed;
  706. }
  707. switch(particle->collision_mode) {
  708. case CollisionMode::BounceHeavy:
  709. particle->speedX *= .2f;
  710. particle->speedY *= .2f;
  711. break;
  712. case CollisionMode::BounceLight:
  713. particle->speedX *= .7f;
  714. particle->speedY *= .7f;
  715. break;
  716. default:
  717. assert(false);
  718. }
  719. particle->pos.x += particle->speedX * dt_sec;
  720. particle->pos.y += particle->speedY * dt_sec;
  721. }
  722. break;
  723. case CollisionMode::Destroy:
  724. particle->ready_for_deletion = true;
  725. break;
  726. case CollisionMode::FadeOut:
  727. particle->lifetime = 0.f;
  728. break;
  729. }
  730. } else {
  731. particle->pos.x += particle->speedX * dt_sec;
  732. particle->pos.y += particle->speedY * dt_sec;
  733. }
  734. switch(particle->angle_mode) {
  735. case RotationMode::Facing:
  736. particle->angle = atanf(particle->speedY / particle->speedX) * 180.f / math::PI;
  737. break;
  738. case RotationMode::Wiggling:
  739. particle->angle += graphicsRandom.randf(-particle->angle_speed / 2.f,
  740. particle->angle_speed / 2.f) * dt_sec;
  741. break;
  742. case RotationMode::Fixed:
  743. default:
  744. particle->angle_speed += particle->angle_acc * dt_sec;
  745. particle->angle_speed *= 1.f - particle->angle_decc * dt_sec;
  746. particle->angle += particle->angle_speed * dt_sec;
  747. }
  748. }
  749. } // For each particle.
  750. // Clear dead particles
  751. // We iterate through the vector backwards because removing an element affects
  752. // the index of all elements after it, which can lead to buggy behavior.
  753. for (int i = static_cast<int>(custom_particles.size()) - 1; i >= 0; --i) {
  754. auto particle = dynamic_cast<CustomParticle*>(custom_particles.at(i).get());
  755. if (particle->ready_for_deletion) {
  756. custom_particles.erase(custom_particles.begin()+i);
  757. }
  758. }
  759. // Add necessary particles.
  760. float remaining = dt_sec + time_last_remaining;
  761. if (enabled) {
  762. int real_max = m_max_amount;
  763. if (!m_cover_screen) {
  764. int i = 0;
  765. for (auto& zone : get_zones()) {
  766. if (zone.get_type() == ParticleZone::ParticleZoneType::Spawn && zone.get_particle_name() == m_name) {
  767. i++;
  768. }
  769. }
  770. real_max *= i;
  771. }
  772. while (remaining > m_delay && int(custom_particles.size()) < real_max)
  773. {
  774. spawn_particles(remaining);
  775. remaining -= m_delay;
  776. }
  777. }
  778. // Maxes to m_delay, so that if there's already the max amount of particles,
  779. // it won't store all the time waiting for some particles to go and then
  780. // spawn a bazillion particles instantly. (Bacisally it means : This will
  781. // help guarantee there will be at least m_delay between each particle
  782. // spawn as long as m_delay >= dt_sec).
  783. time_last_remaining = (remaining > m_delay) ? m_delay : remaining;
  784. }
  785. void
  786. CustomParticleSystem::draw(DrawingContext& context)
  787. {
  788. // The "enabled" flag being false only indicates that new particles shouldn't spawn.
  789. // However, we still need to update the existing particles, if any.
  790. context.push_transform();
  791. std::unordered_map<SpriteProperties*, SurfaceBatch> batches;
  792. for (const auto& particle : custom_particles) {
  793. auto it = batches.find(&(particle->props));
  794. if (it == batches.end()) {
  795. const auto& batch_it = batches.emplace(&(particle->props),
  796. SurfaceBatch(particle->props.texture, particle->props.color));
  797. batch_it.first->second.draw(Rectf(Vector(
  798. particle->pos.x - particle->scale
  799. * static_cast<float>(
  800. particle->props.texture->get_width()
  801. ) * particle->props.scale.x / 2,
  802. particle->pos.y - particle->scale
  803. * static_cast<float>(
  804. particle->props.texture->get_height()
  805. ) * particle->props.scale.y / 2
  806. ),
  807. Vector(
  808. particle->pos.x + particle->scale
  809. * static_cast<float>(
  810. particle->props.texture->get_width()
  811. ) * particle->props.scale.x / 2,
  812. particle->pos.y + particle->scale
  813. * static_cast<float>(
  814. particle->props.texture->get_height()
  815. ) * particle->props.scale.y / 2
  816. )
  817. ), particle->angle);
  818. } else {
  819. it->second.draw(Rectf(particle->pos,
  820. Vector(
  821. particle->pos.x + particle->scale
  822. * static_cast<float>(
  823. particle->texture->get_width()
  824. ) * particle->props.scale.x,
  825. particle->pos.y + particle->scale
  826. * static_cast<float>(
  827. particle->texture->get_height()
  828. ) * particle->props.scale.y
  829. )
  830. ), particle->angle);
  831. }
  832. }
  833. for(auto& it : batches) {
  834. auto& surface = it.first->texture;
  835. auto& batch = it.second;
  836. context.color().draw_surface_batch(surface, batch.move_srcrects(),
  837. batch.move_dstrects(), batch.move_angles(), it.first->color, z_pos);
  838. }
  839. context.pop_transform();
  840. }
  841. // Duplicated from ParticleSystem_Interactive because I intend to bring edits
  842. // sometime in the future, for even more flexibility with particles. (Semphris).
  843. int
  844. CustomParticleSystem::collision(Particle* object, const Vector& movement)
  845. {
  846. using namespace collision;
  847. CustomParticle* particle = dynamic_cast<CustomParticle*>(object);
  848. assert(particle);
  849. // Calculate rectangle where the object will move.
  850. float x1, x2;
  851. float y1, y2;
  852. x1 = object->pos.x - particle->props.hb_scale.x * static_cast<float>(particle->props.texture->get_width()) / 2
  853. + particle->props.hb_offset.x * static_cast<float>(particle->props.texture->get_width());
  854. x2 = x1 + particle->props.hb_scale.x * static_cast<float>(particle->props.texture->get_width()) + movement.x;
  855. if (x2 < x1) {
  856. float temp_x = x1;
  857. x1 = x2;
  858. x2 = temp_x;
  859. }
  860. y1 = object->pos.y - particle->props.hb_scale.y * static_cast<float>(particle->props.texture->get_height()) / 2
  861. + particle->props.hb_offset.y * static_cast<float>(particle->props.texture->get_height());
  862. y2 = y1 + particle->props.hb_scale.y * static_cast<float>(particle->props.texture->get_height()) + movement.y;
  863. if (y2 < y1) {
  864. float temp_y = y1;
  865. y1 = y2;
  866. y2 = temp_y;
  867. }
  868. bool water = false;
  869. // Test with all tiles in this rectangle.
  870. int starttilex = int(x1-1) / 32;
  871. int starttiley = int(y1-1) / 32;
  872. int max_x = int(x2+1);
  873. int max_y = int(y2+1);
  874. Rectf dest(x1, y1, x2, y2);
  875. dest.move(movement);
  876. Constraints constraints;
  877. for (const auto& solids : Sector::get().get_solid_tilemaps()) {
  878. // FIXME: Handle a nonzero tilemap offset.
  879. // Check if it gets fixed in particlesystem_interactive.cpp.
  880. for (int x = starttilex; x*32 < max_x; ++x) {
  881. for (int y = starttiley; y*32 < max_y; ++y) {
  882. const Tile& tile = solids->get_tile(x, y);
  883. // Skip non-solid tiles, except water.
  884. if (! (tile.get_attributes() & (Tile::WATER | Tile::SOLID)))
  885. continue;
  886. Rectf rect = solids->get_tile_bbox(x, y);
  887. if (tile.is_slope ()) { // Slope tile.
  888. AATriangle triangle = AATriangle(rect, tile.get_data());
  889. if (rectangle_aatriangle(&constraints, dest, triangle)) {
  890. if (tile.get_attributes() & Tile::WATER)
  891. water = true;
  892. }
  893. } else { // Normal rectangular tile.
  894. if (dest.overlaps(rect)) {
  895. if (tile.get_attributes() & Tile::WATER)
  896. water = true;
  897. set_rectangle_rectangle_constraints(&constraints, dest, rect);
  898. }
  899. }
  900. }
  901. }
  902. }
  903. // TODO: Avoid using magic numbers in this section.
  904. // Check if any constraints exist for collision.
  905. if (!constraints.has_constraints())
  906. return -1;
  907. const CollisionHit& hit = constraints.hit;
  908. if (water) {
  909. return 0; // Collision with water tile - no need to draw splash.
  910. } else {
  911. if (hit.right || hit.left) {
  912. return 2; // Collision from the right.
  913. } else {
  914. return 1; // Collision from above.
  915. }
  916. }
  917. }
  918. CollisionHit
  919. CustomParticleSystem::get_collision(Particle* object, const Vector& movement)
  920. {
  921. using namespace collision;
  922. CustomParticle* particle = dynamic_cast<CustomParticle*>(object);
  923. assert(particle);
  924. // Calculate rectangle where the object will move.
  925. float x1, x2;
  926. float y1, y2;
  927. x1 = object->pos.x - particle->props.scale.x * static_cast<float>(particle->props.texture->get_width()) / 2;
  928. x2 = x1 + particle->props.scale.x * static_cast<float>(particle->props.texture->get_width()) + movement.x;
  929. if (x2 < x1) {
  930. float temp_x = x1;
  931. x1 = x2;
  932. x2 = temp_x;
  933. }
  934. y1 = object->pos.y - particle->props.scale.y * static_cast<float>(particle->props.texture->get_height()) / 2;
  935. y2 = y1 + particle->props.scale.y * static_cast<float>(particle->props.texture->get_height()) + movement.y;
  936. if (y2 < y1) {
  937. float temp_y = y1;
  938. y1 = y2;
  939. y2 = temp_y;
  940. }
  941. // Test with all tiles in this rectangle.
  942. int starttilex = int(x1-1) / 32;
  943. int starttiley = int(y1-1) / 32;
  944. int max_x = int(x2+1);
  945. int max_y = int(y2+1);
  946. Rectf dest(x1, y1, x2, y2);
  947. dest.move(movement);
  948. Constraints constraints;
  949. for (const auto& solids : Sector::get().get_solid_tilemaps()) {
  950. // FIXME: Handle a nonzero tilemap offset.
  951. // Check if it gets fixed in particlesystem_interactive.cpp.
  952. for (int x = starttilex; x*32 < max_x; ++x) {
  953. for (int y = starttiley; y*32 < max_y; ++y) {
  954. const Tile& tile = solids->get_tile(x, y);
  955. // Skip non-solid tiles.
  956. if (! (tile.get_attributes() & (/*Tile::WATER |*/ Tile::SOLID)))
  957. continue;
  958. Rectf rect = solids->get_tile_bbox(x, y);
  959. if (tile.is_slope ()) { // Slope tile.
  960. AATriangle triangle = AATriangle(rect, tile.get_data());
  961. rectangle_aatriangle(&constraints, dest, triangle);
  962. } else { // Normal rectangular tile.
  963. if (dest.overlaps(rect)) {
  964. set_rectangle_rectangle_constraints(&constraints, dest, rect);
  965. }
  966. }
  967. }
  968. }
  969. }
  970. return constraints.hit;
  971. }
  972. // =============================================================================
  973. // LOCAL
  974. CustomParticleSystem::SpriteProperties
  975. CustomParticleSystem::get_random_texture() const
  976. {
  977. float val = graphicsRandom.randf(texture_sum_odds);
  978. for (const auto& texture : m_textures)
  979. {
  980. val -= texture.likeliness;
  981. if (val <= 0)
  982. {
  983. return texture;
  984. }
  985. }
  986. return m_textures.at(0);
  987. }
  988. std::vector<ParticleZone::ZoneDetails>
  989. CustomParticleSystem::get_zones() const
  990. {
  991. std::vector<ParticleZone::ZoneDetails> list;
  992. //if (!!GameSession::current() && Sector::current()) {
  993. if (!ParticleEditor::current()) {
  994. // In game or in level editor.
  995. for (auto& zone : GameSession::current()->get_current_sector().get_objects_by_type<ParticleZone>()) {
  996. list.push_back(zone.get_details());
  997. }
  998. } else {
  999. // In particle editor.
  1000. list.push_back(ParticleZone::ZoneDetails(m_name,
  1001. ParticleZone::ParticleZoneType::Spawn,
  1002. Rectf(virtual_width / 2 - 16.f,
  1003. virtual_height / 2 - 16.f,
  1004. virtual_width / 2 + 16.f,
  1005. virtual_height / 2 + 16.f)
  1006. ));
  1007. }
  1008. return list;
  1009. }
  1010. float
  1011. CustomParticleSystem::get_abs_x() const
  1012. {
  1013. return (Sector::current()) ? Sector::get().get_camera().get_translation().x : 0.f;
  1014. }
  1015. float
  1016. CustomParticleSystem::get_abs_y() const
  1017. {
  1018. return (Sector::current()) ? Sector::get().get_camera().get_translation().y : 0.f;
  1019. }
  1020. /** Initializes and adds a single particle to the stack. Performs
  1021. * no check regarding the maximum amount of total particles.
  1022. * @param lifetime The time elapsed since the moment the particle should have been born.
  1023. */
  1024. void
  1025. CustomParticleSystem::add_particle(float lifetime, float x, float y)
  1026. {
  1027. auto particle = std::make_unique<CustomParticle>();
  1028. particle->original_props = get_random_texture();
  1029. particle->props = particle->original_props;
  1030. particle->pos.x = x;
  1031. particle->pos.y = y;
  1032. float life_elapsed = lifetime;
  1033. float birth_delta = m_particle_birth_time_variation / 2;
  1034. particle->total_birth = m_particle_birth_time + graphicsRandom.randf(-birth_delta, birth_delta);
  1035. particle->birth_time = particle->total_birth - life_elapsed;
  1036. if (particle->birth_time < 0.f) {
  1037. life_elapsed = -particle->birth_time;
  1038. particle->birth_time = 0.f;
  1039. } else {
  1040. life_elapsed = 0.f;
  1041. }
  1042. float life_delta = m_particle_lifetime_variation / 2;
  1043. particle->lifetime = m_particle_lifetime - life_elapsed + graphicsRandom.randf(-life_delta, life_delta);
  1044. if (particle->lifetime < 0.f) {
  1045. life_elapsed = -particle->lifetime;
  1046. particle->lifetime = 0.f;
  1047. } else {
  1048. life_elapsed = 0.f;
  1049. }
  1050. float death_delta = m_particle_death_time_variation / 2;
  1051. particle->total_death = m_particle_death_time + graphicsRandom.randf(-death_delta, death_delta);
  1052. particle->death_time = particle->total_death - life_elapsed;
  1053. particle->birth_mode = m_particle_birth_mode;
  1054. particle->death_mode = m_particle_death_mode;
  1055. particle->birth_easing = m_particle_birth_easing;
  1056. particle->death_easing = m_particle_death_easing;
  1057. switch(particle->birth_mode) {
  1058. case FadeMode::Shrink:
  1059. particle->scale = 0.f;
  1060. break;
  1061. default:
  1062. break;
  1063. }
  1064. float speedx_delta = m_particle_speed_variation_x / 2;
  1065. particle->speedX = m_particle_speed_x + graphicsRandom.randf(-speedx_delta, speedx_delta);
  1066. float speedy_delta = m_particle_speed_variation_y / 2;
  1067. particle->speedY = m_particle_speed_y + graphicsRandom.randf(-speedy_delta, speedy_delta);
  1068. particle->accX = m_particle_acceleration_x;
  1069. particle->accY = m_particle_acceleration_y;
  1070. particle->frictionX = m_particle_friction_x;
  1071. particle->frictionY = m_particle_friction_y;
  1072. particle->feather_factor = m_particle_feather_factor;
  1073. float angle_delta = m_particle_rotation_variation / 2;
  1074. particle->angle = m_particle_rotation + graphicsRandom.randf(-angle_delta, angle_delta);
  1075. float angle_speed_delta = m_particle_rotation_speed_variation / 2;
  1076. particle->angle_speed = m_particle_rotation_speed + graphicsRandom.randf(-angle_speed_delta, angle_speed_delta);
  1077. particle->angle_acc = m_particle_rotation_acceleration;
  1078. particle->angle_decc = m_particle_rotation_decceleration;
  1079. particle->angle_mode = m_particle_rotation_mode;
  1080. particle->collision_mode = m_particle_collision_mode;
  1081. particle->offscreen_mode = m_particle_offscreen_mode;
  1082. custom_particles.push_back(std::move(particle));
  1083. }
  1084. void
  1085. CustomParticleSystem::spawn_particles(float lifetime)
  1086. {
  1087. if (!m_cover_screen) {
  1088. for (auto& zone : get_zones()) {
  1089. if (zone.get_type() == ParticleZone::ParticleZoneType::Spawn && zone.get_particle_name() == m_name) {
  1090. Rectf rect = zone.get_rect();
  1091. add_particle(lifetime,
  1092. graphicsRandom.randf(rect.get_width()) + rect.get_left(),
  1093. graphicsRandom.randf(rect.get_height()) + rect.get_top());
  1094. }
  1095. }
  1096. } else {
  1097. float abs_x = get_abs_x();
  1098. float abs_y = get_abs_y();
  1099. add_particle(lifetime,
  1100. graphicsRandom.randf(virtual_width) + abs_x,
  1101. graphicsRandom.randf(virtual_height) + abs_y);
  1102. }
  1103. }
  1104. // SCRIPTING
  1105. void
  1106. CustomParticleSystem::ease_value(float* value, float target, float time, easing func)
  1107. {
  1108. assert(value);
  1109. ease_request req;
  1110. req.value = value;
  1111. req.begin = *value;
  1112. req.end = target;
  1113. req.time_total = time;
  1114. req.time_remain = time;
  1115. req.func = func;
  1116. script_easings.push_back(req);
  1117. }
  1118. void
  1119. CustomParticleSystem::spawn_particles(int amount, bool instantly)
  1120. {
  1121. if (!instantly)
  1122. {
  1123. // TODO: Implement delayed spawn mode for scripting.
  1124. log_warning << "Delayed spawn mode is not yet implemented for scripting." << std::endl;
  1125. return;
  1126. }
  1127. for (int i = 0; i < amount; i++)
  1128. spawn_particles(0.f);
  1129. }
  1130. // =============================================================================
  1131. // ============================ ATTRIBUTES =================================
  1132. // =============================================================================
  1133. std::string
  1134. CustomParticleSystem::get_birth_mode() const
  1135. {
  1136. switch (m_particle_birth_mode)
  1137. {
  1138. case FadeMode::None:
  1139. return "None";
  1140. case FadeMode::Fade:
  1141. return "Fade";
  1142. case FadeMode::Shrink:
  1143. return "Shrink";
  1144. default:
  1145. return "";
  1146. }
  1147. }
  1148. void
  1149. CustomParticleSystem::set_birth_mode(const std::string& mode)
  1150. {
  1151. if (mode == "None")
  1152. m_particle_birth_mode = FadeMode::None;
  1153. else if (mode == "Fade")
  1154. m_particle_birth_mode = FadeMode::Fade;
  1155. else if (mode == "Shrink")
  1156. m_particle_birth_mode = FadeMode::Shrink;
  1157. else
  1158. log_warning << "Invalid option " + mode + "; valid options are: None, Fade, Shrink." << std::endl;
  1159. }
  1160. std::string
  1161. CustomParticleSystem::get_death_mode() const
  1162. {
  1163. switch (m_particle_death_mode)
  1164. {
  1165. case FadeMode::None:
  1166. return "None";
  1167. case FadeMode::Fade:
  1168. return "Fade";
  1169. case FadeMode::Shrink:
  1170. return "Shrink";
  1171. default:
  1172. return "";
  1173. }
  1174. }
  1175. void
  1176. CustomParticleSystem::set_death_mode(const std::string& mode)
  1177. {
  1178. if (mode == "None")
  1179. m_particle_death_mode = FadeMode::None;
  1180. else if (mode == "Fade")
  1181. m_particle_death_mode = FadeMode::Fade;
  1182. else if (mode == "Shrink")
  1183. m_particle_death_mode = FadeMode::Shrink;
  1184. else
  1185. log_warning << "Invalid option " + mode + "; valid options are: None, Fade, Shrink." << std::endl;
  1186. }
  1187. std::string
  1188. CustomParticleSystem::get_rotation_mode() const
  1189. {
  1190. switch (m_particle_rotation_mode)
  1191. {
  1192. case RotationMode::Fixed:
  1193. return "Fixed";
  1194. case RotationMode::Facing:
  1195. return "Facing";
  1196. case RotationMode::Wiggling:
  1197. return "Wiggling";
  1198. default:
  1199. return "";
  1200. }
  1201. }
  1202. void
  1203. CustomParticleSystem::set_rotation_mode(const std::string& mode)
  1204. {
  1205. if (mode == "Fixed")
  1206. m_particle_rotation_mode = RotationMode::Fixed;
  1207. else if (mode == "Facing")
  1208. m_particle_rotation_mode = RotationMode::Facing;
  1209. else if (mode == "Wiggling")
  1210. m_particle_rotation_mode = RotationMode::Wiggling;
  1211. else
  1212. log_warning << "Invalid option " + mode + "; valid options are: Fixed, Facing, Wiggling." << std::endl;
  1213. }
  1214. std::string
  1215. CustomParticleSystem::get_collision_mode() const
  1216. {
  1217. switch (m_particle_collision_mode)
  1218. {
  1219. case CollisionMode::Ignore:
  1220. return "Ignore";
  1221. case CollisionMode::Stick:
  1222. return "Stick";
  1223. case CollisionMode::StickForever:
  1224. return "StickForever";
  1225. case CollisionMode::BounceHeavy:
  1226. return "BounceHeavy";
  1227. case CollisionMode::BounceLight:
  1228. return "BounceLight";
  1229. case CollisionMode::Destroy:
  1230. return "Destroy";
  1231. default:
  1232. return "";
  1233. }
  1234. }
  1235. void
  1236. CustomParticleSystem::set_collision_mode(const std::string& mode)
  1237. {
  1238. if (mode == "Ignore")
  1239. m_particle_collision_mode = CollisionMode::Ignore;
  1240. else if (mode == "Stick")
  1241. m_particle_collision_mode = CollisionMode::Stick;
  1242. else if (mode == "StickForever")
  1243. m_particle_collision_mode = CollisionMode::StickForever;
  1244. else if (mode == "BounceHeavy")
  1245. m_particle_collision_mode = CollisionMode::BounceHeavy;
  1246. else if (mode == "BounceLight")
  1247. m_particle_collision_mode = CollisionMode::BounceLight;
  1248. else if (mode == "Destroy")
  1249. m_particle_collision_mode = CollisionMode::Destroy;
  1250. else
  1251. log_warning << "Invalid option " + mode + "; valid options are: Ignore, Stick, StickForever, BounceHeavy, BounceLight, Destroy." << std::endl;
  1252. }
  1253. std::string
  1254. CustomParticleSystem::get_offscreen_mode() const
  1255. {
  1256. switch (m_particle_offscreen_mode)
  1257. {
  1258. case OffscreenMode::Never:
  1259. return "Never";
  1260. case OffscreenMode::OnlyOnExit:
  1261. return "OnlyOnExit";
  1262. case OffscreenMode::Always:
  1263. return "Always";
  1264. default:
  1265. return "";
  1266. }
  1267. }
  1268. void
  1269. CustomParticleSystem::set_offscreen_mode(const std::string& mode)
  1270. {
  1271. if (mode == "Never")
  1272. m_particle_offscreen_mode = OffscreenMode::Never;
  1273. else if (mode == "OnlyOnExit")
  1274. m_particle_offscreen_mode = OffscreenMode::OnlyOnExit;
  1275. else if (mode == "Always")
  1276. m_particle_offscreen_mode = OffscreenMode::Always;
  1277. else
  1278. log_warning << "Invalid option " + mode + "; valid options are: Never, OnlyOnExit, Always." << std::endl;
  1279. }
  1280. // =============================================================================
  1281. // Delay
  1282. // -----------------------------------------------------------------------------
  1283. void
  1284. CustomParticleSystem::fade_delay(float delay, float time)
  1285. {
  1286. ease_value(&m_delay, delay, time, getEasingByName(EasingMode::EaseNone));
  1287. }
  1288. void
  1289. CustomParticleSystem::ease_delay(float delay, float time, const std::string& easing_)
  1290. {
  1291. ease_value(&m_delay, delay, time, getEasingByName(EasingMode_from_string(easing_)));
  1292. }
  1293. // =============================================================================
  1294. // Lifetime
  1295. // -----------------------------------------------------------------------------
  1296. void
  1297. CustomParticleSystem::fade_lifetime(float lifetime, float time)
  1298. {
  1299. ease_value(&m_particle_lifetime, lifetime, time, getEasingByName(EasingMode::EaseNone));
  1300. }
  1301. void
  1302. CustomParticleSystem::ease_lifetime(float lifetime, float time, const std::string& easing_)
  1303. {
  1304. ease_value(&m_particle_lifetime, lifetime, time, getEasingByName(EasingMode_from_string(easing_)));
  1305. }
  1306. // =============================================================================
  1307. // Lifetime variation
  1308. // -----------------------------------------------------------------------------
  1309. void
  1310. CustomParticleSystem::fade_lifetime_variation(float lifetime_variation, float time)
  1311. {
  1312. ease_value(&m_particle_lifetime_variation, lifetime_variation, time, getEasingByName(EasingMode::EaseNone));
  1313. }
  1314. void
  1315. CustomParticleSystem::ease_lifetime_variation(float lifetime_variation, float time, const std::string& easing_)
  1316. {
  1317. ease_value(&m_particle_lifetime_variation, lifetime_variation, time, getEasingByName(EasingMode_from_string(easing_)));
  1318. }
  1319. // =============================================================================
  1320. // Birth time
  1321. // -----------------------------------------------------------------------------
  1322. void
  1323. CustomParticleSystem::fade_birth_time(float birth_time, float time)
  1324. {
  1325. ease_value(&m_particle_birth_time, birth_time, time, getEasingByName(EasingMode::EaseNone));
  1326. }
  1327. void
  1328. CustomParticleSystem::ease_birth_time(float birth_time, float time, const std::string& easing_)
  1329. {
  1330. ease_value(&m_particle_birth_time, birth_time, time, getEasingByName(EasingMode_from_string(easing_)));
  1331. }
  1332. // =============================================================================
  1333. // Birth time variation
  1334. // -----------------------------------------------------------------------------
  1335. void
  1336. CustomParticleSystem::fade_birth_time_variation(float birth_time_variation, float time)
  1337. {
  1338. ease_value(&m_particle_birth_time_variation, birth_time_variation, time, getEasingByName(EasingMode::EaseNone));
  1339. }
  1340. void
  1341. CustomParticleSystem::ease_birth_time_variation(float birth_time_variation, float time, const std::string& easing_)
  1342. {
  1343. ease_value(&m_particle_birth_time_variation, birth_time_variation, time, getEasingByName(EasingMode_from_string(easing_)));
  1344. }
  1345. // =============================================================================
  1346. // Death time
  1347. // -----------------------------------------------------------------------------
  1348. void
  1349. CustomParticleSystem::fade_death_time(float death_time, float time)
  1350. {
  1351. ease_value(&m_particle_death_time, death_time, time, LinearInterpolation);
  1352. }
  1353. void
  1354. CustomParticleSystem::ease_death_time(float death_time, float time, const std::string& easing_)
  1355. {
  1356. ease_value(&m_particle_death_time, death_time, time, getEasingByName(EasingMode_from_string(easing_)));
  1357. }
  1358. // =============================================================================
  1359. // Death time variation
  1360. // -----------------------------------------------------------------------------
  1361. void
  1362. CustomParticleSystem::fade_death_time_variation(float death_time_variation, float time)
  1363. {
  1364. ease_value(&m_particle_death_time_variation, death_time_variation, time, getEasingByName(EasingMode::EaseNone));
  1365. }
  1366. void
  1367. CustomParticleSystem::ease_death_time_variation(float death_time_variation, float time, const std::string& easing_)
  1368. {
  1369. ease_value(&m_particle_death_time_variation, death_time_variation, time, getEasingByName(EasingMode_from_string(easing_)));
  1370. }
  1371. // =============================================================================
  1372. // X speed
  1373. // -----------------------------------------------------------------------------
  1374. void
  1375. CustomParticleSystem::fade_speed_x(float speed_x, float time)
  1376. {
  1377. ease_value(&m_particle_speed_x, speed_x, time, getEasingByName(EasingMode::EaseNone));
  1378. }
  1379. void
  1380. CustomParticleSystem::ease_speed_x(float speed_x, float time, const std::string& easing_)
  1381. {
  1382. ease_value(&m_particle_speed_x, speed_x, time, getEasingByName(EasingMode_from_string(easing_)));
  1383. }
  1384. // =============================================================================
  1385. // Y speed
  1386. // -----------------------------------------------------------------------------
  1387. void
  1388. CustomParticleSystem::fade_speed_y(float speed_y, float time)
  1389. {
  1390. ease_value(&m_particle_speed_y, speed_y, time, getEasingByName(EasingMode::EaseNone));
  1391. }
  1392. void
  1393. CustomParticleSystem::ease_speed_y(float speed_y, float time, const std::string& easing_)
  1394. {
  1395. ease_value(&m_particle_speed_y, speed_y, time, getEasingByName(EasingMode_from_string(easing_)));
  1396. }
  1397. // =============================================================================
  1398. // X speed variation
  1399. // -----------------------------------------------------------------------------
  1400. void
  1401. CustomParticleSystem::fade_speed_variation_x(float speed_variation_x, float time)
  1402. {
  1403. ease_value(&m_particle_speed_variation_x, speed_variation_x, time, getEasingByName(EasingMode::EaseNone));
  1404. }
  1405. void
  1406. CustomParticleSystem::ease_speed_variation_x(float speed_variation_x, float time, const std::string& easing_)
  1407. {
  1408. ease_value(&m_particle_speed_variation_x, speed_variation_x, time, getEasingByName(EasingMode_from_string(easing_)));
  1409. }
  1410. // =============================================================================
  1411. // Y speed variation
  1412. // -----------------------------------------------------------------------------
  1413. void
  1414. CustomParticleSystem::fade_speed_variation_y(float speed_variation_y, float time)
  1415. {
  1416. ease_value(&m_particle_speed_variation_y, speed_variation_y, time, getEasingByName(EasingMode::EaseNone));
  1417. }
  1418. void
  1419. CustomParticleSystem::ease_speed_variation_y(float speed_variation_y, float time, const std::string& easing_)
  1420. {
  1421. ease_value(&m_particle_speed_variation_y, speed_variation_y, time, getEasingByName(EasingMode_from_string(easing_)));
  1422. }
  1423. // =============================================================================
  1424. // X acceleration
  1425. // -----------------------------------------------------------------------------
  1426. void
  1427. CustomParticleSystem::fade_acceleration_x(float acceleration_x, float time)
  1428. {
  1429. ease_value(&m_particle_acceleration_x, acceleration_x, time, getEasingByName(EasingMode::EaseNone));
  1430. }
  1431. void
  1432. CustomParticleSystem::ease_acceleration_x(float acceleration_x, float time, const std::string& easing_)
  1433. {
  1434. ease_value(&m_particle_acceleration_x, acceleration_x, time, getEasingByName(EasingMode_from_string(easing_)));
  1435. }
  1436. // =============================================================================
  1437. // Y acceleration
  1438. // -----------------------------------------------------------------------------
  1439. void
  1440. CustomParticleSystem::fade_acceleration_y(float acceleration_y, float time)
  1441. {
  1442. ease_value(&m_particle_acceleration_y, acceleration_y, time, getEasingByName(EasingMode::EaseNone));
  1443. }
  1444. void
  1445. CustomParticleSystem::ease_acceleration_y(float acceleration_y, float time, const std::string& easing_)
  1446. {
  1447. ease_value(&m_particle_acceleration_y, acceleration_y, time, getEasingByName(EasingMode_from_string(easing_)));
  1448. }
  1449. // =============================================================================
  1450. // X friction
  1451. // -----------------------------------------------------------------------------
  1452. void
  1453. CustomParticleSystem::fade_friction_x(float friction_x, float time)
  1454. {
  1455. ease_value(&m_particle_friction_x, friction_x, time, getEasingByName(EasingMode::EaseNone));
  1456. }
  1457. void
  1458. CustomParticleSystem::ease_friction_x(float friction_x, float time, const std::string& easing_)
  1459. {
  1460. ease_value(&m_particle_friction_x, friction_x, time, getEasingByName(EasingMode_from_string(easing_)));
  1461. }
  1462. // =============================================================================
  1463. // Y friction
  1464. // -----------------------------------------------------------------------------
  1465. void
  1466. CustomParticleSystem::fade_friction_y(float friction_y, float time)
  1467. {
  1468. ease_value(&m_particle_friction_y, friction_y, time, getEasingByName(EasingMode::EaseNone));
  1469. }
  1470. void
  1471. CustomParticleSystem::ease_friction_y(float friction_y, float time, const std::string& easing_)
  1472. {
  1473. ease_value(&m_particle_friction_y, friction_y, time, getEasingByName(EasingMode_from_string(easing_)));
  1474. }
  1475. // =============================================================================
  1476. // Feather factor
  1477. // -----------------------------------------------------------------------------
  1478. void
  1479. CustomParticleSystem::fade_feather_factor(float feather_factor, float time)
  1480. {
  1481. ease_value(&m_particle_feather_factor, feather_factor, time, getEasingByName(EasingMode::EaseNone));
  1482. }
  1483. void
  1484. CustomParticleSystem::ease_feather_factor(float feather_factor, float time, const std::string& easing_)
  1485. {
  1486. ease_value(&m_particle_feather_factor, feather_factor, time, getEasingByName(EasingMode_from_string(easing_)));
  1487. }
  1488. // =============================================================================
  1489. // Rotation
  1490. // -----------------------------------------------------------------------------
  1491. void
  1492. CustomParticleSystem::fade_rotation(float rotation, float time)
  1493. {
  1494. ease_value(&m_particle_rotation, rotation, time, getEasingByName(EasingMode::EaseNone));
  1495. }
  1496. void
  1497. CustomParticleSystem::ease_rotation(float rotation, float time, const std::string& easing_)
  1498. {
  1499. ease_value(&m_particle_rotation, rotation, time, getEasingByName(EasingMode_from_string(easing_)));
  1500. }
  1501. // =============================================================================
  1502. // Rotation variation
  1503. // -----------------------------------------------------------------------------
  1504. void
  1505. CustomParticleSystem::fade_rotation_variation(float rotation_variation, float time)
  1506. {
  1507. ease_value(&m_particle_rotation_variation, rotation_variation, time, getEasingByName(EasingMode::EaseNone));
  1508. }
  1509. void
  1510. CustomParticleSystem::ease_rotation_variation(float rotation_variation, float time, const std::string& easing_)
  1511. {
  1512. ease_value(&m_particle_rotation_variation, rotation_variation, time, getEasingByName(EasingMode_from_string(easing_)));
  1513. }
  1514. // =============================================================================
  1515. // Rotation speed
  1516. // -----------------------------------------------------------------------------
  1517. void
  1518. CustomParticleSystem::fade_rotation_speed(float rotation_speed, float time)
  1519. {
  1520. ease_value(&m_particle_rotation_speed, rotation_speed, time, getEasingByName(EasingMode::EaseNone));
  1521. }
  1522. void
  1523. CustomParticleSystem::ease_rotation_speed(float rotation_speed, float time, const std::string& easing_)
  1524. {
  1525. ease_value(&m_particle_rotation_speed, rotation_speed, time, getEasingByName(EasingMode_from_string(easing_)));
  1526. }
  1527. // =============================================================================
  1528. // Rotation speed variation
  1529. // -----------------------------------------------------------------------------
  1530. void
  1531. CustomParticleSystem::fade_rotation_speed_variation(float rotation_speed_variation, float time)
  1532. {
  1533. ease_value(&m_particle_rotation_speed_variation, rotation_speed_variation, time, getEasingByName(EasingMode::EaseNone));
  1534. }
  1535. void
  1536. CustomParticleSystem::ease_rotation_speed_variation(float rotation_speed_variation, float time, const std::string& easing_)
  1537. {
  1538. ease_value(&m_particle_rotation_speed_variation, rotation_speed_variation, time, getEasingByName(EasingMode_from_string(easing_)));
  1539. }
  1540. // =============================================================================
  1541. // Rotation acceleration
  1542. // -----------------------------------------------------------------------------
  1543. void
  1544. CustomParticleSystem::fade_rotation_acceleration(float rotation_acceleration, float time)
  1545. {
  1546. ease_value(&m_particle_rotation_acceleration, rotation_acceleration, time, getEasingByName(EasingMode::EaseNone));
  1547. }
  1548. void
  1549. CustomParticleSystem::ease_rotation_acceleration(float rotation_acceleration, float time, const std::string& easing_)
  1550. {
  1551. ease_value(&m_particle_rotation_acceleration, rotation_acceleration, time, getEasingByName(EasingMode_from_string(easing_)));
  1552. }
  1553. // =============================================================================
  1554. // Rotation decceleration
  1555. // -----------------------------------------------------------------------------
  1556. void
  1557. CustomParticleSystem::fade_rotation_decceleration(float rotation_decceleration, float time)
  1558. {
  1559. ease_value(&m_particle_rotation_decceleration, rotation_decceleration, time, getEasingByName(EasingMode::EaseNone));
  1560. }
  1561. void
  1562. CustomParticleSystem::ease_rotation_decceleration(float rotation_decceleration, float time, const std::string& easing_)
  1563. {
  1564. ease_value(&m_particle_rotation_decceleration, rotation_decceleration, time, getEasingByName(EasingMode_from_string(easing_)));
  1565. }
  1566. void
  1567. CustomParticleSystem::register_class(ssq::VM& vm)
  1568. {
  1569. ssq::Class cls = vm.addAbstractClass<CustomParticleSystem>("CustomParticleSystem", vm.findClass("ParticleSystem"));
  1570. cls.addFunc("clear", &CustomParticleSystem::clear);
  1571. cls.addFunc<void, CustomParticleSystem, int, bool>("spawn_particles", &CustomParticleSystem::spawn_particles);
  1572. cls.addFunc("get_max_amount", &CustomParticleSystem::get_max_amount);
  1573. cls.addFunc("set_max_amount", &CustomParticleSystem::set_max_amount);
  1574. cls.addFunc("get_cover_screen", &CustomParticleSystem::get_cover_screen);
  1575. cls.addFunc("set_cover_screen", &CustomParticleSystem::set_cover_screen);
  1576. cls.addFunc("get_birth_mode", &CustomParticleSystem::get_birth_mode);
  1577. cls.addFunc("set_birth_mode", &CustomParticleSystem::set_birth_mode);
  1578. cls.addFunc("get_death_mode", &CustomParticleSystem::get_death_mode);
  1579. cls.addFunc("set_death_mode", &CustomParticleSystem::set_death_mode);
  1580. cls.addFunc("get_rotation_mode", &CustomParticleSystem::get_rotation_mode);
  1581. cls.addFunc("set_rotation_mode", &CustomParticleSystem::set_rotation_mode);
  1582. cls.addFunc("get_collision_mode", &CustomParticleSystem::get_collision_mode);
  1583. cls.addFunc("set_collision_mode", &CustomParticleSystem::set_collision_mode);
  1584. cls.addFunc("get_offscreen_mode", &CustomParticleSystem::get_offscreen_mode);
  1585. cls.addFunc("set_offscreen_mode", &CustomParticleSystem::set_offscreen_mode);
  1586. cls.addFunc("get_delay", &CustomParticleSystem::get_delay);
  1587. cls.addFunc("set_delay", &CustomParticleSystem::set_delay);
  1588. cls.addFunc("fade_delay", &CustomParticleSystem::fade_delay);
  1589. cls.addFunc("ease_delay", &CustomParticleSystem::ease_delay);
  1590. cls.addFunc("get_lifetime", &CustomParticleSystem::get_lifetime);
  1591. cls.addFunc("set_lifetime", &CustomParticleSystem::set_lifetime);
  1592. cls.addFunc("fade_lifetime", &CustomParticleSystem::fade_lifetime);
  1593. cls.addFunc("ease_lifetime", &CustomParticleSystem::ease_lifetime);
  1594. cls.addFunc("get_lifetime_variation", &CustomParticleSystem::get_lifetime_variation);
  1595. cls.addFunc("set_lifetime_variation", &CustomParticleSystem::set_lifetime_variation);
  1596. cls.addFunc("fade_lifetime_variation", &CustomParticleSystem::fade_lifetime_variation);
  1597. cls.addFunc("ease_lifetime_variation", &CustomParticleSystem::ease_lifetime_variation);
  1598. cls.addFunc("get_birth_time", &CustomParticleSystem::get_birth_time);
  1599. cls.addFunc("set_birth_time", &CustomParticleSystem::set_birth_time);
  1600. cls.addFunc("fade_birth_time", &CustomParticleSystem::fade_birth_time);
  1601. cls.addFunc("ease_birth_time", &CustomParticleSystem::ease_birth_time);
  1602. cls.addFunc("get_birth_time_variation", &CustomParticleSystem::get_birth_time_variation);
  1603. cls.addFunc("set_birth_time_variation", &CustomParticleSystem::set_birth_time_variation);
  1604. cls.addFunc("fade_birth_time_variation", &CustomParticleSystem::fade_birth_time_variation);
  1605. cls.addFunc("ease_birth_time_variation", &CustomParticleSystem::ease_birth_time_variation);
  1606. cls.addFunc("get_death_time", &CustomParticleSystem::get_death_time);
  1607. cls.addFunc("set_death_time", &CustomParticleSystem::set_death_time);
  1608. cls.addFunc("fade_death_time", &CustomParticleSystem::fade_death_time);
  1609. cls.addFunc("ease_death_time", &CustomParticleSystem::ease_death_time);
  1610. cls.addFunc("get_death_time_variation", &CustomParticleSystem::get_death_time_variation);
  1611. cls.addFunc("set_death_time_variation", &CustomParticleSystem::set_death_time_variation);
  1612. cls.addFunc("fade_death_time_variation", &CustomParticleSystem::fade_death_time_variation);
  1613. cls.addFunc("ease_death_time_variation", &CustomParticleSystem::ease_death_time_variation);
  1614. cls.addFunc("get_speed_x", &CustomParticleSystem::get_speed_x);
  1615. cls.addFunc("set_speed_x", &CustomParticleSystem::set_speed_x);
  1616. cls.addFunc("fade_speed_x", &CustomParticleSystem::fade_speed_x);
  1617. cls.addFunc("ease_speed_x", &CustomParticleSystem::ease_speed_x);
  1618. cls.addFunc("get_speed_y", &CustomParticleSystem::get_speed_y);
  1619. cls.addFunc("set_speed_y", &CustomParticleSystem::set_speed_y);
  1620. cls.addFunc("fade_speed_y", &CustomParticleSystem::fade_speed_y);
  1621. cls.addFunc("ease_speed_y", &CustomParticleSystem::ease_speed_y);
  1622. cls.addFunc("get_speed_variation_x", &CustomParticleSystem::get_speed_variation_x);
  1623. cls.addFunc("set_speed_variation_x", &CustomParticleSystem::set_speed_variation_x);
  1624. cls.addFunc("fade_speed_variation_x", &CustomParticleSystem::fade_speed_variation_x);
  1625. cls.addFunc("ease_speed_variation_x", &CustomParticleSystem::ease_speed_variation_x);
  1626. cls.addFunc("get_speed_variation_y", &CustomParticleSystem::get_speed_variation_y);
  1627. cls.addFunc("set_speed_variation_y", &CustomParticleSystem::set_speed_variation_y);
  1628. cls.addFunc("fade_speed_variation_y", &CustomParticleSystem::fade_speed_variation_y);
  1629. cls.addFunc("ease_speed_variation_y", &CustomParticleSystem::ease_speed_variation_y);
  1630. cls.addFunc("get_acceleration_x", &CustomParticleSystem::get_acceleration_x);
  1631. cls.addFunc("set_acceleration_x", &CustomParticleSystem::set_acceleration_x);
  1632. cls.addFunc("fade_acceleration_x", &CustomParticleSystem::fade_acceleration_x);
  1633. cls.addFunc("ease_acceleration_x", &CustomParticleSystem::ease_acceleration_x);
  1634. cls.addFunc("get_acceleration_y", &CustomParticleSystem::get_acceleration_y);
  1635. cls.addFunc("set_acceleration_y", &CustomParticleSystem::set_acceleration_y);
  1636. cls.addFunc("fade_acceleration_y", &CustomParticleSystem::fade_acceleration_y);
  1637. cls.addFunc("ease_acceleration_y", &CustomParticleSystem::ease_acceleration_y);
  1638. cls.addFunc("get_friction_x", &CustomParticleSystem::get_friction_x);
  1639. cls.addFunc("set_friction_x", &CustomParticleSystem::set_friction_x);
  1640. cls.addFunc("fade_friction_x", &CustomParticleSystem::fade_friction_x);
  1641. cls.addFunc("ease_friction_x", &CustomParticleSystem::ease_friction_x);
  1642. cls.addFunc("get_friction_y", &CustomParticleSystem::get_friction_y);
  1643. cls.addFunc("set_friction_y", &CustomParticleSystem::set_friction_y);
  1644. cls.addFunc("fade_friction_y", &CustomParticleSystem::fade_friction_y);
  1645. cls.addFunc("ease_friction_y", &CustomParticleSystem::ease_friction_y);
  1646. cls.addFunc("get_feather_factor", &CustomParticleSystem::get_feather_factor);
  1647. cls.addFunc("set_feather_factor", &CustomParticleSystem::set_feather_factor);
  1648. cls.addFunc("fade_feather_factor", &CustomParticleSystem::fade_feather_factor);
  1649. cls.addFunc("ease_feather_factor", &CustomParticleSystem::ease_feather_factor);
  1650. cls.addFunc("get_rotation", &CustomParticleSystem::get_rotation);
  1651. cls.addFunc("set_rotation", &CustomParticleSystem::set_rotation);
  1652. cls.addFunc("fade_rotation", &CustomParticleSystem::fade_rotation);
  1653. cls.addFunc("ease_rotation", &CustomParticleSystem::ease_rotation);
  1654. cls.addFunc("get_rotation_variation", &CustomParticleSystem::get_rotation_variation);
  1655. cls.addFunc("set_rotation_variation", &CustomParticleSystem::set_rotation_variation);
  1656. cls.addFunc("fade_rotation_variation", &CustomParticleSystem::fade_rotation_variation);
  1657. cls.addFunc("ease_rotation_variation", &CustomParticleSystem::ease_rotation_variation);
  1658. cls.addFunc("get_rotation_speed", &CustomParticleSystem::get_rotation_speed);
  1659. cls.addFunc("set_rotation_speed", &CustomParticleSystem::set_rotation_speed);
  1660. cls.addFunc("fade_rotation_speed", &CustomParticleSystem::fade_rotation_speed);
  1661. cls.addFunc("ease_rotation_speed", &CustomParticleSystem::ease_rotation_speed);
  1662. cls.addFunc("get_rotation_speed_variation", &CustomParticleSystem::get_rotation_speed_variation);
  1663. cls.addFunc("set_rotation_speed_variation", &CustomParticleSystem::set_rotation_speed_variation);
  1664. cls.addFunc("fade_rotation_speed_variation", &CustomParticleSystem::fade_rotation_speed_variation);
  1665. cls.addFunc("ease_rotation_speed_variation", &CustomParticleSystem::ease_rotation_speed_variation);
  1666. cls.addFunc("get_rotation_acceleration", &CustomParticleSystem::get_rotation_acceleration);
  1667. cls.addFunc("set_rotation_acceleration", &CustomParticleSystem::set_rotation_acceleration);
  1668. cls.addFunc("fade_rotation_acceleration", &CustomParticleSystem::fade_rotation_acceleration);
  1669. cls.addFunc("ease_rotation_acceleration", &CustomParticleSystem::ease_rotation_acceleration);
  1670. cls.addFunc("get_rotation_decceleration", &CustomParticleSystem::get_rotation_decceleration);
  1671. cls.addFunc("set_rotation_decceleration", &CustomParticleSystem::set_rotation_decceleration);
  1672. cls.addFunc("fade_rotation_decceleration", &CustomParticleSystem::fade_rotation_decceleration);
  1673. cls.addFunc("ease_rotation_decceleration", &CustomParticleSystem::ease_rotation_decceleration);
  1674. cls.addVar("max_amount", &CustomParticleSystem::m_max_amount);
  1675. cls.addVar("cover_screen", &CustomParticleSystem::m_cover_screen);
  1676. cls.addVar("delay", &CustomParticleSystem::m_delay);
  1677. cls.addVar("particle_lifetime", &CustomParticleSystem::m_particle_lifetime);
  1678. cls.addVar("particle_lifetime_variation", &CustomParticleSystem::m_particle_lifetime_variation);
  1679. cls.addVar("particle_birth_time", &CustomParticleSystem::m_particle_birth_time);
  1680. cls.addVar("particle_birth_time_variation", &CustomParticleSystem::m_particle_birth_time_variation);
  1681. cls.addVar("particle_death_time", &CustomParticleSystem::m_particle_death_time);
  1682. cls.addVar("particle_death_time_variation", &CustomParticleSystem::m_particle_death_time_variation);
  1683. cls.addVar("particle_speed_x", &CustomParticleSystem::m_particle_speed_x);
  1684. cls.addVar("particle_speed_y", &CustomParticleSystem::m_particle_speed_y);
  1685. cls.addVar("particle_speed_variation_x", &CustomParticleSystem::m_particle_speed_variation_x);
  1686. cls.addVar("particle_speed_variation_y", &CustomParticleSystem::m_particle_speed_variation_y);
  1687. cls.addVar("particle_acceleration_x", &CustomParticleSystem::m_particle_acceleration_x);
  1688. cls.addVar("particle_acceleration_y", &CustomParticleSystem::m_particle_acceleration_y);
  1689. cls.addVar("particle_friction_x", &CustomParticleSystem::m_particle_friction_x);
  1690. cls.addVar("particle_friction_y", &CustomParticleSystem::m_particle_friction_y);
  1691. cls.addVar("particle_feather_factor", &CustomParticleSystem::m_particle_feather_factor);
  1692. cls.addVar("particle_rotation", &CustomParticleSystem::m_particle_rotation);
  1693. cls.addVar("particle_rotation_variation", &CustomParticleSystem::m_particle_rotation_variation);
  1694. cls.addVar("particle_rotation_speed", &CustomParticleSystem::m_particle_rotation_speed);
  1695. cls.addVar("particle_rotation_speed_variation", &CustomParticleSystem::m_particle_rotation_speed_variation);
  1696. cls.addVar("particle_rotation_acceleration", &CustomParticleSystem::m_particle_rotation_acceleration);
  1697. cls.addVar("particle_rotation_decceleration", &CustomParticleSystem::m_particle_rotation_decceleration);
  1698. }
  1699. /* EOF */