Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Game Timing

Sign in to follow this  


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.]
Sign in to follow this  

1 Comment

Recommended Comments

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?

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!