00001 // Filename: particleSystemManager.cxx 00002 // Created by: charles (28Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "particleSystemManager.h" 00020 #include "particleSystem.h" 00021 00022 #include <pandabase.h> 00023 #include <physicsManager.h> 00024 #include <clockObject.h> 00025 00026 #include <algorithm> 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function : ParticleSystemManager 00030 // Access : public 00031 // Description : default constructor 00032 //////////////////////////////////////////////////////////////////// 00033 ParticleSystemManager:: 00034 ParticleSystemManager(int every_nth_frame) : 00035 _nth_frame(every_nth_frame), _cur_frame(0) { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function : remove_particlesystem 00040 // Access : public 00041 // Description : removes a ps from the maintenance list 00042 //////////////////////////////////////////////////////////////////// 00043 void ParticleSystemManager:: 00044 remove_particlesystem(ParticleSystem *ps) { 00045 plist< PT(ParticleSystem) >::iterator found; 00046 00047 PT(ParticleSystem) ptps = ps; 00048 found = find(_ps_list.begin(), _ps_list.end(), ptps); 00049 00050 if (found == _ps_list.end()) 00051 return; 00052 00053 _ps_list.erase(found); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function : do_particles 00058 // Access : public 00059 // Description : does an update and render for each ps in the list. 00060 // this is probably the one you want to use. Rendering 00061 // is the expensive operation, and particles REALLY 00062 // should at least be updated every frame, so nth_frame 00063 // stepping applies only to rendering. 00064 //////////////////////////////////////////////////////////////////// 00065 void ParticleSystemManager:: 00066 do_particles(float dt) { 00067 // cout << "ParticlesystemManager::doparticles entering." << endl; 00068 00069 plist< PT(ParticleSystem) >::iterator cur; 00070 00071 bool render_due = false; 00072 00073 _cur_frame++; 00074 00075 if (_cur_frame >= _nth_frame) { 00076 _cur_frame = 0; 00077 render_due = true; 00078 } 00079 00080 cur = _ps_list.begin(); 00081 00082 // cout << "PSM::do_particles on a vector of size " << _ps_list.size() << endl; 00083 // int cs = 0; 00084 00085 while (cur != _ps_list.end()) { 00086 ParticleSystem *cur_ps = *cur; 00087 00088 // update this system 00089 if (cur_ps->get_active_system_flag() == true) { 00090 // cout << " system " << cs++ << endl; 00091 // cout << " count is: " << cur_ps->get_render_parent()->get_ref_count() << endl; 00092 cur_ps->update(dt); 00093 00094 // handle age 00095 if (cur_ps->get_system_grows_older_flag() == true) { 00096 float age = cur_ps->get_system_age() + dt; 00097 cur_ps->set_system_age(age); 00098 00099 // handle death 00100 if (age >= cur_ps->get_system_lifespan()) { 00101 plist< PT(ParticleSystem) >::iterator kill = cur; 00102 cur++; 00103 00104 _ps_list.erase(kill); 00105 render_due = false; 00106 } 00107 } 00108 00109 // handle render 00110 if (render_due) { 00111 cur_ps->render(); 00112 } 00113 } 00114 00115 cur++; 00116 } 00117 // cout << "PSM::do_particles finished." << endl; 00118 // cout << "ParticleSystemManager::doparticles exiting." << endl; 00119 }