Browse Source

*** empty log message ***

Darren Ranalli 25 years ago
parent
commit
6048676bd5
2 changed files with 74 additions and 31 deletions
  1. 25 28
      panda/src/particlesystem/particleSystem.cxx
  2. 49 3
      panda/src/testbed/test_particles.cxx

+ 25 - 28
panda/src/particlesystem/particleSystem.cxx

@@ -54,8 +54,12 @@ ParticleSystem(int pool_size) :
   _render_parent = new NamedNode("ParticleSystem default render parent");
   _render_parent = new NamedNode("ParticleSystem default render parent");
 
 
   set_emitter(new SphereSurfaceEmitter);
   set_emitter(new SphereSurfaceEmitter);
+
   set_renderer(new PointParticleRenderer);
   set_renderer(new PointParticleRenderer);
-  set_factory(new PointParticleFactory);
+
+  //set_factory(new PointParticleFactory);
+  _factory = new PointParticleFactory;
+  clear_physics_objects();
 
 
   set_pool_size(pool_size);
   set_pool_size(pool_size);
 }
 }
@@ -401,41 +405,33 @@ resize_pool(int size) {
   } else {
   } else {
     // subtract elements
     // subtract elements
     delta = -delta;
     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
 #ifdef PSDEBUG
-          cout << "WAS ALIVE" << endl;
+        cout << "WAS ALIVE" << endl;
 #endif
 #endif
-          kill_particle(delete_index);
-          _free_particle_fifo.pop_back();
-        } else {
+        kill_particle(delete_index);
+        _free_particle_fifo.pop_back();
+      } else {
 #ifdef PSDEBUG
 #ifdef PSDEBUG
-          cout << "WAS NOT ALIVE" << endl;
+        cout << "WAS NOT ALIVE" << endl;
 #endif
 #endif
-          deque<int>::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);
-          }
+        deque<int>::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
 #ifdef PSDEBUG
-          else {
-            cout << "particle not found in free FIFO!!!!!!!!" << endl;
-          }
-#endif
+        else {
+          cout << "particle not found in free FIFO!!!!!!!!" << endl;
         }
         }
-
-        _physics_objects.pop_back();
+#endif
       }
       }
+
+      _physics_objects.pop_back();
     }
     }
   }
   }
 
 
@@ -523,6 +519,7 @@ update(float dt) {
 #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES
 #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES
   cout << "particle update complete" << endl;
   cout << "particle update complete" << endl;
 #endif
 #endif
+
 }
 }
 
 
 #ifdef PSSANITYCHECK
 #ifdef PSSANITYCHECK

+ 49 - 3
panda/src/testbed/test_particles.cxx

@@ -209,6 +209,9 @@ ParticleSystemManager ps_manager;
 
 
 PT(ParticleSystem) particle_system = new ParticleSystem(PARTICLE_SYSTEM_POOL_SIZE);
 PT(ParticleSystem) particle_system = new ParticleSystem(PARTICLE_SYSTEM_POOL_SIZE);
 
 
+static int particles_added = 0;
+
+/*
 #if defined POINT_PARTICLES
 #if defined POINT_PARTICLES
   PT(PointParticleFactory) pf = new PointParticleFactory;
   PT(PointParticleFactory) pf = new PointParticleFactory;
 #elif defined ZSPIN_PARTICLES
 #elif defined ZSPIN_PARTICLES
@@ -216,6 +219,14 @@ PT(ParticleSystem) particle_system = new ParticleSystem(PARTICLE_SYSTEM_POOL_SIZ
 #elif defined ORIENTED_PARTICLES
 #elif defined ORIENTED_PARTICLES
   PT(OrientedParticleFactory) pf = new OrientedParticleFactory;
   PT(OrientedParticleFactory) pf = new OrientedParticleFactory;
 #endif
 #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
 #if defined GEOM_PARTICLE_RENDERER
   PT(GeomParticleRenderer) pr = new GeomParticleRenderer;
   PT(GeomParticleRenderer) pr = new GeomParticleRenderer;
@@ -271,11 +282,10 @@ event_csn_update(CPT_Event) {
 
 
 static void
 static void
 event_add_particles(CPT_Event) {
 event_add_particles(CPT_Event) {
-  static initialized = 0;
 
 
   // guard against additional "P" presses (bad things happen)
   // guard against additional "P" presses (bad things happen)
-  if(initialized) return;
-  initialized = 1;
+  if(particles_added) return;
+  particles_added = 1;
 
 
   // renderer setup
   // renderer setup
   #ifdef PARTICLE_RENDERER_ALPHA_MODE
   #ifdef PARTICLE_RENDERER_ALPHA_MODE
@@ -364,6 +374,7 @@ event_add_particles(CPT_Event) {
   #endif
   #endif
 
 
   // factory setup
   // factory setup
+
   #ifdef PARTICLE_FACTORY_LIFESPAN_BASE
   #ifdef PARTICLE_FACTORY_LIFESPAN_BASE
     pf->set_lifespan_base(PARTICLE_FACTORY_LIFESPAN_BASE);
     pf->set_lifespan_base(PARTICLE_FACTORY_LIFESPAN_BASE);
   #endif
   #endif
@@ -560,17 +571,52 @@ event_more_particles(CPT_Event) {
     0,
     0,
   };
   };
 
 
+  if(!particles_added) return;
+
   if (0 == sizes[index]) index = 0;
   if (0 == sizes[index]) index = 0;
   set_pool_size(sizes[index]);
   set_pool_size(sizes[index]);
   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&) {
 void demo_keys(EventHandler&) {
   new RenderRelation( lights, dlight );
   new RenderRelation( lights, dlight );
   have_dlight = true;
   have_dlight = true;
 
 
   event_handler.add_hook("p", event_add_particles);
   event_handler.add_hook("p", event_add_particles);
   event_handler.add_hook("m", event_more_particles);
   event_handler.add_hook("m", event_more_particles);
+  event_handler.add_hook(",", event_switch_particle_factory_type);
 }
 }
 
 
 int main(int argc, char *argv[]) {
 int main(int argc, char *argv[]) {