Removing per-particle calls to usecTimestampNow() which can add up when simulating a lot of particles.

This commit is contained in:
Andrew Meadows 2014-01-20 13:27:19 -08:00
parent 61e1b25e70
commit 79e4b6d691
3 changed files with 5 additions and 7 deletions

View file

@ -475,15 +475,13 @@ void Particle::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssiz
}
void Particle::update() {
uint64_t now = usecTimestampNow();
float elapsed = static_cast<float>(now - _lastUpdated);
void Particle::update(const uint64_t& now) {
float timeElapsed = (float)(now - _lastUpdated) / (float)(USECS_PER_SECOND);
_lastUpdated = now;
float timeElapsed = elapsed / static_cast<float>(USECS_PER_SECOND);
// calculate our default shouldDie state... then allow script to change it if it wants...
float velocityScalar = glm::length(getVelocity());
const float STILL_MOVING = 0.05f / static_cast<float>(TREE_SCALE);
const float STILL_MOVING = 0.05f / (float)(TREE_SCALE);
bool isStillMoving = (velocityScalar > STILL_MOVING);
const float REALLY_OLD = 30.0f; // 30 seconds
bool isReallyOld = (getLifetime() > REALLY_OLD);

View file

@ -117,7 +117,7 @@ public:
static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew);
void update();
void update(const uint64_t& now);
void collisionWithParticle(Particle* other);
void collisionWithVoxel(VoxelDetail* voxel);

View file

@ -71,7 +71,7 @@ void ParticleTreeElement::update(ParticleTreeUpdateArgs& args) {
QList<Particle>::iterator particleItr = _particles->begin();
while(particleItr != _particles->end()) {
Particle& particle = (*particleItr);
particle.update();
particle.update(_lastChanged);
// If the particle wants to die, or if it's left our bounding box, then move it
// into the arguments moving particles. These will be added back or deleted completely