im making a simple html5 game for learning purposes. I want to send as minimal data over the wire as possible to keep in sync. When i send the game state between client and server i only want to send what has changed in the game state since last update to save on bandwidth / latency.
The only way i can figure out to do this is by creating a "snapshot" or copy of the game state object on each update recieved from the remote source, then after the game state is manipulated locally and needs to be sent out to the remote source loop through the game state object comparing each value to the tempory game state and only send the differences...
is this the most efficient way to do this?
/****************************/
/**** Current game state ****/
gameState = {
playerOneID: 'XXX-XXX-XXX-XXX',
playerTwoID: 'YYY-YYY-YYY-YYY',
elapsedTime: 00007,
myVariable: 'abcd1234'
}
/*******************************************/
/**** saves game state from last update recieved ****/
tmpGameState = {
playerOneID: 'XXX-XXX-XXX-XXX',
playerTwoID: 'YYY-YYY-YYY-YYY',
elapsedTime: 00003,
myVariable: 'abc123'
}
Most networks at least sends data into at most 1024 byte packet and at least when it is schedule to leave.