Time Synchronization
[Networking]

Collaboration diagram for Time Synchronization:

A system of approximating the time the server is using to assist in having all clients show a game state that is as current as possible. More...


Files

file  timesync.c
 Implementation of Time Synchronization.
file  timesync.h
 Interface to the Time Synchronization module.

Data Structures

struct  TimeSample_t
 Data from a single time sync sample. More...

Typedefs

typedef TimeSample_t TimeSample

Enumerations

enum  TSYNC_STATE {
  TIMESYNC_IDLE, TIMESYNC_INPROG, TIMESYNC_FINISHED, TIMESYNC_POOR,
  TIMESYNC_ERROR
}

Functions

void StartClientTimeSync ()
 Starts the time synchronization process on the I/O Thread.
Bool StartServerTimeSync ()
 Starts the time synchronization server on a separate thread.
void StopServerTimeSync ()
 Stops the time synchronization server and returns the time sync state to TSYNC_STATE::TIMESYNC_IDLE.

Variables

Sint32 timeDelta
 The time delta used to produce common game time.
TimeSample timeSyncResults
 The final results of the last time sync operation that ended with a state of either TSYNC_STATE::TIMESYNC_FINISHED or TSYNC_STATE::TIMESYNC_POOR.
int timeSyncState
 The state of the time synchronization system; a value from TSYNC_STATE.

Detailed Description

A system of approximating the time the server is using to assist in having all clients show a game state that is as current as possible.

The system consists of two parts: client and server. The client first connects to a server, then calls StartClientSync(). The time sync process occurs on the I/O Thread. timeSyncState will change to reflect the status of the time sync operation (see TSYNC_STATE for the valid codes).

The server is started by a call to StartServerTimeSync() which will start another thread to handle incomming client time sync requests. To stop the time sync server, call StopServerTimeSync().

Copyright (C) 2007 Jeff Jackowski

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Or visit their website at: http://www.gnu.org/

Author:
Jeff Jackowski

Typedef Documentation

typedef struct TimeSample_t TimeSample

Definition at line 111 of file timesync.h.


Enumeration Type Documentation

enum TSYNC_STATE

Enumerator:
TIMESYNC_IDLE  Indicates that the time synchronization process is not running and there are no valid results.
TIMESYNC_INPROG  Indicates that time synchronization is in progress and results are not yet available.
TIMESYNC_FINISHED  Indicates that the time synchronization process has completed successfully and valid results are available.
TIMESYNC_POOR  Indicates that the time synchronization process could not determine a good time delta and any attempt to play may not work well.
TIMESYNC_ERROR  Indicates that the time synchronization process terminated on an error and no results are available.

Definition at line 65 of file timesync.h.


Function Documentation

void StartClientTimeSync (  ) 

Starts the time synchronization process on the I/O Thread.

Precondition:
The process is a client that has successfully connected to a server.
Author:
Jeff Jackowski

Definition at line 372 of file timesync.c.

References ClientSync(), QueueOperation(), TIMESYNC_INPROG, and timeSyncState.

Referenced by DiscoverConnectServer().

Here is the call graph for this function:

Bool StartServerTimeSync (  ) 

Starts the time synchronization server on a separate thread.

Todo:
Fix this to better support IPv6.
Returns:
True on success, false if the server thread could not be started.
Author:
Jeff Jackowski

Todo:
Support IPv6.

Definition at line 435 of file timesync.c.

References FALSE, SocketAddr_t::ipv4, PORT_STSYNC, ServerTimeSyncThread(), thread, TRUE, tsyncSock, and UnicastSocket().

Referenced by NetCliToSrv().

Here is the call graph for this function:

void StopServerTimeSync (  ) 

Stops the time synchronization server and returns the time sync state to TSYNC_STATE::TIMESYNC_IDLE.

Author:
Jeff Jackowski

Definition at line 452 of file timesync.c.

References CloseSocket, TIMESYNC_IDLE, timeSyncState, and tsyncSock.

Referenced by NetCliToSrv(), NetDisconnect(), NetSrvToCli(), and NetUninit().


Variable Documentation

Sint32 timeDelta

The time delta used to produce common game time.

This is the integer version of timeSyncResults.delta.

Definition at line 44 of file timesync.c.

Referenced by ClientSync().

TimeSample timeSyncResults

The final results of the last time sync operation that ended with a state of either TSYNC_STATE::TIMESYNC_FINISHED or TSYNC_STATE::TIMESYNC_POOR.

Definition at line 46 of file timesync.c.

Referenced by ClientSync(), ComputeAverages(), ComputeStdDeviation(), RemoveBadSamples(), and RenderLatency().

int timeSyncState

The state of the time synchronization system; a value from TSYNC_STATE.

Definition at line 45 of file timesync.c.


Generated on Mon May 28 04:41:44 2007 for Retro Tank Super Attack by  doxygen 1.5.2