From 07988147b95ca7a4be9536284cb1059aa85b2bf0 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 1 Jan 2018 00:31:44 -0500 Subject: [PATCH] prevent compiling if pmap doesn't have enough space, make lua elements favor 1 byte IDs --- src/lua/LuaScriptInterface.cpp | 22 +++++++++++++++++++--- src/simulation/Elements.h | 7 +++++++ src/simulation/Simulation.cpp | 19 +------------------ src/simulation/elements/PIPE.cpp | 2 +- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 00b2a2a60..93346f9d9 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2526,9 +2526,10 @@ int LuaScriptInterface::elements_allocate(lua_State * l) } int newID = -1; - for(int i = PT_NUM-1; i >= 0; i--) + // Start out at 255 so that lua element IDs are still one byte (better save compatibility) + for (int i = PT_NUM >= 255 ? 255 : PT_NUM; i >= 0; i--) { - if(!luacon_sim->elements[i].Enabled) + if (!luacon_sim->elements[i].Enabled) { newID = i; luacon_sim->elements[i] = Element(); @@ -2537,8 +2538,23 @@ int LuaScriptInterface::elements_allocate(lua_State * l) break; } } + // If not enough space, then we start with the new maimum ID + if (newID == -1) + { + for (int i = PT_NUM-1; i >= 255; i--) + { + if (!luacon_sim->elements[i].Enabled) + { + newID = i; + luacon_sim->elements[i] = Element(); + luacon_sim->elements[i].Enabled = true; + luacon_sim->elements[i].Identifier = strdup(identifier.c_str()); + break; + } + } + } - if(newID != -1) + if (newID != -1) { lua_getglobal(l, "elements"); lua_pushinteger(l, newID); diff --git a/src/simulation/Elements.h b/src/simulation/Elements.h index 43dc34f9c..295e6ee78 100644 --- a/src/simulation/Elements.h +++ b/src/simulation/Elements.h @@ -60,6 +60,13 @@ #define PT_NUM (1< 16 +#error PMAPBITS is too large +#endif +#if ((XRES*YRES)< 0x100000000L +#error not enough space in pmap +#endif + struct playerst; #include "ElementClasses.h" diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 2cf88aae3..dc772c8fb 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -196,23 +196,6 @@ int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure soapList.insert(std::pair(n, i)); break; } - - /*if (save->pmapbits != PMAPBITS) - { - unsigned int pmapmask = (1<pmapbits)-1; - if (parts[i].type == PT_CRAY || parts[i].type == PT_DRAY || parts[i].type == PT_CONV) - { - int type = parts[i].ctype & pmapmask; - int data = parts[i].ctype >> save->pmapbits; - parts[i].ctype = PMAP(data, type); - } - else if (parts[i].type == PT_PIPE || parts[i].type == PT_PPIP) - { - int type = parts[i].tmp & pmapmask; - int data = parts[i].tmp >> save->pmapbits; - parts[i].tmp = PMAP(data, type); - } - }*/ } parts_lastActiveIndex = NPART-1; force_stacking_check = true; @@ -288,7 +271,7 @@ bool Simulation::TypeInCtype(int el) el == PT_STOR || el == PT_CONV || el == PT_STKM || el == PT_STKM2 || el == PT_FIGH || el == PT_LAVA || el == PT_SPRK || el == PT_PSTN || el == PT_CRAY || el == PT_DTEC || el == PT_DRAY || el == PT_PIPE || - el == PT_PPIP; + el == PT_PPIP; } bool Simulation::TypeInTmp(int el) diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 21c7e2bc9..a1b495b71 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -56,7 +56,7 @@ Element_PIPE::Element_PIPE() // 0x00001C00 forward single pixel pipe direction // 0x00002000 will transfer like a single pixel pipe when in reverse mode // 0x0001C000 reverse single pixel pipe direction -// 0x00060000 PIPE color data stored here +// 0x000E0000 PIPE color data stored here #define PFLAG_NORMALSPEED 0x00010000 #define PFLAG_INITIALIZING 0x00020000 // colors haven't been set yet