From 53672c05197dcd3a8a0ff7a46aea79370b98608a Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 7 Apr 2020 08:28:31 +0100 Subject: [PATCH] Introduce a GameStateSnapshot to the replay file --- src/openrct2/ReplayManager.cpp | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 4605c7a69f..2fbbf26e22 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -11,6 +11,7 @@ #include "Context.h" #include "Game.h" +#include "GameStateSnapshots.h" #include "OpenRCT2.h" #include "ParkImporter.h" #include "PlatformEnvironment.h" @@ -91,11 +92,12 @@ namespace OpenRCT2 std::multiset commands; std::vector> checksums; uint32_t checksumIndex; + MemoryStream gameStateSnapshot; }; class ReplayManager final : public IReplayManager { - static constexpr uint16_t ReplayVersion = 3; + static constexpr uint16_t ReplayVersion = 4; static constexpr uint32_t ReplayMagic = 0x5243524F; // ORCR. static constexpr int ReplayCompressionLevel = 9; static constexpr int NormalRecordingChecksumTicks = 1; @@ -246,6 +248,14 @@ namespace OpenRCT2 DataSerialiser cheatDataDs(true, replayData->cheatData); SerialiseCheats(cheatDataDs); + IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots(); + + auto& snapshot = snapshots->CreateSnapshot(); + snapshots->Capture(snapshot); + snapshots->LinkSnapshot(snapshot, gCurrentTicks, scenario_rand_state().s0); + DataSerialiser snapShotDs(true, replayData->gameStateSnapshot); + snapshots->SerialiseSnapshot(snapshot, snapShotDs); + if (_mode != ReplayMode::NORMALISATION) _mode = ReplayMode::RECORDING; @@ -379,6 +389,27 @@ namespace OpenRCT2 gCurrentTicks = replayData->tickStart; + replayData->gameStateSnapshot.SetPosition(0); + DataSerialiser ds(false, replayData->gameStateSnapshot); + + IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots(); + + GameStateSnapshot_t& replaySnapshot = snapshots->CreateSnapshot(); + snapshots->SerialiseSnapshot(replaySnapshot, ds); + + auto& localSnapshot = snapshots->CreateSnapshot(); + snapshots->Capture(localSnapshot); + snapshots->LinkSnapshot(localSnapshot, gCurrentTicks, scenario_rand_state().s0); + GameStateCompareData_t cmpData = snapshots->Compare(replaySnapshot, localSnapshot); + if (cmpData.spriteChanges.size() > 0) + { + std::string outputPath = GetContext()->GetPlatformEnvironment()->GetDirectoryPath( + DIRBASE::USER, DIRID::LOG_DESYNCS); + + std::string outputFile = Path::Combine(outputPath, "replaydesync.txt"); + snapshots->LogCompareDataToFile(outputFile, cmpData); + } + _currentReplay = std::move(replayData); _currentReplay->checksumIndex = 0; _faultyChecksumIndex = -1; @@ -595,6 +626,7 @@ namespace OpenRCT2 data.parkParams.SetPosition(0); data.cheatData.SetPosition(0); data.spriteSpatialData.SetPosition(0); + data.gameStateSnapshot.SetPosition(0); return true; } @@ -728,6 +760,7 @@ namespace OpenRCT2 serialiser << data.checksums[i].second.raw; } + serialiser << data.gameStateSnapshot; return true; }