particleSystem.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. // Filename: particleSystem.cxx
  2. // Created by: charles (14Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include <stdlib.h>
  19. #include "luse.h"
  20. #include "lmat_ops.h"
  21. #include "clockObject.h"
  22. #include "physicsManager.h"
  23. #include "physicalNode.h"
  24. #include "nearly_zero.h"
  25. #include "transformState.h"
  26. #include "nodePath.h"
  27. #include "config_particlesystem.h"
  28. #include "particleSystem.h"
  29. #include "particleSystemManager.h"
  30. #include "pointParticleRenderer.h"
  31. #include "pointParticleFactory.h"
  32. #include "sphereSurfaceEmitter.h"
  33. TypeHandle ParticleSystem::_type_handle;
  34. ////////////////////////////////////////////////////////////////////
  35. // Function : ParticleSystem
  36. // Access : Public
  37. // Description : Default Constructor.
  38. ////////////////////////////////////////////////////////////////////
  39. ParticleSystem::
  40. ParticleSystem(int pool_size) :
  41. Physical(pool_size, false)
  42. {
  43. _birth_rate = 0.5f;
  44. _tics_since_birth = _birth_rate;
  45. _litter_size = 1;
  46. _litter_spread = 0;
  47. _living_particles = 0;
  48. _active_system_flag = true;
  49. _local_velocity_flag = true;
  50. _spawn_on_death_flag = false;
  51. _system_grows_older_flag = false;
  52. _system_lifespan = 0.0f;
  53. _i_was_spawned_flag = false;
  54. _particle_pool_size = 0;
  55. _floor_z = -HUGE_VAL;
  56. // just in case someone tries to do something that requires the
  57. // use of an emitter, renderer, or factory before they've actually
  58. // assigned one. This is ok, because assigning them (set_renderer(),
  59. // set_emitter(), etc...) forces them to set themselves up for the
  60. // system, keeping the pool sizes consistent.
  61. _render_node.clear();
  62. _render_parent = new PandaNode("ParticleSystem default render parent");
  63. set_emitter(new SphereSurfaceEmitter);
  64. set_renderer(new PointParticleRenderer);
  65. //set_factory(new PointParticleFactory);
  66. _factory = new PointParticleFactory;
  67. clear_physics_objects();
  68. set_pool_size(pool_size);
  69. }
  70. ////////////////////////////////////////////////////////////////////
  71. // Function : ParticleSystem
  72. // Access : Public
  73. // Description : Copy Constructor.
  74. ////////////////////////////////////////////////////////////////////
  75. ParticleSystem::
  76. ParticleSystem(const ParticleSystem& copy) :
  77. Physical(copy),
  78. _system_age(0.0f),
  79. _template_system_flag(false)
  80. {
  81. _birth_rate = copy._birth_rate;
  82. _litter_size = copy._litter_size;
  83. _litter_spread = copy._litter_spread;
  84. _active_system_flag = copy._active_system_flag;
  85. _local_velocity_flag = copy._local_velocity_flag;
  86. _spawn_on_death_flag = copy._spawn_on_death_flag;
  87. _i_was_spawned_flag = copy._i_was_spawned_flag;
  88. _system_grows_older_flag = copy._system_grows_older_flag;
  89. _emitter = copy._emitter;
  90. _renderer = copy._renderer->make_copy();
  91. _factory = copy._factory;
  92. _render_parent = copy._render_parent;
  93. _render_node = _renderer->get_render_node();
  94. _render_parent->add_child(_render_node);
  95. _tics_since_birth = _birth_rate;
  96. _system_lifespan = copy._system_lifespan;
  97. _living_particles = 0;
  98. set_pool_size(copy._particle_pool_size);
  99. }
  100. ////////////////////////////////////////////////////////////////////
  101. // Function : ~ParticleSystem
  102. // Access : Public
  103. // Description : You get the ankles and I'll get the wrists.
  104. ////////////////////////////////////////////////////////////////////
  105. ParticleSystem::
  106. ~ParticleSystem() {
  107. set_pool_size(0);
  108. if (!_template_system_flag) {
  109. _renderer.clear();
  110. if (!_render_node.is_null())
  111. _render_parent->remove_child(_render_node);
  112. }
  113. }
  114. ////////////////////////////////////////////////////////////////////
  115. // Function : birth_particle
  116. // Access : Private
  117. // Description : A new particle is born. This doesn't allocate,
  118. // resets an element from the particle pool.
  119. ////////////////////////////////////////////////////////////////////
  120. bool ParticleSystem::
  121. birth_particle() {
  122. int pool_index;
  123. // make sure there's room for a new particle
  124. if (_living_particles >= _particle_pool_size) {
  125. #ifdef PSDEBUG
  126. if (_living_particles > _particle_pool_size) {
  127. cout << "_living_particles > _particle_pool_size" << endl;
  128. }
  129. #endif
  130. return false;
  131. }
  132. #ifdef PSDEBUG
  133. if (0 == _free_particle_fifo.size()) {
  134. cout << "Error: _free_particle_fifo is empty, but _living_particles < _particle_pool_size" << endl;
  135. return false;
  136. }
  137. #endif
  138. pool_index = _free_particle_fifo.back();
  139. _free_particle_fifo.pop_back();
  140. // get a handle on our particle.
  141. BaseParticle *bp = (BaseParticle *) _physics_objects[pool_index].p();
  142. // start filling out the variables.
  143. _factory->populate_particle(bp);
  144. bp->set_alive(true);
  145. bp->set_active(true);
  146. bp->init();
  147. // get the location of the new particle.
  148. LPoint3f new_pos, world_pos;
  149. LVector3f new_vel;
  150. GeomNode *render_node;
  151. _emitter->generate(new_pos, new_vel);
  152. render_node = _renderer->get_render_node();
  153. // go from birth space to render space
  154. NodePath physical_np(get_physical_node());
  155. NodePath render_np(render_node);
  156. CPT(TransformState) transform = physical_np.get_transform(render_np);
  157. const LMatrix4f &birth_to_render_xform = transform->get_mat();
  158. world_pos = new_pos * birth_to_render_xform;
  159. // cout << "New particle at " << world_pos << endl;
  160. // possibly transform the initial velocity as well.
  161. if (_local_velocity_flag == false)
  162. new_vel = new_vel * birth_to_render_xform;
  163. bp->reset_position(world_pos/* + (NORMALIZED_RAND() * new_vel)*/);
  164. bp->set_velocity(new_vel);
  165. ++_living_particles;
  166. // propogate information down to renderer
  167. _renderer->birth_particle(pool_index);
  168. return true;
  169. }
  170. ////////////////////////////////////////////////////////////////////
  171. // Function : birth_litter
  172. // Access : Private
  173. // Description : spawns a new batch of particles
  174. ////////////////////////////////////////////////////////////////////
  175. void ParticleSystem::
  176. birth_litter() {
  177. int litter_size, i;
  178. litter_size = _litter_size;
  179. if (_litter_spread != 0)
  180. litter_size += I_SPREAD(_litter_spread);
  181. for (i = 0; i < litter_size; ++i) {
  182. if (birth_particle() == false)
  183. return;
  184. }
  185. }
  186. ////////////////////////////////////////////////////////////////////
  187. // Function : spawn_child_system
  188. // Access : private
  189. // Description : Creates a new particle system based on local
  190. // template info and adds it to the ps and physics
  191. // managers
  192. ////////////////////////////////////////////////////////////////////
  193. void ParticleSystem::
  194. spawn_child_system(BaseParticle *bp) {
  195. // first, make sure that the system exists in the graph via a
  196. // physicalnode reference.
  197. PhysicalNode *this_pn = get_physical_node();
  198. if (!this_pn) {
  199. physics_cat.error() << "ParticleSystem::spawn_child_system: "
  200. << "Spawning system is not in the scene graph,"
  201. << " aborting." << endl;
  202. return;
  203. }
  204. if (this_pn->get_num_parents() == 0) {
  205. physics_cat.error() << "ParticleSystem::spawn_child_system: "
  206. << "PhysicalNode this system is contained in "
  207. << "has no parent, aborting." << endl;
  208. return;
  209. }
  210. PandaNode *parent = this_pn->get_parent(0);
  211. // handle the spawn templates
  212. int new_ps_index = rand() % _spawn_templates.size();
  213. ParticleSystem *ps_template = _spawn_templates[new_ps_index];
  214. // create a new particle system
  215. PT(ParticleSystem) new_ps = new ParticleSystem(*ps_template);
  216. new_ps->_i_was_spawned_flag = true;
  217. // first, set up the render node info.
  218. new_ps->_render_parent = _spawn_render_node;
  219. new_ps->_render_node = new_ps->_renderer->get_render_node();
  220. new_ps->_render_parent->add_child(new_ps->_render_node);
  221. // now set up the new system's PhysicalNode.
  222. PT(PhysicalNode) new_pn = new PhysicalNode("new_pn");
  223. new_pn->add_physical(new_ps);
  224. // the transform on the new child has to represent the transform
  225. // from the current system up to its parent, and then subsequently
  226. // down to the new child.
  227. parent->add_child(new_pn);
  228. NodePath parent_np(parent);
  229. NodePath physical_np(get_physical_node());
  230. CPT(TransformState) transform = physical_np.get_transform(parent_np);
  231. const LMatrix4f &old_system_to_parent_xform = transform->get_mat();
  232. LMatrix4f child_space_xform = old_system_to_parent_xform *
  233. bp->get_lcs();
  234. new_pn->set_transform(TransformState::make_mat(child_space_xform));
  235. // tack the new system onto the managers
  236. _manager->attach_particlesystem(new_ps);
  237. get_physics_manager()->attach_physical(new_ps);
  238. }
  239. ////////////////////////////////////////////////////////////////////
  240. // Function : kill_particle
  241. // Access : Private
  242. // Description : Kills a particle, returns its slot to the empty
  243. // stack.
  244. ////////////////////////////////////////////////////////////////////
  245. void ParticleSystem::
  246. kill_particle(int pool_index) {
  247. // get a handle on our particle
  248. BaseParticle *bp = (BaseParticle *) _physics_objects[pool_index].p();
  249. // create a new system where this one died, maybe.
  250. if (_spawn_on_death_flag == true) {
  251. spawn_child_system(bp);
  252. }
  253. // tell everyone that it's dead
  254. bp->set_alive(false);
  255. bp->set_active(false);
  256. bp->die();
  257. _free_particle_fifo.push_back(pool_index);
  258. // tell renderer
  259. _renderer->kill_particle(pool_index);
  260. _living_particles--;
  261. }
  262. ////////////////////////////////////////////////////////////////////
  263. // Function : resize_pool
  264. // Access : Private
  265. // Description : Resizes the particle pool
  266. ////////////////////////////////////////////////////////////////////
  267. #ifdef PSDEBUG
  268. #define PARTICLE_SYSTEM_RESIZE_POOL_SENTRIES
  269. #endif
  270. void ParticleSystem::
  271. resize_pool(int size) {
  272. int i;
  273. int delta = size - _particle_pool_size;
  274. int po_delta = _particle_pool_size - _physics_objects.size();
  275. #ifdef PARTICLE_SYSTEM_RESIZE_POOL_SENTRIES
  276. cout << "resizing particle pool from " << _particle_pool_size
  277. << " to " << size << endl;
  278. #endif
  279. if (_factory.is_null()) {
  280. particlesystem_cat.error() << "ParticleSystem::resize_pool"
  281. << " called with null _factory." << endl;
  282. return;
  283. }
  284. if (_renderer.is_null()) {
  285. particlesystem_cat.error() << "ParticleSystem::resize_pool"
  286. << " called with null _renderer." << endl;
  287. return;
  288. }
  289. _particle_pool_size = size;
  290. // make sure the physics_objects array is OK
  291. if (po_delta) {
  292. if (po_delta > 0) {
  293. for (i = 0; i < po_delta; i++)
  294. {
  295. // int free_index = _physics_objects.size();
  296. BaseParticle *new_particle = _factory->alloc_particle();
  297. if (new_particle) {
  298. _factory->populate_particle(new_particle);
  299. _physics_objects.push_back(new_particle);
  300. } else {
  301. #ifdef PSDEBUG
  302. cout << "Error allocating new particle" << endl;
  303. _particle_pool_size--;
  304. #endif
  305. }
  306. }
  307. } else {
  308. #ifdef PSDEBUG
  309. cout << "physics_object array is too large??" << endl;
  310. _particle_pool_size--;
  311. #endif
  312. po_delta = -po_delta;
  313. for (i = 0; i < po_delta; i++) {
  314. int delete_index = _physics_objects.size()-1;
  315. BaseParticle *bp = (BaseParticle *) _physics_objects[delete_index].p();
  316. if (bp->get_alive()) {
  317. kill_particle(delete_index);
  318. _free_particle_fifo.pop_back();
  319. } else {
  320. pdeque<int>::iterator i;
  321. i = find(_free_particle_fifo.begin(), _free_particle_fifo.end(), delete_index);
  322. if (i != _free_particle_fifo.end()) {
  323. _free_particle_fifo.erase(i);
  324. }
  325. }
  326. _physics_objects.pop_back();
  327. }
  328. }
  329. }
  330. // disregard no change
  331. if (delta == 0)
  332. return;
  333. // update the pool
  334. if (delta > 0) {
  335. // add elements
  336. for (i = 0; i < delta; i++)
  337. {
  338. int free_index = _physics_objects.size();
  339. BaseParticle *new_particle = _factory->alloc_particle();
  340. if (new_particle) {
  341. _factory->populate_particle(new_particle);
  342. _physics_objects.push_back(new_particle);
  343. _free_particle_fifo.push_back(free_index);
  344. } else {
  345. #ifdef PSDEBUG
  346. cout << "Error allocating new particle" << endl;
  347. _particle_pool_size--;
  348. #endif
  349. }
  350. }
  351. } else {
  352. // subtract elements
  353. delta = -delta;
  354. for (i = 0; i < delta; i++) {
  355. int delete_index = _physics_objects.size()-1;
  356. BaseParticle *bp = (BaseParticle *) _physics_objects[delete_index].p();
  357. if (bp->get_alive()) {
  358. #ifdef PSDEBUG
  359. cout << "WAS ALIVE" << endl;
  360. #endif
  361. kill_particle(delete_index);
  362. _free_particle_fifo.pop_back();
  363. } else {
  364. #ifdef PSDEBUG
  365. cout << "WAS NOT ALIVE" << endl;
  366. #endif
  367. pdeque<int>::iterator i;
  368. i = find(_free_particle_fifo.begin(), _free_particle_fifo.end(), delete_index);
  369. if (i != _free_particle_fifo.end()) {
  370. _free_particle_fifo.erase(i);
  371. }
  372. #ifdef PSDEBUG
  373. else {
  374. cout << "particle not found in free FIFO!!!!!!!!" << endl;
  375. }
  376. #endif
  377. }
  378. _physics_objects.pop_back();
  379. }
  380. }
  381. _renderer->resize_pool(_particle_pool_size);
  382. #ifdef PARTICLE_SYSTEM_RESIZE_POOL_SENTRIES
  383. cout << "particle pool resized" << endl;
  384. #endif
  385. }
  386. //////////////////////////////////////////////////////////////////////
  387. // Function : update
  388. // Access : Public
  389. // Description : Updates the particle system. Call once per frame.
  390. //////////////////////////////////////////////////////////////////////
  391. #ifdef PSDEBUG
  392. //#define PARTICLE_SYSTEM_UPDATE_SENTRIES
  393. #endif
  394. void ParticleSystem::
  395. update(float dt) {
  396. int ttl_updates_left = _living_particles;
  397. int current_index = 0, index_counter = 0;
  398. BaseParticle *bp;
  399. float age;
  400. #ifdef PSSANITYCHECK
  401. // check up on things
  402. if (sanity_check()) return;
  403. #endif
  404. #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES
  405. cout << "UPDATE: pool size: " << _particle_pool_size
  406. << ", live particles: " << _living_particles << endl;
  407. #endif
  408. // run through the particle array
  409. while (ttl_updates_left) {
  410. current_index = index_counter;
  411. index_counter++;
  412. #ifdef PSDEBUG
  413. if (current_index >= _particle_pool_size) {
  414. cout << "ERROR: _living_particles is out of sync (too large)" << endl;
  415. cout << "pool size: " << _particle_pool_size
  416. << ", live particles: " << _living_particles
  417. << ", updates left: " << ttl_updates_left << endl;
  418. break;
  419. }
  420. #endif
  421. // get the current particle.
  422. bp = (BaseParticle *) _physics_objects[current_index].p();
  423. #ifdef PSDEBUG
  424. if (!bp) {
  425. cout << "NULL ptr at index " << current_index << endl;
  426. continue;
  427. }
  428. #endif
  429. if (bp->get_alive() == false)
  430. continue;
  431. age = bp->get_age() + dt;
  432. bp->set_age(age);
  433. //cerr<<"bp->get_position().get_z() returning "<<bp->get_position().get_z()<<endl;
  434. if (age >= bp->get_lifespan()) {
  435. kill_particle(current_index);
  436. } else if (get_floor_z() != -HUGE_VAL
  437. && bp->get_position().get_z() <= get_floor_z()) {
  438. // ...the particle is going under the floor.
  439. // Maybe tell the particle to bounce: bp->bounce()?
  440. kill_particle(current_index);
  441. } else {
  442. bp->update();
  443. }
  444. // break out early if we're lucky
  445. ttl_updates_left--;
  446. }
  447. // generate new particles if necessary.
  448. _tics_since_birth += dt;
  449. while (_tics_since_birth >= _birth_rate) {
  450. birth_litter();
  451. _tics_since_birth -= _birth_rate;
  452. }
  453. #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES
  454. cout << "particle update complete" << endl;
  455. #endif
  456. }
  457. #ifdef PSSANITYCHECK
  458. //////////////////////////////////////////////////////////////////////
  459. // Function : sanity_check
  460. // Access : Private
  461. // Description : Checks consistency of live particle count, free
  462. // particle list, etc. returns 0 if everything is normal
  463. //////////////////////////////////////////////////////////////////////
  464. #ifndef NDEBUG
  465. #define PSSCVERBOSE
  466. #endif
  467. class SC_valuenamepair : public ReferenceCount {
  468. public:
  469. int value;
  470. char *name;
  471. SC_valuenamepair(int v, char *s) : value(v), name(s) {}
  472. };
  473. // returns 0 if OK, # of errors if not OK
  474. static int check_free_live_total_particles(pvector< PT(SC_valuenamepair) > live_counts,
  475. pvector< PT(SC_valuenamepair) > dead_counts, pvector< PT(SC_valuenamepair) > total_counts,
  476. int print_all = 0) {
  477. int val = 0;
  478. int l, d, t;
  479. for(l = 0; l < live_counts.size(); l++) {
  480. for(d = 0; d < dead_counts.size(); d++) {
  481. for(t = 0; t < total_counts.size(); t++) {
  482. int live = live_counts[l]->value;
  483. int dead = dead_counts[d]->value;
  484. int total = total_counts[t]->value;
  485. if ((live + dead) != total) {
  486. #ifdef PSSCVERBOSE
  487. cout << "free/live/total count: "
  488. << live_counts[l]->name << " (" << live << ") + "
  489. << dead_counts[d]->name << " (" << dead << ") = "
  490. << live + dead << ", != "
  491. << total_counts[t]->name << " (" << total << ")"
  492. << endl;
  493. #endif
  494. val++;
  495. }
  496. }
  497. }
  498. }
  499. return val;
  500. }
  501. int ParticleSystem::
  502. sanity_check() {
  503. int result = 0;
  504. int i;
  505. BaseParticle *bp;
  506. int pool_size;
  507. ///////////////////////////////////////////////////////////////////
  508. // check pool size
  509. if (_particle_pool_size != _physics_objects.size()) {
  510. #ifdef PSSCVERBOSE
  511. cout << "_particle_pool_size (" << _particle_pool_size
  512. << ") != particle array size (" << _physics_objects.size() << ")" << endl;
  513. #endif
  514. result++;
  515. }
  516. pool_size = min(_particle_pool_size, _physics_objects.size());
  517. ///////////////////////////////////////////////////////////////////
  518. ///////////////////////////////////////////////////////////////////
  519. // find out how many particles are REALLY alive and dead
  520. int real_live_particle_count = 0;
  521. int real_dead_particle_count = 0;
  522. for (i = 0; i < _physics_objects.size(); i++) {
  523. bp = (BaseParticle *) _physics_objects[i].p();
  524. if (true == bp->get_alive()) {
  525. real_live_particle_count++;
  526. } else {
  527. real_dead_particle_count++;
  528. }
  529. }
  530. if (real_live_particle_count != _living_particles) {
  531. #ifdef PSSCVERBOSE
  532. cout << "manually counted live particle count (" << real_live_particle_count
  533. << ") != _living_particles (" << _living_particles << ")" << endl;
  534. #endif
  535. result++;
  536. }
  537. if (real_dead_particle_count != _free_particle_fifo.size()) {
  538. #ifdef PSSCVERBOSE
  539. cout << "manually counted dead particle count (" << real_dead_particle_count
  540. << ") != free particle fifo size (" << _free_particle_fifo.size() << ")" << endl;
  541. #endif
  542. result++;
  543. }
  544. ///////////////////////////////////////////////////////////////////
  545. ///////////////////////////////////////////////////////////////////
  546. // check the free particle pool
  547. for (i = 0; i < _free_particle_fifo.size(); i++) {
  548. int index = _free_particle_fifo[i];
  549. // check that we're in bounds
  550. if (index >= pool_size) {
  551. #ifdef PSSCVERBOSE
  552. cout << "index from free particle fifo (" << index
  553. << ") is too large; pool size is " << pool_size << endl;
  554. #endif
  555. result++;
  556. continue;
  557. }
  558. // check that the particle is indeed dead
  559. bp = (BaseParticle *) _physics_objects[index].p();
  560. if (true == bp->get_alive()) {
  561. #ifdef PSSCVERBOSE
  562. cout << "particle " << index << " in free fifo is not dead" << endl;
  563. #endif
  564. result++;
  565. }
  566. }
  567. ///////////////////////////////////////////////////////////////////
  568. ///////////////////////////////////////////////////////////////////
  569. // check the numbers of free particles, live particles, and total particles
  570. pvector< PT(SC_valuenamepair) > live_counts;
  571. pvector< PT(SC_valuenamepair) > dead_counts;
  572. pvector< PT(SC_valuenamepair) > total_counts;
  573. live_counts.push_back(new SC_valuenamepair(real_live_particle_count, "real_live_particle_count"));
  574. dead_counts.push_back(new SC_valuenamepair(real_dead_particle_count, "real_dead_particle_count"));
  575. dead_counts.push_back(new SC_valuenamepair(_free_particle_fifo.size(), "free particle fifo size"));
  576. total_counts.push_back(new SC_valuenamepair(_particle_pool_size, "_particle_pool_size"));
  577. total_counts.push_back(new SC_valuenamepair(_physics_objects.size(), "actual particle pool size"));
  578. result += check_free_live_total_particles(live_counts, dead_counts, total_counts);
  579. ///////////////////////////////////////////////////////////////////
  580. return result;
  581. }
  582. #endif
  583. ////////////////////////////////////////////////////////////////////
  584. // Function : output
  585. // Access : Public
  586. // Description : Write a string representation of this instance to
  587. // <out>.
  588. ////////////////////////////////////////////////////////////////////
  589. void ParticleSystem::
  590. output(ostream &out) const {
  591. #ifndef NDEBUG //[
  592. out<<"ParticleSystem";
  593. #endif //] NDEBUG
  594. }
  595. ////////////////////////////////////////////////////////////////////
  596. // Function : write_free_particle_fifo
  597. // Access : Public
  598. // Description : Write a string representation of this instance to
  599. // <out>.
  600. ////////////////////////////////////////////////////////////////////
  601. void ParticleSystem::
  602. write_free_particle_fifo(ostream &out, int indent) const {
  603. #ifndef NDEBUG //[
  604. out.width(indent);
  605. out<<""<<"_free_particle_fifo ("<<_free_particle_fifo.size()<<" forces)\n";
  606. for (pdeque< int >::const_iterator i=_free_particle_fifo.begin();
  607. i != _free_particle_fifo.end();
  608. ++i) {
  609. out.width(indent+2); out<<""; out<<(*i)<<"\n";
  610. }
  611. #endif //] NDEBUG
  612. }
  613. ////////////////////////////////////////////////////////////////////
  614. // Function : write_spawn_templates
  615. // Access : Public
  616. // Description : Write a string representation of this instance to
  617. // <out>.
  618. ////////////////////////////////////////////////////////////////////
  619. void ParticleSystem::
  620. write_spawn_templates(ostream &out, int indent) const {
  621. #ifndef NDEBUG //[
  622. out.width(indent);
  623. out<<""<<"_spawn_templates ("<<_spawn_templates.size()<<" templates)\n";
  624. for (pvector< PT(ParticleSystem) >::const_iterator i=_spawn_templates.begin();
  625. i != _spawn_templates.end();
  626. ++i) {
  627. (*i)->write(out, indent+2);
  628. }
  629. #endif //] NDEBUG
  630. }
  631. ////////////////////////////////////////////////////////////////////
  632. // Function : write
  633. // Access : Public
  634. // Description : Write a string representation of this instance to
  635. // <out>.
  636. ////////////////////////////////////////////////////////////////////
  637. void ParticleSystem::
  638. write(ostream &out, int indent) const {
  639. #ifndef NDEBUG //[
  640. out.width(indent); out<<""; out<<"ParticleSystem:\n";
  641. out.width(indent+2); out<<""; out<<"_particle_pool_size "<<_particle_pool_size<<"\n";
  642. out.width(indent+2); out<<""; out<<"_living_particles "<<_living_particles<<"\n";
  643. out.width(indent+2); out<<""; out<<"_tics_since_birth "<<_tics_since_birth<<"\n";
  644. out.width(indent+2); out<<""; out<<"_litter_size "<<_litter_size<<"\n";
  645. out.width(indent+2); out<<""; out<<"_litter_spread "<<_litter_spread<<"\n";
  646. out.width(indent+2); out<<""; out<<"_system_age "<<_system_age<<"\n";
  647. out.width(indent+2); out<<""; out<<"_system_lifespan "<<_system_lifespan<<"\n";
  648. out.width(indent+2); out<<""; out<<"_factory "<<_factory<<"\n";
  649. out.width(indent+2); out<<""; out<<"_emitter "<<_emitter<<"\n";
  650. out.width(indent+2); out<<""; out<<"_renderer "<<_renderer<<"\n";
  651. out.width(indent+2); out<<""; out<<"_manager "<<_manager<<"\n";
  652. out.width(indent+2); out<<""; out<<"_template_system_flag "<<_template_system_flag<<"\n";
  653. out.width(indent+2); out<<""; out<<"_render_parent "<<_render_parent<<"\n";
  654. out.width(indent+2); out<<""; out<<"_render_node "<<_render_node<<"\n";
  655. out.width(indent+2); out<<""; out<<"_active_system_flag "<<_active_system_flag<<"\n";
  656. out.width(indent+2); out<<""; out<<"_local_velocity_flag "<<_local_velocity_flag<<"\n";
  657. out.width(indent+2); out<<""; out<<"_system_grows_older_flag "<<_system_grows_older_flag<<"\n";
  658. out.width(indent+2); out<<""; out<<"_spawn_on_death_flag "<<_spawn_on_death_flag<<"\n";
  659. out.width(indent+2); out<<""; out<<"_spawn_render_node "<<_spawn_render_node<<"\n";
  660. out.width(indent+2); out<<""; out<<"_i_was_spawned_flag "<<_i_was_spawned_flag<<"\n";
  661. write_free_particle_fifo(out, indent+2);
  662. write_spawn_templates(out, indent+2);
  663. Physical::write(out, indent+2);
  664. #endif //] NDEBUG
  665. }