Browse Source

added pstat calipers to sprite particles

Asad M. Zaman 19 years ago
parent
commit
49307714d1

+ 5 - 0
panda/src/particlesystem/particleSystem.cxx

@@ -33,9 +33,12 @@
 #include "pointParticleRenderer.h"
 #include "pointParticleRenderer.h"
 #include "pointParticleFactory.h"
 #include "pointParticleFactory.h"
 #include "sphereSurfaceEmitter.h"
 #include "sphereSurfaceEmitter.h"
+#include "pStatTimer.h"
 
 
 TypeHandle ParticleSystem::_type_handle;
 TypeHandle ParticleSystem::_type_handle;
 
 
+PStatCollector ParticleSystem::_update_collector("App:Particles:Update");
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //    Function : ParticleSystem
 //    Function : ParticleSystem
 //      Access : Public
 //      Access : Public
@@ -467,6 +470,8 @@ resize_pool(int size) {
 #endif
 #endif
 void ParticleSystem::
 void ParticleSystem::
 update(float dt) {
 update(float dt) {
+  PStatTimer t1(_update_collector);
+
   int ttl_updates_left = _living_particles;
   int ttl_updates_left = _living_particles;
   int current_index = 0, index_counter = 0;
   int current_index = 0, index_counter = 0;
   BaseParticle *bp;
   BaseParticle *bp;

+ 3 - 2
panda/src/particlesystem/particleSystem.h

@@ -30,9 +30,8 @@
 #include "physical.h"
 #include "physical.h"
 #include "pandaNode.h"
 #include "pandaNode.h"
 #include "referenceCount.h"
 #include "referenceCount.h"
-
 #include "pdeque.h"
 #include "pdeque.h"
-
+#include "pStatTimer.h"
 #include "baseParticle.h"
 #include "baseParticle.h"
 #include "baseParticleRenderer.h"
 #include "baseParticleRenderer.h"
 #include "baseParticleEmitter.h"
 #include "baseParticleEmitter.h"
@@ -186,6 +185,8 @@ private:
   static TypeHandle _type_handle;
   static TypeHandle _type_handle;
 
 
   friend class ParticleSystemManager; // particleSystemManager.h
   friend class ParticleSystemManager; // particleSystemManager.h
+
+  static PStatCollector _update_collector;
 };
 };
 
 
 #include "particleSystem.I"
 #include "particleSystem.I"

+ 4 - 0
panda/src/particlesystem/particleSystemManager.cxx

@@ -22,9 +22,12 @@
 #include "pandabase.h"
 #include "pandabase.h"
 #include "physicsManager.h"
 #include "physicsManager.h"
 #include "clockObject.h"
 #include "clockObject.h"
+#include "pStatTimer.h"
 
 
 #include <algorithm>
 #include <algorithm>
 
 
+PStatCollector ParticleSystemManager::_do_particles_collector("App:Particles:Do Particles");
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //    Function : ParticleSystemManager
 //    Function : ParticleSystemManager
 //      Access : public
 //      Access : public
@@ -74,6 +77,7 @@ remove_particlesystem(ParticleSystem *ps) {
 void ParticleSystemManager::
 void ParticleSystemManager::
 do_particles(float dt) {
 do_particles(float dt) {
   //  cout << "ParticlesystemManager::doparticles entering." << endl;
   //  cout << "ParticlesystemManager::doparticles entering." << endl;
+  PStatTimer t1(_do_particles_collector);
 
 
   plist< PT(ParticleSystem) >::iterator cur;
   plist< PT(ParticleSystem) >::iterator cur;
 
 

+ 3 - 1
panda/src/particlesystem/particleSystemManager.h

@@ -21,8 +21,8 @@
 
 
 #include "pandabase.h"
 #include "pandabase.h"
 #include "plist.h"
 #include "plist.h"
-
 #include "particleSystem.h"
 #include "particleSystem.h"
+#include "pStatCollector.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : ParticleSystemManager
 //       Class : ParticleSystemManager
@@ -55,6 +55,8 @@ private:
 
 
   int _nth_frame;
   int _nth_frame;
   int _cur_frame;
   int _cur_frame;
+
+  static PStatCollector _do_particles_collector;
 };
 };
 
 
 #include "particleSystemManager.I"
 #include "particleSystemManager.I"

+ 101 - 94
panda/src/particlesystem/spriteParticleRenderer.cxx

@@ -33,6 +33,10 @@
 #include "nodePathCollection.h"
 #include "nodePathCollection.h"
 #include "indent.h"
 #include "indent.h"
 #include "config_particlesystem.h"
 #include "config_particlesystem.h"
+#include "pStatTimer.h"
+
+PStatCollector SpriteParticleRenderer::_sprite_particle_render("App:Particles:Sprite:Render");
+PStatCollector SpriteParticleRenderer::_sprite_particle_process_vertices("App:Particles:Sprite:Render:Process Verts");
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //    Function : SpriteParticleRenderer::SpriteParticleRenderer
 //    Function : SpriteParticleRenderer::SpriteParticleRenderer
@@ -556,7 +560,8 @@ kill_particle(int) {
 // Description : big child render.  populates the geom node.
 // Description : big child render.  populates the geom node.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void SpriteParticleRenderer::
 void SpriteParticleRenderer::
-render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
+render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { 
+  PStatTimer t1(_sprite_particle_process_vertices);
   // There is no texture data available, exit.
   // There is no texture data available, exit.
   if (_anims.empty()) {
   if (_anims.empty()) {
     return;
     return;
@@ -610,120 +615,122 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
   _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
   _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
 
 
   // run through every filled slot
   // run through every filled slot
-  for (i = 0; i < (int)po_vector.size(); i++) {
-    cur_particle = (BaseParticle *) po_vector[i].p();
+  {
+    PStatTimer t2(_sprite_particle_process_vertices);
+    for (i = 0; i < (int)po_vector.size(); i++) {
+      cur_particle = (BaseParticle *) po_vector[i].p();
 
 
-    if (!cur_particle->get_alive()) {
-      continue;
-    }
+      if (!cur_particle->get_alive()) {
+        continue;
+      }
 
 
-    LPoint3f position = cur_particle->get_position();
+      LPoint3f position = cur_particle->get_position();
 
 
-    // x aabb adjust
-    if (position[0] > _aabb_max[0])
-      _aabb_max[0] = position[0];
-    else if (position[0] < _aabb_min[0])
-      _aabb_min[0] = position[0];
+      // x aabb adjust
+      if (position[0] > _aabb_max[0])
+        _aabb_max[0] = position[0];
+      else if (position[0] < _aabb_min[0])
+        _aabb_min[0] = position[0];
 
 
-    // y aabb adjust
-    if (position[1] > _aabb_max[1])
-      _aabb_max[1] = position[1];
-    else if (position[1] < _aabb_min[1])
-      _aabb_min[1] = position[1];
+      // y aabb adjust
+      if (position[1] > _aabb_max[1])
+        _aabb_max[1] = position[1];
+      else if (position[1] < _aabb_min[1])
+        _aabb_min[1] = position[1];
 
 
-    // z aabb adjust
-    if (position[2] > _aabb_max[2])
-      _aabb_max[2] = position[2];
-    else if (position[2] < _aabb_min[2])
-      _aabb_min[2] = position[2];
+      // z aabb adjust
+      if (position[2] > _aabb_max[2])
+        _aabb_max[2] = position[2];
+      else if (position[2] < _aabb_min[2])
+        _aabb_min[2] = position[2];
 
 
 
 
-    float t = cur_particle->get_parameterized_age();
-    int anim_index = cur_particle->get_index();
+      float t = cur_particle->get_parameterized_age();
+      int anim_index = cur_particle->get_index();
 
 
-    // If an animation has been removed, we need to reassign
-    // those particles assigned to the removed animation.
-    if(_animation_removed && (anim_index >= anim_count)) {
-      anim_index = int(NORMALIZED_RAND()*anim_count);
-      anim_index = anim_index<anim_count?anim_index:anim_index-1;
-      cur_particle->set_index(anim_index);
-    }
+      // If an animation has been removed, we need to reassign
+      // those particles assigned to the removed animation.
+      if(_animation_removed && (anim_index >= anim_count)) {
+        anim_index = int(NORMALIZED_RAND()*anim_count);
+        anim_index = anim_index<anim_count?anim_index:anim_index-1;
+        cur_particle->set_index(anim_index);
+      }
 
 
-    // Find the frame
-    if (_animate_frames) {
-      if (_animate_frames_rate == 0.0f) {
-        frame = (int)(t*_anim_size[anim_index]);
+      // Find the frame
+      if (_animate_frames) {
+        if (_animate_frames_rate == 0.0f) {
+          frame = (int)(t*_anim_size[anim_index]);
+        } else {
+          frame = (int)fmod(cur_particle->get_age()*_animate_frames_rate+1,_anim_size[anim_index]);
+        }
       } else {
       } else {
-        frame = (int)fmod(cur_particle->get_age()*_animate_frames_rate+1,_anim_size[anim_index]);
+        frame = _animate_frames_index;
       }
       }
-    } else {
-      frame = _animate_frames_index;
-    }
 
 
-    // Quick check make sure our math above didn't result in an invalid frame.
-    frame = (frame < _anim_size[anim_index]) ? frame : (_anim_size[anim_index]-1);
-    ++_ttl_count[anim_index][frame];
-
-    // Calculate the color
-    // This is where we'll want to give the renderer the new color
-    Colorf c = _color_interpolation_manager->generateColor(t);
-
-    int alphamode=get_alpha_mode();
-    if (alphamode != PR_ALPHA_NONE) {
-      if (alphamode == PR_ALPHA_OUT)
-        c[3] *= (1.0f - t) * get_user_alpha();
-      else if (alphamode == PR_ALPHA_IN)
-        c[3] *= t * get_user_alpha();
-      else if (alphamode == PR_ALPHA_IN_OUT) {
-        c[3] *= 2.0f * min(t, 1.0f - t) * get_user_alpha();
-      }
-      else {
-        assert(alphamode == PR_ALPHA_USER);
-        c[3] *= get_user_alpha();
+      // Quick check make sure our math above didn't result in an invalid frame.
+      frame = (frame < _anim_size[anim_index]) ? frame : (_anim_size[anim_index]-1);
+      ++_ttl_count[anim_index][frame];
+
+      // Calculate the color
+      // This is where we'll want to give the renderer the new color
+      Colorf c = _color_interpolation_manager->generateColor(t);
+
+      int alphamode=get_alpha_mode();
+      if (alphamode != PR_ALPHA_NONE) {
+        if (alphamode == PR_ALPHA_OUT)
+          c[3] *= (1.0f - t) * get_user_alpha();
+        else if (alphamode == PR_ALPHA_IN)
+          c[3] *= t * get_user_alpha();
+        else if (alphamode == PR_ALPHA_IN_OUT) {
+          c[3] *= 2.0f * min(t, 1.0f - t) * get_user_alpha();
+        }
+        else {
+          assert(alphamode == PR_ALPHA_USER);
+          c[3] *= get_user_alpha();
+        }
       }
       }
-    }
-    
-    // Send the data on its way...
-    _sprite_writer[anim_index][frame].vertex.add_data3f(position);
-    _sprite_writer[anim_index][frame].color.add_data4f(c);
+          
+      // Send the data on its way...
+      _sprite_writer[anim_index][frame].vertex.add_data3f(position);
+      _sprite_writer[anim_index][frame].color.add_data4f(c);
     
     
-    float current_x_scale = _initial_x_scale;
-    float current_y_scale = _initial_y_scale;
+      float current_x_scale = _initial_x_scale;
+      float current_y_scale = _initial_y_scale;
     
     
-    if (_animate_x_ratio || _animate_y_ratio) {
-      if (_blend_method == PP_BLEND_CUBIC) {
-        t = CUBIC_T(t);
-      }
+      if (_animate_x_ratio || _animate_y_ratio) {
+        if (_blend_method == PP_BLEND_CUBIC) {
+          t = CUBIC_T(t);
+        }
       
       
-      if (_animate_x_ratio) {
-        current_x_scale = (_initial_x_scale +
-                           (t * (_final_x_scale - _initial_x_scale)));
+        if (_animate_x_ratio) {
+          current_x_scale = (_initial_x_scale +
+                             (t * (_final_x_scale - _initial_x_scale)));
+        }
+        if (_animate_y_ratio) {
+          current_y_scale = (_initial_y_scale +
+                             (t * (_final_y_scale - _initial_y_scale)));
+        }
       }
       }
-      if (_animate_y_ratio) {
-        current_y_scale = (_initial_y_scale +
-                           (t * (_final_y_scale - _initial_y_scale)));
+
+      if (_sprite_writer[anim_index][frame].size.has_column()) {
+        _sprite_writer[anim_index][frame].size.add_data1f(current_y_scale * _height);
+      }
+      if (_sprite_writer[anim_index][frame].aspect_ratio.has_column()) {
+        _sprite_writer[anim_index][frame].aspect_ratio.add_data1f(_aspect_ratio * current_x_scale / current_y_scale);
+      }
+      if (_animate_theta) {
+        _sprite_writer[anim_index][frame].rotate.add_data1f(cur_particle->get_theta());
+      } else if (_sprite_writer[anim_index][frame].rotate.has_column()) {
+        _sprite_writer[anim_index][frame].rotate.add_data1f(_theta);
       }
       }
-    }
-    
-    if (_sprite_writer[anim_index][frame].size.has_column()) {
-      _sprite_writer[anim_index][frame].size.add_data1f(current_y_scale * _height);
-    }
-    if (_sprite_writer[anim_index][frame].aspect_ratio.has_column()) {
-      _sprite_writer[anim_index][frame].aspect_ratio.add_data1f(_aspect_ratio * current_x_scale / current_y_scale);
-    }
-    if (_animate_theta) {
-      _sprite_writer[anim_index][frame].rotate.add_data1f(cur_particle->get_theta());
-    } else if (_sprite_writer[anim_index][frame].rotate.has_column()) {
-      _sprite_writer[anim_index][frame].rotate.add_data1f(_theta);
-    }
 
 
-    // maybe jump out early?
-    remaining_particles--;
-    if (remaining_particles == 0) {
-      break;
+      // maybe jump out early?
+      remaining_particles--;
+      if (remaining_particles == 0) {
+        break;
+      }
     }
     }
   }
   }
-
   int n = 0;
   int n = 0;
   GeomNode *render_node = get_render_node();
   GeomNode *render_node = get_render_node();
   
   

+ 4 - 0
panda/src/particlesystem/spriteParticleRenderer.h

@@ -33,6 +33,7 @@
 #include "textureCollection.h"
 #include "textureCollection.h"
 #include "nodePathCollection.h"
 #include "nodePathCollection.h"
 #include "vector_int.h"
 #include "vector_int.h"
+#include "pStatCollector.h"
 
 
 class NodePath;
 class NodePath;
 
 
@@ -267,6 +268,9 @@ private:
   vector_int _anim_size;   // Holds the number of frames in each animation.
   vector_int _anim_size;   // Holds the number of frames in each animation.
   pvector<int*> _ttl_count;  // _ttl_count[i][j] holds the number of particles attached to animation 'i' at frame 'j'.
   pvector<int*> _ttl_count;  // _ttl_count[i][j] holds the number of particles attached to animation 'i' at frame 'j'.
   vector_int _birth_list;  // Holds the list of particles that need a new random animation to start on.
   vector_int _birth_list;  // Holds the list of particles that need a new random animation to start on.
+
+  static PStatCollector _sprite_particle_render;
+  static PStatCollector _sprite_particle_process_vertices;
 };
 };
 
 
 #include "spriteParticleRenderer.I"
 #include "spriteParticleRenderer.I"