Skip to content

Commit

Permalink
prevent compiling if pmap doesn't have enough space, make lua element…
Browse files Browse the repository at this point in the history
…s favor 1 byte IDs
  • Loading branch information
jacob1 committed Jan 1, 2018
1 parent b5159ab commit 0798814
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
22 changes: 19 additions & 3 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/simulation/Elements.h
Expand Up @@ -60,6 +60,13 @@

#define PT_NUM (1<<PMAPBITS)

#if PMAPBITS > 16
#error PMAPBITS is too large
#endif
#if ((XRES*YRES)<<PMAPBITS) > 0x100000000L
#error not enough space in pmap
#endif

struct playerst;

#include "ElementClasses.h"
Expand Down
19 changes: 1 addition & 18 deletions src/simulation/Simulation.cpp
Expand Up @@ -196,23 +196,6 @@ int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure
soapList.insert(std::pair<unsigned int, unsigned int>(n, i));
break;
}

/*if (save->pmapbits != PMAPBITS)
{
unsigned int pmapmask = (1<<save->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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/PIPE.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 0798814

Please sign in to comment.