Update( FrameTime )
This will update Animations, Physics, Tween, based upon the input time... if we use 0 then AppGameKit uses the Time between the current and last Sync (i.e. GetFrameTime( )) although keep in mind this function is inaccurate.
If we manually call this, it WILL override it's call within Sync( ) although it is better to use Render( ) : Swap( ).
Now in order to get both Client and Server to be running the same time., we can use GetSecondsFromUnix( )
Keep in mind this value is going to be universal...
Type Time
Previous As Float
Current As Float
Duration As Float
Elapsed As Float
Frequency As Float
EndType
Function Time( Frequency As Float )
Local Out As Time
Out.Frequency = Frequency / 1000.0
Out.Current = Timer()
EndFunction Out
Function SyncTime( This Ref As Time )
This.Previous = This.Current
This.Current = Timer()
This.Duration = This.Current - This.Previous
Inc This.Elapsed, This.Duration
If This.Elapsed >= This.Frequency
Dec This.Elapsed, This.Frequency
ExitFunction -1
EndIf
EndFunction 0
This is a Timer Type and Function... pretty simple to figure out how to use it.
By Default, this is NOT going to be Synchronised between Applications, but we can change that using Unix Time.
Print( "Calibrating... Please Wait" )
Sync()
Repeat
ResetTimer()
Until GetSecondsFromUnix( GetUnixTime() ) = 0
Print( "Calibration Complete" )
Sync()
Alright, so now any Timers we create are Synchronised with the Unix Time WHEN you created them.
Now remember both Unix Time and Timer( ) should be Synchronised., meaning we can now send the Trunc( TimeName.Duration ) (Integer... Milliseconds) and Unix Seconds (Integer) together.
We then compare it on the Client Side when we receive the Message.
Latency# = Abs( ( ClientSecond + (ClientMillisecond * 0.001) ) - ( HostSecond + (HostMillisecond * 0.001) ) )
This will give us the Latency (in Seconds) ... now as a note if we want this in Milliseconds we just * 1000.0
Remember that Latency# is going to be an Offset., so we want to then add that to our Update( MainLoop.Duration + Latency# ) and this will ensure that ALL Clients are Synchronised with the Host Application.
It might also be a good idea to store Latency over 1s Periods., as this IS going to be useful for Network Prediction purposes.
But I wont delve into that here.
Hopefully this is helpful.