particleSystem.cxx 25 KB

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