prevent compiling if pmap doesn't have enough space, make lua elements favor 1 byte IDs

This commit is contained in:
jacob1 2018-01-01 00:31:44 -05:00
parent b5159ab74e
commit 07988147b9
4 changed files with 28 additions and 22 deletions

View File

@ -2526,7 +2526,8 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
} }
int newID = -1; 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)
{ {
@ -2537,6 +2538,21 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
break; 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)
{ {

View File

@ -60,6 +60,13 @@
#define PT_NUM (1<<PMAPBITS) #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; struct playerst;
#include "ElementClasses.h" #include "ElementClasses.h"

View File

@ -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)); soapList.insert(std::pair<unsigned int, unsigned int>(n, i));
break; 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; parts_lastActiveIndex = NPART-1;
force_stacking_check = true; force_stacking_check = true;

View File

@ -56,7 +56,7 @@ Element_PIPE::Element_PIPE()
// 0x00001C00 forward single pixel pipe direction // 0x00001C00 forward single pixel pipe direction
// 0x00002000 will transfer like a single pixel pipe when in reverse mode // 0x00002000 will transfer like a single pixel pipe when in reverse mode
// 0x0001C000 reverse single pixel pipe direction // 0x0001C000 reverse single pixel pipe direction
// 0x00060000 PIPE color data stored here // 0x000E0000 PIPE color data stored here
#define PFLAG_NORMALSPEED 0x00010000 #define PFLAG_NORMALSPEED 0x00010000
#define PFLAG_INITIALIZING 0x00020000 // colors haven't been set yet #define PFLAG_INITIALIZING 0x00020000 // colors haven't been set yet