Game Development Community

Advice for sending time in packUpdate/unpackUpdate?

by Tom Spilman · in Torque Game Engine · 05/04/2006 (2:56 am) · 1 replies

I need to send a countdown timer value from the server to the client. This value is being counted down on all clients at the same time and needs to be very near identical on the clients if not perfectly in sync.

My first thought was that i could count on the simulation time being in sync across clients and the server. This way i could convert the countdown timer value into an absolute end time and convert it back once it gets the the client. The problem is that the client isn't in sync with the server. The one place in script i see where time is sync'd is in server/scripts/game.cs:

function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

.. which would call client/scripts/client.cs and do nothing:

function clientCmdSyncClock(%time)
{
   // Time update from the server, this is only sent at the start of a mission
   // or when a client joins a game in progress.
}

So i would need to figure out what belongs in clientCmdSyncClock() to actually do the sync. Then maybe this could work as long as i can count on clocks not drifting.

Or is there a better method to sync a timer like this that i've missed?

About the author

Tom is a programmer and co-owner of Sickhead Games, LLC.


#1
05/04/2006 (3:13 am)
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime, $Sim::Time);

function clientCmdSyncClock(%gameStartTime, %serverSimTime)
{
   // Time update from the server, this is only sent at the start of a mission
   // or when a client joins a game in progress.
   echo("SyncClock received" SPC %time SPC $Sim::Time);
   $TimeOffset = $Sim::Time - %serverSimTime;
   GUITimer.setTime(%gameStartTime);
}

Is what we've got. The GUI Timer is an X minutes left countdown timer that starts counting from the current time offset by %gamestarttime. Serversimtime is sent over to allow for clients joining mid way through the game.

Although I didn't code this and havn't done any real testing it does appear to work in both single player and over the internet test we did. Although the time will probably be slightly out due to latency, but nothing really noticable.