Leave the original GameSave alone in Simulation::Load

This commit is contained in:
Tamás Bálint Misius 2021-10-13 11:26:48 +02:00
parent 816b9eda3d
commit d675d483bd
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
5 changed files with 16 additions and 16 deletions

2
.gitignore vendored
View File

@ -90,4 +90,4 @@ screenshot_*
*.opensdf
*.sdf
/font/
compile_commands.json

View File

@ -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),

View File

@ -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<char> data);

View File

@ -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<GameSave>(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<GameSave::PaletteItem>::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<CustomGOLData> 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;

View File

@ -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