diff --git a/panda/src/particlesystem/particleSystem.cxx b/panda/src/particlesystem/particleSystem.cxx index 38f0b72d7e..6cdbcc27b4 100644 --- a/panda/src/particlesystem/particleSystem.cxx +++ b/panda/src/particlesystem/particleSystem.cxx @@ -54,8 +54,12 @@ ParticleSystem(int pool_size) : _render_parent = new NamedNode("ParticleSystem default render parent"); set_emitter(new SphereSurfaceEmitter); + set_renderer(new PointParticleRenderer); - set_factory(new PointParticleFactory); + + //set_factory(new PointParticleFactory); + _factory = new PointParticleFactory; + clear_physics_objects(); set_pool_size(pool_size); } @@ -401,41 +405,33 @@ resize_pool(int size) { } else { // subtract elements delta = -delta; - if (delta >= _physics_objects.size()) { -#ifdef PSDEBUG - cout << "Weird... do we have a negative pool size??" << endl; -#endif - _physics_objects.erase(_physics_objects.begin(), _physics_objects.end()); - _free_particle_fifo.clear(); - } else { - for (i = 0; i < delta; i++) { - int delete_index = _physics_objects.size()-1; - BaseParticle *bp = (BaseParticle *) _physics_objects[delete_index].p(); + for (i = 0; i < delta; i++) { + int delete_index = _physics_objects.size()-1; + BaseParticle *bp = (BaseParticle *) _physics_objects[delete_index].p(); - if (bp->get_alive()) { + if (bp->get_alive()) { #ifdef PSDEBUG - cout << "WAS ALIVE" << endl; + cout << "WAS ALIVE" << endl; #endif - kill_particle(delete_index); - _free_particle_fifo.pop_back(); - } else { + kill_particle(delete_index); + _free_particle_fifo.pop_back(); + } else { #ifdef PSDEBUG - cout << "WAS NOT ALIVE" << endl; -#endif - deque::iterator i; - i = find(_free_particle_fifo.begin(), _free_particle_fifo.end(), delete_index); - if (i != _free_particle_fifo.end()) { - _free_particle_fifo.erase(i); - } -#ifdef PSDEBUG - else { - cout << "particle not found in free FIFO!!!!!!!!" << endl; - } + cout << "WAS NOT ALIVE" << endl; #endif + deque::iterator i; + i = find(_free_particle_fifo.begin(), _free_particle_fifo.end(), delete_index); + if (i != _free_particle_fifo.end()) { + _free_particle_fifo.erase(i); } - - _physics_objects.pop_back(); +#ifdef PSDEBUG + else { + cout << "particle not found in free FIFO!!!!!!!!" << endl; + } +#endif } + + _physics_objects.pop_back(); } } @@ -523,6 +519,7 @@ update(float dt) { #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES cout << "particle update complete" << endl; #endif + } #ifdef PSSANITYCHECK diff --git a/panda/src/testbed/test_particles.cxx b/panda/src/testbed/test_particles.cxx index 111af1c38b..d9aa917d26 100644 --- a/panda/src/testbed/test_particles.cxx +++ b/panda/src/testbed/test_particles.cxx @@ -209,6 +209,9 @@ ParticleSystemManager ps_manager; PT(ParticleSystem) particle_system = new ParticleSystem(PARTICLE_SYSTEM_POOL_SIZE); +static int particles_added = 0; + +/* #if defined POINT_PARTICLES PT(PointParticleFactory) pf = new PointParticleFactory; #elif defined ZSPIN_PARTICLES @@ -216,6 +219,14 @@ PT(ParticleSystem) particle_system = new ParticleSystem(PARTICLE_SYSTEM_POOL_SIZ #elif defined ORIENTED_PARTICLES PT(OrientedParticleFactory) pf = new OrientedParticleFactory; #endif +*/ +#if defined POINT_PARTICLES + PT(BaseParticleFactory) pf = new PointParticleFactory; +#elif defined ZSPIN_PARTICLES + PT(BaseParticleFactory) pf = new ZSpinParticleFactory; +#elif defined ORIENTED_PARTICLES + PT(BaseParticleFactory) pf = new OrientedParticleFactory; +#endif #if defined GEOM_PARTICLE_RENDERER PT(GeomParticleRenderer) pr = new GeomParticleRenderer; @@ -271,11 +282,10 @@ event_csn_update(CPT_Event) { static void event_add_particles(CPT_Event) { - static initialized = 0; // guard against additional "P" presses (bad things happen) - if(initialized) return; - initialized = 1; + if(particles_added) return; + particles_added = 1; // renderer setup #ifdef PARTICLE_RENDERER_ALPHA_MODE @@ -364,6 +374,7 @@ event_add_particles(CPT_Event) { #endif // factory setup + #ifdef PARTICLE_FACTORY_LIFESPAN_BASE pf->set_lifespan_base(PARTICLE_FACTORY_LIFESPAN_BASE); #endif @@ -560,17 +571,52 @@ event_more_particles(CPT_Event) { 0, }; + if(!particles_added) return; + if (0 == sizes[index]) index = 0; set_pool_size(sizes[index]); index++; } +static void +event_switch_particle_factory_type(CPT_Event) { + static int index = 0; + + if(!particles_added) return; + + cout << "Switching to a"; + + switch (index) { + case 0: + cout << " point"; + pf = new PointParticleFactory; + particle_system->set_factory(pf); + break; + case 1: + cout << " z-spin"; + pf = new ZSpinParticleFactory; + particle_system->set_factory(pf); + break; + case 2: + cout << "n oriented"; + pf = new OrientedParticleFactory; + particle_system->set_factory(pf); + break; + } + + cout << " particle factory" << endl; + + index++; + if (index > 2) index = 0; +} + void demo_keys(EventHandler&) { new RenderRelation( lights, dlight ); have_dlight = true; event_handler.add_hook("p", event_add_particles); event_handler.add_hook("m", event_more_particles); + event_handler.add_hook(",", event_switch_particle_factory_type); } int main(int argc, char *argv[]) {