Getting a negative readout from Millisecs()
Blitz3D Forums/Blitz3D Beginners Area/Getting a negative readout from Millisecs()
| ||
Some of my programs that were around 1000 ifps on my tower started being a solid 60 on my new laptop, and then about a month later, 0. So I checked the readouts for the render tween, and Millisecs() has a negative number on my laptop, counting up to 0. Anyone know why? |
| ||
Iirc millisecs() counts the number of milliseconds that the computer has been on, and if that's longer than the variable can contain it rolls over into negatives. On a laptop that sleeps or hibernates rather than shuts down, it is bound to happen a lot. |
| ||
So, no effect on the render tween, I take it? I can only tell visually that it still seems to be working right, but I kind of miss my handy dandy "before the render tweening" fps indicator that the negative value seems to cancel out. |
| ||
From what I can recall the rendertween code uses the relative difference between values returned by the Millisecs() command, rather than the direct output from Millisecs(). The difference value will always be correct as long as the difference time isn't greater than around 24 days (ie. the number of milliseconds that can be counted by either the positive or negative values of a 32 bit integer. See the comments here for more info: http://www.blitzbasic.com/b3ddocs/command.php?name=Millisecs&ref=2d_cat So basically set up your game loop like this:- Global G_old_millisecs ;- G_old_millisecs = Millisecs() ; Prime the 'G_old_millisecs' global. You'll also need to do this after returning from any kind of pause in your game session. While Not Keyhit( 1 ) milisecs_difference = Millisecs() - G_old_millisecs ; 'milisecs_difference' should be used to increment your various game timers here. Those timers should factor in the value storage limitations of 32 bit signed integers. Wend |
| ||
Nobody said that? Millisecs counts up from the last booting on. After 2 million seconds it sets the 32th bit true. Reading this as a signed 32 Bit integer gives a negative value, since that bit is normally used as minus sign. You may simply mask millisecs m=Millisecs() and $7fffffff but every month or so, it will restart from zero, so, catch that before it causes an error. if newmillisecs < oldmillisecs then print "something's strange..." |
| ||
Then again... o.O, no you can't simply mask the bit, because it counts up beginning from ~ -2 billion... well, just catch the rare new < old case and handle it. |