SDL_GetTicks()

SDL_GetTicks() function. it stores the first time program started and gives you the value how much time has passed since the first execution. yeah here is the question. wouldnt it be problematic after some time passed. i mean every data type has a limit right ???

is it a problem or not. and if it is how to fix it
Last edited on
closed account (3qX21hU5)
From what I seen from the documentation the value will wrap around after 49.7 days so no it will not be a problem most likely (Unless you plan to have your program running for over a month and a half then you need to account for it).
thx.
Yes after a [long] while SDL_GetTicks(), and any other 'gettick' or 'clock' style of function will wrap.

The way around this is to never use the given time directly, but rather use the delta between two recorded times to know how much time has passed.

1
2
3
4
5
6
7
8
prevtime = SDL_GetTicks();

// ... later

nexttime = SDL_GetTicks();

timepassed = (nexttime - prevtime);
  // ok to use 'timepassed'... even if SDL_GetTicks wrapped 


As long as the delta doesn't wrap you'll be fine.
wow that was the thing i was looking for
closed account (3qX21hU5)
I am assuming that you are making some sort of a game (Correct me if I am wrong). But even if you aren't this article is worth checking out http://gafferongames.com/game-physics/fix-your-timestep/
even though i m not making one i want to know how to make one. and also working on complex algorithms (maybe it might not be complex but to me it is for now) will increase my experience and knowledge i believe

and thanks for the link

EDIT: also that site is worth more then just checking. people should memorize those articles :D
Last edited on
i removed my question from here because it was something out of this topic
Last edited on
Topic archived. No new replies allowed.