Code archives/Algorithms/Timescale

This code has been declared by its author to be Public Domain code.

Download source code

Timescale by Streaksy2010
Put SyncLagScale in your main loop, and multiply every movement by Timescale#, and it'll move fluidly. I've found this extremely useful. It's an alternative to using frame-limitting timers.

You can even use SetTimeScale(s#) to control the speed of time.

Enjoy >D

(Code archive contribution #4)
Global TimeScale#,LagScale#,TimeScaleMul#=1,TimeScaleLastTime ;TIMESCALING
Global TimeScaleLibPresent=1


Function SyncLagScale()
tim=MilliSecs()
timepassed#=tim-TimeScaleLastTime
If TimeScaleLastTime=0 Then lagscale=1 Else lagscale=(timepassed/1000)*50
TimeScaleLastTime=tim
timescale=lagscale*timescalemul:If timescale>6 Then timescale=6
If timescale>20 Then timescale=1  ;okay thats alot... lets treat it like a delay rather than an example of framerate
End Function

Function SetTimeScale(s#)
timescalemul=s
End Function

Comments

Serpent2010
I've been thinking for a while about doing something like this in a game - any frame rate would be supported and lag would be accounted for, which would be very useful in multiplayer games in that computers stay in sync despite one computer lagging more than the other.

I was going to comment on how you should limit the scaling, but I see that you've already accounted to this.

Nicely done and useful. Thanks for posting.


Streaksy2010
Thanks again serpent =D


Code Archives Forum