I am implementing a simulation software, its about displaying some moving objects on the screen, and since i am very new to this thing, I made a little research & i am using SDL in the simulation (is it a good choice?),
my question is mainly about the frames per second, i must run at 60 or 100 fps ( I mean fixed frames per second depending on the user input), and i am doing it this way...
#define m_iUpdateInterval 10 // in case of 100 fps , is this right? and in case of 50 it would be #define m_iUpdateInterval 20
int timeToNextUpdate;
int main(int argc, char *argv[])
{
//
//some SDl initilizazion goes here
//and
timeToNextUpdate = 0;
bool done = false;
While(!done)
{
//catch events.....
//do something
//NOW THE QUESTION
SDL_Flip(screen);
SDL_Delay( timeLeft() );
}
return 1;
}
timeLeft(void)
{
Uint32 currentTime;
currentTime = SDL_GetTicks();
if( timeToNextUpdate <= currentTime )
{
timeToNextUpdate = currentTime + m_iUpdateInterval;
return 0;
}
return(timeToNextUpdate - currentTime);
}
is it the right way to do it?( If it is right at all....) (125 points)
This thing deals with times…so how can I decide the speed of my object for example (125 points)
any explanation of how is this done is most welcome