timbobsteve
Member
- Joined
- Oct 4, 2005
- Messages
- 301
Hi All,
Just a quick query to see how everyone else manages timers in their own code. Let me give some background. Currently I have a sprite class that loads in a descriptor file that tells it what sprite-sheet to use, the number of frames, the frame-rate, the dimensions of each frame on the sheet and whether to oscillate the animation. This is all working fine, but I'm experiencing some slow-down and I think it might be because my Sprite class has it's own LastTicks variable and calculates the new LastTicks value every time Sprite->Animate() is run. e.g.
I was wondering if querying SDL for ticks on ever cycle is what could be affecting the performance (e.g. when my sprite moves it "jitters" across the screen).
Would it be a good move to move the timer stuff to the main Engine code and then pass the Ticks-Passed value to each object when calling OnLoop()? How else would you allow child objects to query their creator (the Engine) whenever they need to know the time-passed? (I wouldn't want to start passing pointers to the Engine, just so children could use engine->GetTicks()... it seems unsafe).
Any help is appreciated
Timbobsteve.
Just a quick query to see how everyone else manages timers in their own code. Let me give some background. Currently I have a sprite class that loads in a descriptor file that tells it what sprite-sheet to use, the number of frames, the frame-rate, the dimensions of each frame on the sheet and whether to oscillate the animation. This is all working fine, but I'm experiencing some slow-down and I think it might be because my Sprite class has it's own LastTicks variable and calculates the new LastTicks value every time Sprite->Animate() is run. e.g.
Code:
Sprite::Animate() {
long newTicks = SDL_GetTicks();
float secondsPassed = (float)newTicks - (float)oldTicks / 1000
// If need to animate based on time then do it here
if(secondsPassed >= 1) {
// Increase frame by 1
frameCount++;
oldTicks = newTicks;
}
}
Would it be a good move to move the timer stuff to the main Engine code and then pass the Ticks-Passed value to each object when calling OnLoop()? How else would you allow child objects to query their creator (the Engine) whenever they need to know the time-passed? (I wouldn't want to start passing pointers to the Engine, just so children could use engine->GetTicks()... it seems unsafe).
Any help is appreciated
Timbobsteve.