• entries
246
175
• views
154182

# Game Timing

197 views

one of the things i do in most of my allegro-demo thingers is i have a timer variable that tracks how long has passed (in msec) since the program was started. its granted that i can't really do alot better than 10msec granularity, so thats ok, thats what i have it set to.

i'm using an unsigned int that rolls over after 4294967295. X3 works it out to..

msecs /sec /min /hr /day
4294967295/1000/60/60/24 = 49.71027 days.

i'm never going to see that happen in any of my games, i'm sure of it. but.. what if? one thought i just had was about the granularity. if instead of cranking the time passed by 10msec, how about i just crank it by 1 and multiply the resulting yeild by 10 when i want to use it? that means i can use it 10x longer.. (assume average 365.25day years)

msecs /sec /min /hr /day /yr
42949672950/1000/60/60/24/365.25 = 1.360993 years.

i'd say that was a fine solution, but in a worst-case scenario, i think that i could keep another unsigned int that stored the number of days that passed and knock the timer back 24 hours every time it rolled over. i don't even think i'd need to use an unsigned for that.. i'm actually going to go build that right now.

[edit: yup it works great, it can go to the maximum of an unsigned long in days before i have to worry about timer overruns. hmm how many years is that... calc says ~11,759,000 years [grin] if i were to use an unsigned int, i'd get ~179.425 years out of it. that'd be damn good enough for me.]

## 1 Comment

Windows 95/98 will crash if you leave them on for 49 days, so I suspect you're in good company. [grin]

How long is anyone gonna realistically play your game anyway?

## Create an account

Register a new account