domewolf/maidemo — Issue #12: Physics performance
Author: jesseniemisto
Created: 2011-11-04 17:40:59+00:00
State: open

srsly, physics library is getting way too cumbersome. Just check that screenshot:

http://users.metropolia.fi/~m0703165/shot.png

And you'll notice that the culprit is checkCollisions(). Just reviewed some of the code and here's a few performance killers:

- Why is every body pair added (and iterated!) in collisions module. This takes way too much time. Only actual collisions should be added.
- World bodies are iterated too many times. Combine resolveForces and checkCollisions.

step() should look like (pseudo-code):

// first iteration.
for (each body) {

Vec2f net_force

for (each celestial body) {
if (body->testCollisionWith(celestial body)) {
collisionsModule.addCollisionPair(body, celestialBody)
}
net_force += body->resolveForceWith(celestial Body)
}

body->setNetForce(net_force);

if (body->shouldRemove()) {
callbackRemoveFunction(body); // e.g. static controller function
}
}

collisionsModule.applyCollisions();

// second iteration.
for (each body) {
// via member variable, can also be given as param
body->applyForce();
}

That should make the physics much faster.