[bb] Timescale by Streaksy [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Timescale
Author : Streaksy
Posted : 1+ years ago

Description : 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)


Code :
Code (blitzbasic) Select
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 :


Serpent(Posted 1+ years ago)

 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.


Streaksy(Posted 1+ years ago)

 Thanks again serpent =D