Skip to content

Commit

Permalink
Don't report desynch when player names don't match.
Browse files Browse the repository at this point in the history
Host sometimes considers empty slots to have names, while other clients consider the
empty slots unnamed. Since the player names don't affect the game state, this is safe
to ignore.
  • Loading branch information
Cyp committed May 6, 2012
1 parent 18216c6 commit 1ef4fc6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/netplay/netplay.cpp
Expand Up @@ -3407,6 +3407,16 @@ void _syncDebugBacktrace(const char *function)
syncDebugLog[syncDebugNext].setCrc(backupCrc);
}

uint32_t syncDebugGetCrc()
{
return syncDebugLog[syncDebugNext].getCrc();
}

void syncDebugSetCrc(uint32_t crc)
{
syncDebugLog[syncDebugNext].setCrc(crc);
}

void resetSyncDebug()
{
for (unsigned i = 0; i < MAX_SYNC_HISTORY; ++i)
Expand Down
2 changes: 2 additions & 0 deletions lib/netplay/netplay.h
Expand Up @@ -351,6 +351,8 @@ void _syncDebug(const char *function, const char *str, ...)
void _syncDebugIntList(const char *function, const char *str, int *ints, size_t numInts);
#define syncDebugBacktrace() do { _syncDebugBacktrace(__FUNCTION__); } while(0)
void _syncDebugBacktrace(const char *function); ///< Adds a backtrace to syncDebug, if the platform supports it. Can be a bit slow, don't call way too often, unless desperate.
uint32_t syncDebugGetCrc(); ///< syncDebug() calls between uint32_t crc = syncDebugGetCrc(); and syncDebugSetCrc(crc); appear in synch debug logs, but without triggering a desynch if different.
void syncDebugSetCrc(uint32_t crc); ///< syncDebug() calls between uint32_t crc = syncDebugGetCrc(); and syncDebugSetCrc(crc); appear in synch debug logs, but without triggering a desynch if different.

typedef uint16_t GameCrcType; // Truncate CRC of game state to 16 bits, to save a bit of bandwidth.
void resetSyncDebug(); ///< Resets the syncDebug, so syncDebug from a previous game doesn't cause a spurious desynch dump.
Expand Down
6 changes: 3 additions & 3 deletions src/loop.cpp
Expand Up @@ -423,17 +423,17 @@ static GAMECODE renderLoop()

static void gameStateUpdate()
{
// Can't dump isHumanPlayer, since it causes spurious desynch dumps when players leave.
// TODO isHumanPlayer should probably be synchronised, since the game state seems to depend on it, so there might also be a risk of real desynchs when players leave.
//syncDebug("map = \"%s\", humanPlayers = %d %d %d %d %d %d %d %d", game.map, isHumanPlayer(0), isHumanPlayer(1), isHumanPlayer(2), isHumanPlayer(3), isHumanPlayer(4), isHumanPlayer(5), isHumanPlayer(6), isHumanPlayer(7));
syncDebug("map = \"%s\", pseudorandom 32-bit integer = 0x%08X, allocated = %d %d %d %d %d %d %d %d %d %d, position = %d %d %d %d %d %d %d %d %d %d", game.map, gameRandU32(),
NetPlay.players[0].allocated, NetPlay.players[1].allocated, NetPlay.players[2].allocated, NetPlay.players[3].allocated, NetPlay.players[4].allocated, NetPlay.players[5].allocated, NetPlay.players[6].allocated, NetPlay.players[7].allocated, NetPlay.players[8].allocated, NetPlay.players[9].allocated,
NetPlay.players[0].position, NetPlay.players[1].position, NetPlay.players[2].position, NetPlay.players[3].position, NetPlay.players[4].position, NetPlay.players[5].position, NetPlay.players[6].position, NetPlay.players[7].position, NetPlay.players[8].position, NetPlay.players[9].position
);
// TODO: Figure out why the following player names aren't always synchronised.
uint32_t crc = syncDebugGetCrc();
for (unsigned n = 0; n < MAX_PLAYERS; ++n)
{
syncDebug("Player %d = \"%s\"", n, NetPlay.players[n].name);
}
syncDebugSetCrc(crc); // Do not dump desynch logs because of NetPlay.players[n].name being different.

// Actually send pending droid orders.
sendQueuedDroidInfo();
Expand Down

0 comments on commit 1ef4fc6

Please sign in to comment.