From c28316c5c77d47abf5718e23b53b222848f24b89 Mon Sep 17 00:00:00 2001 From: Cyp Date: Sat, 10 Jul 2010 18:04:49 +0200 Subject: [PATCH] newnet: Don't bother sending synch messages unless actually out of synch. If it ain't broke, don't use up bandwidth trying to fix it. --- lib/gamelib/gtime.c | 5 ++++ lib/gamelib/gtime.h | 2 ++ src/multisync.c | 70 ++++++++++++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/lib/gamelib/gtime.c b/lib/gamelib/gtime.c index 18c82802b..90ac0dadd 100644 --- a/lib/gamelib/gtime.c +++ b/lib/gamelib/gtime.c @@ -435,3 +435,8 @@ void setPlayerGameTime(unsigned player, uint32_t time) gameQueueTime[player] = time; } } + +bool isInSync(void) +{ + return !crcError; +} diff --git a/lib/gamelib/gtime.h b/lib/gamelib/gtime.h index 9494ccf7c..39176fb57 100644 --- a/lib/gamelib/gtime.h +++ b/lib/gamelib/gtime.h @@ -180,6 +180,8 @@ void recvPlayerGameTime(NETQUEUE_ queue); ///< Processes a GAME_ bool checkPlayerGameTime(unsigned player); ///< Checks that we are not waiting for a GAME_GAME_TIME message from this player. (player can be NET_ALL_PLAYERS.) void setPlayerGameTime(unsigned player, uint32_t time); ///< Sets the player's time. +bool isInSync(void); ///< Returns true unless there was a CRC mismatch between the last GAME_GAME_TIME messages. + #ifdef __cplusplus } #endif //__cplusplus diff --git a/src/multisync.c b/src/multisync.c index 1a1e6c6d4..2a8e6da99 100644 --- a/src/multisync.c +++ b/src/multisync.c @@ -220,7 +220,11 @@ static BOOL sendDroidCheck(void) lastSent = gameTime; - NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_DROID); + + if (!isInSync()) // Don't really send anything, unless out of synch. + { + NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_DROID); + } // Allocate space for the list of droids to send ppD = alloca(sizeof(DROID *) * toSend); @@ -245,17 +249,25 @@ static BOOL sendDroidCheck(void) *(PACKAGED_CHECK *)pD->gameCheckDroid = packageCheck(pD); } - // Send the number of droids to expect - NETuint8_t(&count); - NETuint32_t(&gameTime); // Send game time. - - // Add the droids to the packet - for (i = 0; i < count; i++) + if (!isInSync()) // Don't really send anything, unless out of synch. { - NETPACKAGED_CHECK((PACKAGED_CHECK *)ppD[i]->gameCheckDroid); + // Send the number of droids to expect + NETuint8_t(&count); + NETuint32_t(&gameTime); // Send game time. + + // Add the droids to the packet + for (i = 0; i < count; i++) + { + NETPACKAGED_CHECK((PACKAGED_CHECK *)ppD[i]->gameCheckDroid); + } } - return NETend(); + if (!isInSync()) // Don't really send anything, unless out of synch. + { + return NETend(); + } + + return true; } #define MIN_DELAY_BETWEEN_DROID_SYNCHS 5000 // Must be longer than maximum possible latency. @@ -512,18 +524,21 @@ static BOOL sendStructureCheck(void) if (myResponsibility(player)) { - NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_STRUCT); - NETuint8_t(&player); - NETuint32_t(&gameTime); - NETuint32_t(&pS->id); - NETuint32_t(&pS->body); - NETuint32_t(&pS->pStructureType->type); - NETRotation(&pS->rot); - if (hasCapacity) - { - NETuint8_t(&capacity); - } - NETend(); + if (!isInSync()) // Don't really send anything, unless out of synch. + { + NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_STRUCT); + NETuint8_t(&player); + NETuint32_t(&gameTime); + NETuint32_t(&pS->id); + NETuint32_t(&pS->body); + NETuint32_t(&pS->pStructureType->type); + NETRotation(&pS->rot); + if (hasCapacity) + { + NETuint8_t(&capacity); + } + NETend(); + } } } @@ -680,11 +695,14 @@ static BOOL sendPowerCheck() powerCheckLastPower[player] = getPower(player); if (myResponsibility(player)) { - NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_POWER); - NETuint8_t(&player); - NETuint32_t(&gameTime); - NETfloat(&powerCheckLastPower[player]); - NETend(); + if (!isInSync()) // Don't really send anything, unless out of synch. + { + NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_POWER); + NETuint8_t(&player); + NETuint32_t(&gameTime); + NETfloat(&powerCheckLastPower[player]); + NETend(); + } } } return true;