Hi there!
Thanks for your replies, they are really helpful!
I've checked the link about improve Cocos2D performance and I've done a couple of things that made me win about 10 FPS in the iPhone 1G (so now the game runs at about 50 FPS, which is quite more acceptable than 30-40 FPS)! I've also modified my own scene update methods to link them to the delta time (so now even if the game runs beyond 60 FPS game logic is processed correctly -I think this is how chipmunk works, isn't it?-).
There's only one thing that isn't clear for me (and I think this is one of the most important things): timesteps (both of you told me about them)!
Well, at the beginning I had steps as a static variable:
Code: Select all
-(void) step: (ccTime) delta
{
int steps = 2;
CGFloat dt = delta/(CGFloat)steps;
for(int i=0; i<steps; i++){
cpSpaceStep(space, dt);
}
cpSpaceHashEach(space->activeShapes, &eachShape, nil);
cpSpaceHashEach(space->staticShapes, &eachShape, nil);
[self updateScene:delta];
}
This works great with the 3GS, but crashes with the 1G as I told you. Then' I've tried the following:
Code: Select all
-(void) step: (ccTime) delta
{
int steps = 10;
CGFloat dt = delta/(CGFloat)steps;
for(int i=0; i<steps; i++){
cpSpaceStep(space, dt);
}
cpSpaceHashEach(space->activeShapes, &eachShape, nil);
cpSpaceHashEach(space->staticShapes, &eachShape, nil);
[self updateScene:delta];
}
Let's rock! 10 steps instead of 2! With this the game runs well in the iPhone 1G! However, I suppose this can waste a lot of resources because the game may need only 4 or 6 steps and every time chipmunk is doing 10 steps, so now I've done the following:
Code: Select all
-(void) step: (ccTime) delta
{
// 60 FPS means a standard delta of 0.01666
// so if FPS are less than 0.01666 steps will increase,
// and if not steps will be 2 as they were at the beginning
int steps = (int)( delta / 0.01666 ) + 1;
if (steps < 2) {
steps = 2;
}
CGFloat dt = delta/(CGFloat)steps;
for(int i=0; i<steps; i++){
cpSpaceStep(space, dt);
}
cpSpaceHashEach(space->activeShapes, &eachShape, nil);
cpSpaceHashEach(space->staticShapes, &eachShape, nil);
[self updateScene:delta];
}
Which method do you recommend, the second or the third one? I mean it's OK to calculate how many steps will be needed at every loop or it's better to have always more steps than normally needed to ensure it will work?
Thanks in advance for your time!
PS: Sorry for my english, it isn't as good as I want...