From d675d483bd1749a7e3e84e05d7a82f9eb2f785bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 13 Oct 2021 11:26:48 +0200 Subject: [PATCH] Leave the original GameSave alone in Simulation::Load --- .gitignore | 2 +- src/client/GameSave.cpp | 2 +- src/client/GameSave.h | 2 +- src/simulation/Simulation.cpp | 14 +++++++------- src/simulation/Simulation.h | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index e75f18a3b..43905b162 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,4 @@ screenshot_* *.opensdf *.sdf /font/ - +compile_commands.json diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index c52f84335..a24d1418d 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -17,7 +17,7 @@ #include "common/tpt-minmax.h" -GameSave::GameSave(GameSave & save): +GameSave::GameSave(const GameSave & save): majorVersion(save.majorVersion), waterEEnabled(save.waterEEnabled), legacyEnable(save.legacyEnable), diff --git a/src/client/GameSave.h b/src/client/GameSave.h index fb68544fd..71c19a3f8 100644 --- a/src/client/GameSave.h +++ b/src/client/GameSave.h @@ -113,7 +113,7 @@ public: int pmapbits; GameSave(); - GameSave(GameSave & save); + GameSave(const GameSave & save); GameSave(int width, int height); GameSave(char * data, int dataSize); GameSave(std::vector data); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index c14a366f4..0ac13da5c 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -42,15 +42,16 @@ 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]; -int Simulation::Load(GameSave * save, bool includePressure) +int Simulation::Load(const GameSave * save, bool includePressure) { return Load(save, includePressure, 0, 0); } -int Simulation::Load(GameSave * save, bool includePressure, int fullX, int fullY) +int Simulation::Load(const GameSave * originalSave, bool includePressure, int fullX, int fullY) { - if (!save) + if (!originalSave) return 1; + auto save = std::unique_ptr(new GameSave(*originalSave)); try { save->Expand(); @@ -77,9 +78,8 @@ int Simulation::Load(GameSave * save, bool includePressure, int fullX, int fullY } if(save->palette.size()) { - for(std::vector::iterator iter = save->palette.begin(), end = save->palette.end(); iter != end; ++iter) + for(auto &pi : save->palette) { - GameSave::PaletteItem pi = *iter; if (pi.second > 0 && pi.second < PT_NUM) { int myId = 0; @@ -5356,7 +5356,7 @@ void Simulation::SetCustomGOL(std::vector newCustomGol) customGol = newCustomGol; } -String Simulation::ElementResolve(int type, int ctype) +String Simulation::ElementResolve(int type, int ctype) const { if (type == PT_LIFE) { @@ -5376,7 +5376,7 @@ String Simulation::ElementResolve(int type, int ctype) return "Empty"; } -String Simulation::BasicParticleInfo(Particle const &sample_part) +String Simulation::BasicParticleInfo(Particle const &sample_part) const { StringBuilder sampleInfo; int type = sample_part.type; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 1d1e5a2ec..a7c1b97d1 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -115,8 +115,8 @@ public: int sandcolour_frame; int deco_space; - int Load(GameSave * save, bool includePressure); - int Load(GameSave * save, bool includePressure, int x, int y); + int Load(const GameSave * save, bool includePressure); + int Load(const GameSave * save, bool includePressure, int x, int y); GameSave * Save(bool includePressure); GameSave * Save(bool includePressure, int x1, int y1, int x2, int y2); void SaveSimOptions(GameSave * gameSave); @@ -135,10 +135,10 @@ public: int eval_move(int pt, int nx, int ny, unsigned *rr); void init_can_move(); bool IsWallBlocking(int x, int y, int type); - bool IsElement(int type) { + bool IsElement(int type) const { return (type > 0 && type < PT_NUM && elements[type].Enabled); } - bool IsElementOrNone(int type) { + bool IsElementOrNone(int type) const { return (type >= 0 && type < PT_NUM && elements[type].Enabled); } void create_cherenkov_photon(int pp); @@ -221,8 +221,8 @@ public: static int remainder_p(int x, int y); static float remainder_p(float x, float y); - String ElementResolve(int type, int ctype); - String BasicParticleInfo(Particle const &sample_part); + String ElementResolve(int type, int ctype) const; + String BasicParticleInfo(Particle const &sample_part) const; struct CustomGOLData