EmitterInstanceList.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : W3DView *
  23. * *
  24. * $Archive:: /VSS_Sync/W3DView/EmitterInstanceList.cpp $Modtime:: $*
  25. * *
  26. * $Revision:: 7 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #include "StdAfx.H"
  32. #include "EmitterInstanceList.H"
  33. #include "Utils.H"
  34. /////////////////////////////////////////////////////////////////////
  35. //
  36. // ~EmitterInstanceListClass
  37. //
  38. /////////////////////////////////////////////////////////////////////
  39. EmitterInstanceListClass::~EmitterInstanceListClass (void)
  40. {
  41. Free_List ();
  42. return ;
  43. }
  44. /////////////////////////////////////////////////////////////////////
  45. //
  46. // Free_List
  47. //
  48. /////////////////////////////////////////////////////////////////////
  49. void
  50. EmitterInstanceListClass::Free_List (void)
  51. {
  52. //
  53. // Release our hold on each of the emitter pointers
  54. //
  55. for (int index = 0; index < m_List.Count (); index ++) {
  56. MEMBER_RELEASE (m_List[index]);
  57. }
  58. m_List.Delete_All ();
  59. return ;
  60. }
  61. /////////////////////////////////////////////////////////////////////
  62. //
  63. // Add_Emitter
  64. //
  65. /////////////////////////////////////////////////////////////////////
  66. void
  67. EmitterInstanceListClass::Add_Emitter (ParticleEmitterClass *emitter)
  68. {
  69. ASSERT (emitter != NULL);
  70. if (emitter != NULL) {
  71. //
  72. // If this is the first emitter in the list, then initialize
  73. // the definition to it's state
  74. //
  75. if (m_List.Count () == 0) {
  76. ParticleEmitterDefClass *def = emitter->Build_Definition ();
  77. if (def != NULL) {
  78. ParticleEmitterDefClass::operator= (*def);
  79. SAFE_DELETE (def);
  80. }
  81. }
  82. //
  83. // Add this emitter to the list and put a hold on its reference
  84. //
  85. SAFE_ADD_REF (emitter);
  86. m_List.Add (emitter);
  87. }
  88. return ;
  89. }
  90. /////////////////////////////////////////////////////////////////////
  91. //
  92. // Set_Velocity
  93. //
  94. /////////////////////////////////////////////////////////////////////
  95. void
  96. EmitterInstanceListClass::Set_Velocity (const Vector3 &value)
  97. {
  98. ParticleEmitterDefClass::Set_Velocity (value);
  99. //
  100. // Pass this setting onto the emitters immediately
  101. //
  102. for (int index = 0; index < m_List.Count (); index ++) {
  103. m_List[index]->Set_Base_Velocity (value);
  104. }
  105. return ;
  106. }
  107. /////////////////////////////////////////////////////////////////////
  108. //
  109. // Set_Acceleration
  110. //
  111. /////////////////////////////////////////////////////////////////////
  112. void
  113. EmitterInstanceListClass::Set_Acceleration (const Vector3 &value)
  114. {
  115. ParticleEmitterDefClass::Set_Acceleration (value);
  116. //
  117. // Pass this setting onto the emitters immediately
  118. //
  119. for (int index = 0; index < m_List.Count (); index ++) {
  120. m_List[index]->Set_Acceleration (value);
  121. }
  122. return ;
  123. }
  124. /////////////////////////////////////////////////////////////////////
  125. //
  126. // Set_Burst_Size
  127. //
  128. /////////////////////////////////////////////////////////////////////
  129. void
  130. EmitterInstanceListClass::Set_Burst_Size (unsigned int count)
  131. {
  132. ParticleEmitterDefClass::Set_Burst_Size (count);
  133. //
  134. // Pass this setting onto the emitters immediately
  135. //
  136. for (int index = 0; index < m_List.Count (); index ++) {
  137. m_List[index]->Set_Burst_Size (count);
  138. }
  139. return ;
  140. }
  141. /////////////////////////////////////////////////////////////////////
  142. //
  143. // Set_Outward_Vel
  144. //
  145. /////////////////////////////////////////////////////////////////////
  146. void
  147. EmitterInstanceListClass::Set_Outward_Vel (float value)
  148. {
  149. ParticleEmitterDefClass::Set_Outward_Vel (value);
  150. //
  151. // Pass this setting onto the emitters immediately
  152. //
  153. for (int index = 0; index < m_List.Count (); index ++) {
  154. m_List[index]->Set_Outwards_Velocity (value);
  155. }
  156. return ;
  157. }
  158. /////////////////////////////////////////////////////////////////////
  159. //
  160. // Set_Vel_Inherit
  161. //
  162. /////////////////////////////////////////////////////////////////////
  163. void
  164. EmitterInstanceListClass::Set_Vel_Inherit (float value)
  165. {
  166. ParticleEmitterDefClass::Set_Vel_Inherit (value);
  167. //
  168. // Pass this setting onto the emitters immediately
  169. //
  170. for (int index = 0; index < m_List.Count (); index ++) {
  171. m_List[index]->Set_Velocity_Inheritance_Factor (value);
  172. }
  173. return ;
  174. }
  175. /////////////////////////////////////////////////////////////////////
  176. //
  177. // Set_Velocity_Random
  178. //
  179. /////////////////////////////////////////////////////////////////////
  180. void
  181. EmitterInstanceListClass::Set_Velocity_Random (Vector3Randomizer *randomizer)
  182. {
  183. ParticleEmitterDefClass::Set_Velocity_Random (randomizer);
  184. if (randomizer != NULL) {
  185. //
  186. // Pass this setting onto the emitters immediately
  187. //
  188. for (int index = 0; index < m_List.Count (); index ++) {
  189. m_List[index]->Set_Velocity_Randomizer (randomizer->Clone ());
  190. }
  191. }
  192. return ;
  193. }
  194. /////////////////////////////////////////////////////////////////////
  195. //
  196. // Set_Color_Keyframes
  197. //
  198. /////////////////////////////////////////////////////////////////////
  199. void
  200. EmitterInstanceListClass::Set_Color_Keyframes (ParticlePropertyStruct<Vector3> &keyframes)
  201. {
  202. //
  203. // Make sure tha any value that is supposed to go to zero, really
  204. // does even if its got a randomizer.
  205. //
  206. if ( (keyframes.Rand.X != 0) ||
  207. (keyframes.Rand.Y != 0) ||
  208. (keyframes.Rand.Z != 0))
  209. {
  210. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  211. if ((keyframes.Values[index].X <= 0.000001F) &&
  212. (keyframes.Values[index].Y <= 0.000001F) &&
  213. (keyframes.Values[index].Z <= 0.000001F)) {
  214. keyframes.Values[index].X = -keyframes.Rand.X;
  215. keyframes.Values[index].Y = -keyframes.Rand.Y;
  216. keyframes.Values[index].Z = -keyframes.Rand.Z;
  217. }
  218. }
  219. }
  220. ParticleEmitterDefClass::Set_Color_Keyframes (keyframes);
  221. //
  222. // Pass this setting onto the emitters immediately
  223. //
  224. for (int index = 0; index < m_List.Count (); index ++) {
  225. m_List[index]->Reset_Colors (keyframes);
  226. }
  227. return ;
  228. }
  229. /////////////////////////////////////////////////////////////////////
  230. //
  231. // Set_Opacity_Keyframes
  232. //
  233. /////////////////////////////////////////////////////////////////////
  234. void
  235. EmitterInstanceListClass::Set_Opacity_Keyframes (ParticlePropertyStruct<float> &keyframes)
  236. {
  237. //
  238. // Make sure tha any value that is supposed to go to zero, really
  239. // does even if its got a randomizer.
  240. //
  241. if (keyframes.Rand != 0)
  242. {
  243. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  244. if (keyframes.Values[index] <= 0.000001F) {
  245. keyframes.Values[index] = -keyframes.Rand;
  246. }
  247. }
  248. }
  249. ParticleEmitterDefClass::Set_Opacity_Keyframes (keyframes);
  250. //
  251. // Pass this setting onto the emitters immediately
  252. //
  253. for (int index = 0; index < m_List.Count (); index ++) {
  254. m_List[index]->Reset_Opacity (keyframes);
  255. }
  256. return ;
  257. }
  258. /////////////////////////////////////////////////////////////////////
  259. //
  260. // Set_Size_Keyframes
  261. //
  262. /////////////////////////////////////////////////////////////////////
  263. void
  264. EmitterInstanceListClass::Set_Size_Keyframes (ParticlePropertyStruct<float> &keyframes)
  265. {
  266. //
  267. // Make sure tha any value that is supposed to go to zero, really
  268. // does even if its got a randomizer.
  269. //
  270. if (keyframes.Rand != 0)
  271. {
  272. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  273. if (keyframes.Values[index] <= 0.000001F) {
  274. keyframes.Values[index] = -keyframes.Rand;
  275. }
  276. }
  277. }
  278. ParticleEmitterDefClass::Set_Size_Keyframes (keyframes);
  279. //
  280. // Pass this setting onto the emitters immediately
  281. //
  282. for (int index = 0; index < m_List.Count (); index ++) {
  283. m_List[index]->Reset_Size (keyframes);
  284. }
  285. return ;
  286. }
  287. /////////////////////////////////////////////////////////////////////
  288. //
  289. // Set_Rotation_Keyframes
  290. //
  291. /////////////////////////////////////////////////////////////////////
  292. void
  293. EmitterInstanceListClass::Set_Rotation_Keyframes (ParticlePropertyStruct<float> &keyframes, float orient_rnd)
  294. {
  295. ParticleEmitterDefClass::Set_Rotation_Keyframes (keyframes, orient_rnd);
  296. //
  297. // Pass this setting onto the emitters immediately
  298. //
  299. for (int index = 0; index < m_List.Count (); index ++) {
  300. m_List[index]->Reset_Rotations (keyframes, orient_rnd);
  301. }
  302. return ;
  303. }
  304. /////////////////////////////////////////////////////////////////////
  305. //
  306. // Set_Frame_Keyframes
  307. //
  308. /////////////////////////////////////////////////////////////////////
  309. void
  310. EmitterInstanceListClass::Set_Frame_Keyframes (ParticlePropertyStruct<float> &keyframes)
  311. {
  312. ParticleEmitterDefClass::Set_Frame_Keyframes (keyframes);
  313. //
  314. // Pass this setting onto the emitters immediately
  315. //
  316. for (int index = 0; index < m_List.Count (); index ++) {
  317. m_List[index]->Reset_Frames (keyframes);
  318. }
  319. return ;
  320. }
  321. /////////////////////////////////////////////////////////////////////
  322. //
  323. // Set_Blur_Time_Keyframes
  324. //
  325. /////////////////////////////////////////////////////////////////////
  326. void
  327. EmitterInstanceListClass::Set_Blur_Time_Keyframes (ParticlePropertyStruct<float> &keyframes)
  328. {
  329. ParticleEmitterDefClass::Set_Blur_Time_Keyframes (keyframes);
  330. //
  331. // Pass this setting onto the emitters immediately
  332. //
  333. for (int index = 0; index < m_List.Count (); index ++) {
  334. m_List[index]->Reset_Blur_Times (keyframes);
  335. }
  336. return ;
  337. }
  338. ///////////////////////////////////////////////////////////////////////////////////
  339. //
  340. // Get_Color_Keyframes
  341. //
  342. void
  343. EmitterInstanceListClass::Get_Color_Keyframes (ParticlePropertyStruct<Vector3> &keyframes) const
  344. {
  345. ParticleEmitterDefClass::Get_Color_Keyframes (keyframes);
  346. //
  347. // Normalize the data
  348. //
  349. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  350. if (keyframes.Values[index].X <= 0.000001F) {
  351. keyframes.Values[index].X = 0;
  352. }
  353. if (keyframes.Values[index].Y <= 0.000001F) {
  354. keyframes.Values[index].Y = 0;
  355. }
  356. if (keyframes.Values[index].Z <= 0.000001F) {
  357. keyframes.Values[index].Z = 0;
  358. }
  359. }
  360. return ;
  361. }
  362. ///////////////////////////////////////////////////////////////////////////////////
  363. //
  364. // Get_Opacity_Keyframes
  365. //
  366. void
  367. EmitterInstanceListClass::Get_Opacity_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  368. {
  369. ParticleEmitterDefClass::Get_Opacity_Keyframes (keyframes);
  370. //
  371. // Normalize the data
  372. //
  373. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  374. if (keyframes.Values[index] <= 0.000001F) {
  375. keyframes.Values[index] = 0;
  376. }
  377. }
  378. return ;
  379. }
  380. ///////////////////////////////////////////////////////////////////////////////////
  381. //
  382. // Get_Size_Keyframes
  383. //
  384. void
  385. EmitterInstanceListClass::Get_Size_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  386. {
  387. ParticleEmitterDefClass::Get_Size_Keyframes (keyframes);
  388. //
  389. // Normalize the data
  390. //
  391. for (UINT index = 0; index < keyframes.NumKeyFrames; index ++) {
  392. if (keyframes.Values[index] <= 0.000001F) {
  393. keyframes.Values[index] = 0;
  394. }
  395. }
  396. return ;
  397. }