So recently I began to start some optimization on scuba guy. Our first game. Everybody’s always talking about fix your timestep fix your timestep, so I finially got around to doing it. My previous method was scheduling as fast as it could, and stepping through the space with a different delta time every tick..

[cc lang=”objc”]
[self schedule: @selector(tick:)];

-(void)tick:(ccTime)dt {
cpSpaceStep(space, dt);
}
[/cc]

So i finally switched it to a fixed timestep. Funny, cause I actually saw no significant performance improvements in this case. I switched my scheduler to 1.0/60.0 and the fixed timestep to 1.0/60.0 as well. Running at 30FPS and nothing too significant. After poking around the forums, supposedly you see some performance improvements in chipmunk because it can cache things with a fixed timestep. Anyways, here’s the switch:

[cc lang=”objc”]
[self schedule: @selector(tick:) interval: 1.0f/60.0f];
-(void)tick:(ccTime)dt {

float fixedTimeStep = 1.0/60.0;
float timeToRun = dt + timeAccumulator;
while(timeToRun >= fixedTimeStep) {
cpSpaceStep(space, fixedTimeStep);
timeToRun = timeToRun – fixedTimeStep;
}
timeAccumulator = timeToRun;
}
[/cc]