Merge pull request #13901 from ZehMatt/fix-replaysnapshot

Fix replay snapshots comparing states with different ticks
This commit is contained in:
ζeh Matt 2021-01-22 20:15:33 +02:00 committed by GitHub
commit 54578a0870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 20 deletions

View File

@ -533,7 +533,8 @@ struct GameStateSnapshots final : public IGameStateSnapshots
virtual GameStateCompareData_t Compare(const GameStateSnapshot_t& base, const GameStateSnapshot_t& cmp) const override final
{
GameStateCompareData_t res;
res.tick = base.tick;
res.tickLeft = base.tick;
res.tickRight = cmp.tick;
res.srand0Left = base.srand0;
res.srand0Right = cmp.srand0;
@ -643,7 +644,13 @@ struct GameStateSnapshots final : public IGameStateSnapshots
std::string outputBuffer;
char tempBuffer[1024] = {};
snprintf(tempBuffer, sizeof(tempBuffer), "tick: %08X\n", cmpData.tick);
if (cmpData.tickLeft != cmpData.tickRight)
{
outputBuffer += "WARNING: Comparing two snapshots with different ticks, this will very likely result in false "
"positives\n";
}
snprintf(tempBuffer, sizeof(tempBuffer), "tick left = %08X, tick right = %08X\n", cmpData.tickLeft, cmpData.tickRight);
outputBuffer += tempBuffer;
snprintf(

View File

@ -48,7 +48,8 @@ struct GameStateSpriteChange_t
struct GameStateCompareData_t
{
uint32_t tick;
uint32_t tickLeft;
uint32_t tickRight;
uint32_t srand0Left;
uint32_t srand0Right;
std::vector<GameStateSpriteChange_t> spriteChanges;

View File

@ -177,11 +177,7 @@ namespace OpenRCT2
#ifndef DISABLE_NETWORK
// If the network is disabled we will only get a dummy hash which will cause
// false positives during replay.
if (!CheckState())
{
StopPlayback();
return;
}
CheckState();
#endif
ReplayCommands();
@ -454,11 +450,6 @@ namespace OpenRCT2
virtual bool IsPlaybackStateMismatching() const override
{
if (_mode != ReplayMode::NONE)
{
// This state is only valid after the playback.
return false;
}
return _faultyChecksumIndex != -1;
}
@ -794,16 +785,18 @@ namespace OpenRCT2
}
#ifndef DISABLE_NETWORK
bool CheckState()
void CheckState()
{
uint32_t checksumIndex = _currentReplay->checksumIndex;
if (checksumIndex >= _currentReplay->checksums.size())
return true;
return;
const auto& savedChecksum = _currentReplay->checksums[checksumIndex];
if (_currentReplay->checksums[checksumIndex].first == gCurrentTicks)
{
_currentReplay->checksumIndex++;
rct_sprite_checksum checksum = sprite_checksum();
if (savedChecksum.second.raw != checksum.raw)
{
@ -815,8 +808,6 @@ namespace OpenRCT2
replayTick, savedChecksum.second.ToString().c_str(), checksum.ToString().c_str());
_faultyChecksumIndex = checksumIndex;
return false;
}
else
{
@ -825,10 +816,7 @@ namespace OpenRCT2
"Good state at tick %u ; Saved: %s, Current: %s", gCurrentTicks,
savedChecksum.second.ToString().c_str(), checksum.ToString().c_str());
}
_currentReplay->checksumIndex++;
}
return true;
}
#endif // DISABLE_NETWORK

View File

@ -98,6 +98,8 @@ TEST_P(ReplayTests, RunReplay)
while (replayManager->IsReplaying())
{
gs->UpdateLogic();
if (replayManager->IsPlaybackStateMismatching())
break;
}
ASSERT_FALSE(replayManager->IsReplaying());
ASSERT_FALSE(replayManager->IsPlaybackStateMismatching());