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.
master
Cyp 2010-07-10 18:04:49 +02:00
parent d2994ad998
commit c28316c5c7
3 changed files with 51 additions and 26 deletions

View File

@ -435,3 +435,8 @@ void setPlayerGameTime(unsigned player, uint32_t time)
gameQueueTime[player] = time; gameQueueTime[player] = time;
} }
} }
bool isInSync(void)
{
return !crcError;
}

View File

@ -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.) 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. 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 #ifdef __cplusplus
} }
#endif //__cplusplus #endif //__cplusplus

View File

@ -220,7 +220,11 @@ static BOOL sendDroidCheck(void)
lastSent = gameTime; 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 // Allocate space for the list of droids to send
ppD = alloca(sizeof(DROID *) * toSend); ppD = alloca(sizeof(DROID *) * toSend);
@ -245,17 +249,25 @@ static BOOL sendDroidCheck(void)
*(PACKAGED_CHECK *)pD->gameCheckDroid = packageCheck(pD); *(PACKAGED_CHECK *)pD->gameCheckDroid = packageCheck(pD);
} }
// Send the number of droids to expect if (!isInSync()) // Don't really send anything, unless out of synch.
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); // 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. #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)) if (myResponsibility(player))
{ {
NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_STRUCT); if (!isInSync()) // Don't really send anything, unless out of synch.
NETuint8_t(&player); {
NETuint32_t(&gameTime); NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_STRUCT);
NETuint32_t(&pS->id); NETuint8_t(&player);
NETuint32_t(&pS->body); NETuint32_t(&gameTime);
NETuint32_t(&pS->pStructureType->type); NETuint32_t(&pS->id);
NETRotation(&pS->rot); NETuint32_t(&pS->body);
if (hasCapacity) NETuint32_t(&pS->pStructureType->type);
{ NETRotation(&pS->rot);
NETuint8_t(&capacity); if (hasCapacity)
} {
NETend(); NETuint8_t(&capacity);
}
NETend();
}
} }
} }
@ -680,11 +695,14 @@ static BOOL sendPowerCheck()
powerCheckLastPower[player] = getPower(player); powerCheckLastPower[player] = getPower(player);
if (myResponsibility(player)) if (myResponsibility(player))
{ {
NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_POWER); if (!isInSync()) // Don't really send anything, unless out of synch.
NETuint8_t(&player); {
NETuint32_t(&gameTime); NETbeginEncode(NETgameQueue(selectedPlayer), GAME_CHECK_POWER);
NETfloat(&powerCheckLastPower[player]); NETuint8_t(&player);
NETend(); NETuint32_t(&gameTime);
NETfloat(&powerCheckLastPower[player]);
NETend();
}
} }
} }
return true; return true;