particlebase.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. \brief Invokers for ParticleBase events, called from events
  3. @code
  4. void EnableOnEndPrint(ParticleBase psrc)
  5. {
  6. psrc.GetEvents().Event_OnParticleEnd.Insert(PrintParticleEnded);
  7. }
  8. void PrintParticleEnded(ParticleBase psrc)
  9. {
  10. Print(string.Format("%1 ended.", psrc.GetDebugNameNative());
  11. }
  12. @endcode
  13. */
  14. class ParticleEvents
  15. {
  16. /**
  17. \brief Called when particle starts playing
  18. \note Particle: Called when any Play method has been called
  19. \note ParticleSource: Called when PlayParticleNative is successful
  20. */
  21. ref ScriptInvoker Event_OnParticleStart = new ScriptInvoker();
  22. /**
  23. \brief Called when particle stops playing
  24. \note Particle: Called when any Stop method has been called or when lifetime is over
  25. \note ParticleSource: Called when StopParticleNative is successful, when the particle ends and when the particle is destroyed while it is playing
  26. */
  27. ref ScriptInvoker Event_OnParticleStop = new ScriptInvoker();
  28. /**
  29. \brief Called when particle is reset
  30. \note Particle: Not present, there is no reset functionality
  31. \note ParticleSource: Called when ResetParticleNative is successful
  32. */
  33. ref ScriptInvoker Event_OnParticleReset = new ScriptInvoker();
  34. /**
  35. \brief Called when particle ends
  36. \note Particle: Called when lifetime is over and there are no emitors active anymore
  37. \note ParticleSource: Called when particle ends naturally or after the particle is stopped and there are no emitors active anymore
  38. \warning Looped never ends naturally and need to be stopped
  39. */
  40. ref ScriptInvoker Event_OnParticleEnd = new ScriptInvoker();
  41. /**
  42. \brief Called when particle receives a parent
  43. \note Particle: Not present
  44. */
  45. ref ScriptInvoker Event_OnParticleParented = new ScriptInvoker();
  46. /**
  47. \brief Called when particle is orphaned
  48. \note Particle: Not present
  49. */
  50. ref ScriptInvoker Event_OnParticleUnParented = new ScriptInvoker();
  51. }
  52. /**
  53. \brief Engine base class with internal functionality
  54. \note Is NOT intended for direct creation
  55. * As this does not have an actual particle
  56. * Use either Particle or ParticleSource
  57. */
  58. class ParticleBase : Entity
  59. {
  60. //! Whether the particle is currently playing
  61. protected bool m_IsPlaying;
  62. //! Event invokers
  63. protected ref ParticleEvents m_EventInvokers;
  64. //! ctor
  65. void ParticleBase()
  66. {
  67. m_EventInvokers = new ParticleEvents();
  68. }
  69. //! Have script recognize this as a Particle without casting
  70. override bool IsParticle()
  71. {
  72. return true;
  73. }
  74. /** \name Playback
  75. Methods regarding playing/stopping of particle
  76. */
  77. //@{
  78. /**
  79. \brief Method to tell the particle to start playing
  80. \param particle_id \p int Particle ID registered in ParticleList to start playing
  81. \return \p bool Whether the particle successfully started
  82. */
  83. void PlayParticle(int particle_id = -1)
  84. {
  85. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  86. }
  87. /**
  88. \brief Method to tell the particle to start playing
  89. \param particle_id \p int Particle ID registered in ParticleList to start playing
  90. \param flags \p int Flags to pass to the playing
  91. \return \p bool Whether the particle successfully started
  92. */
  93. bool PlayParticleEx(int particle_id = -1, int flags = 0)
  94. {
  95. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  96. return false;
  97. }
  98. /**
  99. \brief Method to tell the particle to stop playing
  100. \param flags \p int Flags to pass to the stopping
  101. \return \p bool Whether the particle successfully stopped
  102. */
  103. bool StopParticle(int flags = 0)
  104. {
  105. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  106. return false;
  107. }
  108. /**
  109. \brief Method to tell the particle to reset
  110. \return \p bool Whether the particle successfully reset
  111. */
  112. bool ResetParticle()
  113. {
  114. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  115. return false;
  116. }
  117. /**
  118. \brief Method to tell the particle to restart (reset + play)
  119. \return \p bool Whether the particle successfully restarted
  120. */
  121. bool RestartParticle()
  122. {
  123. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  124. return false;
  125. }
  126. /**
  127. \brief Ask if the particle is still playing
  128. \return \p bool Whether the particle is playing
  129. */
  130. bool IsParticlePlaying()
  131. {
  132. ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
  133. return false;
  134. }
  135. //@}
  136. /**
  137. \brief Get the events
  138. \return \p ParticleEvents If there is any events set, this will return them so that additional functionality can be bound to them
  139. */
  140. ParticleEvents GetEvents()
  141. {
  142. return m_EventInvokers;
  143. }
  144. /** \name Events
  145. * ParticleBase events
  146. * For ParticleSource, these are handed on C++ side
  147. * For more information, read ParticleEvents
  148. */
  149. //@{
  150. /**
  151. \brief Event when the particle starts
  152. */
  153. protected void OnParticleStart()
  154. {
  155. m_IsPlaying = true;
  156. GetEvents().Event_OnParticleStart.Invoke(this);
  157. }
  158. /**
  159. \brief Event when the particle stops
  160. */
  161. protected void OnParticleStop()
  162. {
  163. m_IsPlaying = false;
  164. GetEvents().Event_OnParticleStop.Invoke(this);
  165. }
  166. /**
  167. \brief Event when the particle is restarted
  168. */
  169. protected void OnParticleReset()
  170. {
  171. GetEvents().Event_OnParticleReset.Invoke(this);
  172. }
  173. /**
  174. \brief Event when the particle ends
  175. \note Looping particles will never end
  176. */
  177. protected void OnParticleEnd()
  178. {
  179. GetEvents().Event_OnParticleEnd.Invoke(this);
  180. }
  181. /**
  182. \brief Event when the particle receives a parent
  183. */
  184. protected void OnParticleParented(IEntity parent)
  185. {
  186. GetEvents().Event_OnParticleParented.Invoke(this);
  187. }
  188. /**
  189. \brief Event when the particle is orphaned
  190. */
  191. protected void OnParticleUnParented(IEntity parent)
  192. {
  193. GetEvents().Event_OnParticleUnParented.Invoke(this);
  194. }
  195. //@}
  196. }