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;
}
}
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.)
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

View File

@ -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;