millisecs on pc/mac

BlitzMax Forums/BlitzMax Beginners Area/millisecs on pc/mac

Kemi(Posted 2006) [#1]
I use the following loop for timing the animation of a sprite:

if millisecs()>oldms+50
oldms=millisecs()
frame=frame+1
end if

and so on.
Somehow, the animation is correct on Mac, but veeeery slow on Win.
It's not that the game runs to slow, it's just this animation that runs slow.
Isn't millisecs() safe or the same on different systems?


Dreamora(Posted 2006) [#2]
Its the same for all systems.
but as 50 isn't even divideable through 16.66 I might ask a different question:

Any chance, VSync is off on your Mac but enabled on your windows machine? (it is default enabled. this means you have to use flip 0 / flip false if you want to have your graphics app run without "waiting for sync")

A different thing is that Apple uses OpenGL but Windows DX at default. You might try it with OpenGL there as well using SetGraphicsDriver GLMax2DDriver() before calling graphics.

Its definitely no millisecs issue


H&K(Posted 2006) [#3]
Also what are you doing when it fails?

ie You havent actaly shown a loop, but just an conditional that we assume is within a loop for example

do
If milli>old+50 then .... stuff
? Win
Delay 1000
?
Loop

(I realise you havent done this, but you might be doing something else that could cause the delay)


FlameDuck(Posted 2006) [#4]
While I can't imagine it makes any difference, try:
	newms=MilliSecs()
If Abs (oldms-newms) > 50
	Print "!"
	oldms = newms
EndIf
This does two things. It uses discrete delta values, preventing the game from hanging when MilliSecs() rollover occurs, secondly it assures that the number of millisecs elapsed is the same both times it has been used. Not that I think it makes a difference from what you describe, but without more code to go by, it's the best I can do.


BadJim(Posted 2006) [#5]
This line is wrong:
oldms = millisecs()

It should read:
oldms=oldms+50

This is the main reason why your timing is out.

You also should use While instead of If. This avoids slowdown if the players framerate drops below 20fps. Also, remember to initialise oldms to millisecs() or you will skip an absurd number of frames