From 6179071351097b8de5f44619e670aaf8c1fe8404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Tue, 30 May 2023 15:18:54 +0200 Subject: [PATCH] Pass particle coordinates to Simulation::Save Both Save and Load were recently migrated to block coordinates, see 7ef02a6c0bb1. The expected behaviour for Save is to extend the particle-oriented rect it gets to the smallest enclosing block-oriented rect and save all blocks inside that rect, but exclude the particles that fall outside the original rect. Using block coordinates made this exclusion impossible. --- src/gui/game/GameController.cpp | 8 ++++---- src/simulation/Simulation.cpp | 6 +++--- src/simulation/Simulation.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 299b2e7b7..351ffb9de 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -442,7 +442,7 @@ static Rect SaneSaveRect(Vec2 point1, Vec2 point2) auto tly = std::min(point1.Y, point2.Y); auto brx = std::max(point1.X, point2.X); auto bry = std::max(point1.Y, point2.Y); - return RectBetween(Vec2{ tlx, tly } / CELL, Vec2{ brx, bry } / CELL); + return RectBetween(Vec2{ tlx, tly }, Vec2{ brx, bry }); } ByteString GameController::StampRegion(ui::Point point1, ui::Point point2) @@ -1146,7 +1146,7 @@ void GameController::OpenSearch(String searchText) void GameController::OpenLocalSaveWindow(bool asCurrent) { Simulation * sim = gameModel->GetSimulation(); - auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), CELLS.OriginRect()); + auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), RES.OriginRect()); if(!gameSave) { new ErrorMessage("Error", "Unable to build save."); @@ -1357,7 +1357,7 @@ void GameController::OpenSaveWindow() if(gameModel->GetUser().UserID) { Simulation * sim = gameModel->GetSimulation(); - auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), CELLS.OriginRect()); + auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), RES.OriginRect()); if(!gameSave) { new ErrorMessage("Error", "Unable to build save."); @@ -1399,7 +1399,7 @@ void GameController::SaveAsCurrent() if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName()) { Simulation * sim = gameModel->GetSimulation(); - auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), CELLS.OriginRect()); + auto gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), RES.OriginRect()); if(!gameSave) { new ErrorMessage("Error", "Unable to build save."); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 117d725e7..4053c6e88 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -19,7 +19,7 @@ extern int Element_LOLZ_lolz[XRES/9][YRES/9]; extern int Element_LOVE_RuleTable[9][9]; extern int Element_LOVE_love[XRES/9][YRES/9]; -void Simulation::Load(const GameSave *originalSave, bool includePressure, Vec2 blockP) +void Simulation::Load(const GameSave *originalSave, bool includePressure, Vec2 blockP) // block coordinates { auto save = std::unique_ptr(new GameSave(*originalSave)); @@ -335,10 +335,10 @@ void Simulation::Load(const GameSave *originalSave, bool includePressure, Vec2 Simulation::Save(bool includePressure, Rect blockR) +std::unique_ptr Simulation::Save(bool includePressure, Rect partR) // particle coordinates { + auto blockR = RectBetween(partR.TopLeft / CELL, partR.BottomRight / CELL); auto blockP = blockR.TopLeft; - auto partR = RectSized(blockR.TopLeft * CELL, blockR.Size() * CELL); auto newSave = std::make_unique(blockR.Size()); auto &possiblyCarriesType = Particle::PossiblyCarriesType(); diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 57632d8b9..f274d36cc 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -121,8 +121,8 @@ public: uint64_t frameCount; bool ensureDeterminism; - void Load(const GameSave *save, bool includePressure, Vec2 blockP); - std::unique_ptr Save(bool includePressure, Rect blockR); + void Load(const GameSave *save, bool includePressure, Vec2 blockP); // block coordinates + std::unique_ptr Save(bool includePressure, Rect partR); // particle coordinates void SaveSimOptions(GameSave &gameSave); SimulationSample GetSample(int x, int y);