Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualParadigm Shifter

Posted 28 October 2013 - 09:35 PM

You should have 2 clocks anyway... real time and virtual time, the real time clock keeps ticking when the game is paused. Virtual time only runs when game is running and you can scale it for time control effects too.

 

If OP is worried about accuracy with a constantly increasing time you can use fmodf to do a floating point modulo style operation so values wrap around at multiples of the periodicity, or just subtract the periodicity when the counter overflows.

 

EDIT: I also saw an article or blog from a guy a Valve who says they use double precision time but start off at a large value so it keeps the same precision for a long time (something like weeks or months, maybe years), but my google fu failed me.

 

EDIT2: Google fu didn't fail me for long, when I remembered it was in a blog post! http://www.altdevblogaday.com/2012/02/05/dont-store-that-in-a-float/

 

EDIT3: I'm sure there was something in the blog about starting the time not at zero but I guess I misremembered. Maybe that was in another article in his discussion of floating point stuff, so check the other articles as well.


#3Paradigm Shifter

Posted 28 October 2013 - 09:29 PM

You should have 2 clocks anyway... real time and virtual time, the real time clock keeps ticking when the game is paused. Virtual time only runs when game is running and you can scale it for time control effects too.

 

If OP is worried about accuracy with a constantly increasing time you can use fmodf to do a floating point modulo style operation so values wrap around at multiples of the periodicity, or just subtract the periodicity when the counter overflows.

 

EDIT: I also saw an article or blog from a guy a Valve who says they use double precision time but start off at a large value so it keeps the same precision for a long time (something like weeks or months, maybe years), but my google fu failed me.

 

EDIT2: Google fu didn't fail me for long, when I remembered it was in a blog post! http://www.altdevblogaday.com/2012/02/05/dont-store-that-in-a-float/


#2Paradigm Shifter

Posted 28 October 2013 - 09:28 PM

You should have 2 clocks anyway... real time and virtual time, the real time clock keeps ticking when the game is paused. Virtual time only runs when game is running and you can scale it for time control effects too.

 

If OP is worried about accuracy with a constantly increasing time you can use fmodf to do a floating point modulo style operation so values wrap around at multiples of the periodicity, or just subtract the periodicity when the counter overflows.

 

EDIT: I also saw an article or blog from a guy a Valve who says they use double precision time but start off at a large value so it keeps the same precision for a long time (something like weeks or months, maybe years), but my google fu failed me.


#1Paradigm Shifter

Posted 28 October 2013 - 09:25 PM

You should have 2 clocks anyway... real time and virtual time, the real time clock keeps ticking when the game is paused. Virtual time only runs when game is running and you can scale it for time control effects too.

 

If OP is worried about accuracy with a constantly increasing time you can use fmodf to do a floating point modulo style operation so values wrap around at multiples of the periodicity, or just subtract the periodicity when the counter overflows.


PARTNERS