Millisecs() alternatives ?

Blitz3D Forums/Blitz3D Programming/Millisecs() alternatives ?

RifRaf(Posted 2009) [#1]
Ive found that any timing based on millisecs() can get funky if a machine is left on for days.. So far i think ive gotten around this by starting the game with a global stamp if the current time, then creating a new millisecs to subtract the start time from current millisecs value.

Are there any OTHER alternatives to this ?


Global Game_StartTime=millisecs()

Function Millisecs2#()
Return MilliSecs()-game_starttime#
End Function 



GfK(Posted 2009) [#2]
Millisecs() will start returning negative values (but incrementing as normal) after about 25 days of system up-time.

I *almost* suggested using a timer instead but apparently Blitz3D timers are a completely different beast to the timers available in Blitzmax (which I migh add, do the trick nicely).

I think BlitzSupport wrote an alternative Millisecs() function that gets around the 25 day limit but again, it was Blitzmax code and involved Long vars so wouldn't translate to Blitz3D.

I appreciate that none of this is any help whatsoever, other than to suggest why not use Blitzmax and MiniB3D in future? Other than that, if whatever hacky method you're using works, why change?


xlsior(Posted 2009) [#3]
...Or do a periodic test to see if millisecs() is smaller than your previous known value. If yes, then you know that the timer rolled over, and you can account for that.


GIB3D(Posted 2009) [#4]
Just use Abs(MilliSecs())

Edit: Oh I forgot that Millisecs() would look like it's counting down if it's on its negative side, if you use Abs on it. So nevermind.


RifRaf(Posted 2009) [#5]
is there a windows api call to reset the timer ?


GfK(Posted 2009) [#6]
I don't believe so, and even if there was, messing with it might screw up any other system timer-dependent processes.

What you might be able to do (random thought, off the top of my head), is this:
Function myMillisecs()
  Return Millisecs() - 2147483647
End Function
That way it'll be double the time (about 50 days) before the returned value is less than it was the last time you called it, as for the first 25 days you'll get negative values. This is assuming that Blitz3D handles Ints like Blitzmax does, and won't give an overflow error or something if you try to put too high/low a value into a var.

I really think you're a bit stuffed as to a permanent solution to this.


cyberyoyo(Posted 2009) [#7]
GIA_Green_Fire_
You were on the right tracks.
you need to do this:
abs(oldmillisecs-millisecs())
oldmillisecs=millisecs()


And everything should be okay


Jasu(Posted 2009) [#8]
Always count "millisecs since last tick" instead of using Millisecs() directly.
Repeat
  TimeDiff = Millisecs() - oldTime
  oldTime = Millisecs()
  ; Do all stuff using TimeDiff variable
Forever

The feature that causes this problem is also the solution:
- 2147483648 - 2147483630 = 18 (why, you might ask?)
Because -2147483648 - 1 = +2147483647 (caused by crossing integer limit)
and +2147483647 - 2147483629 = 18

You should do this regardless if you use max or 3d.