diff --git a/src/lua_maplib.c b/src/lua_maplib.c index c512bf3c..54614c4e 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -400,46 +400,6 @@ static int sector_get(lua_State *L) return 0; } -// help function for P_LoadSectors, find a flat in the active wad files, -// allocate an id for it, and set the levelflat (to speedup search) -// -static INT32 P_AddLevelFlatRuntime(const char *flatname) -{ - size_t i; - levelflat_t *levelflat = levelflats; - - // - // first scan through the already found flats - // - for (i = 0; i < numlevelflats; i++, levelflat++) - if (strnicmp(levelflat->name,flatname,8)==0) - break; - - // that flat was already found in the level, return the id - if (i == numlevelflats) - { - // allocate new flat memory - levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL); - levelflat = levelflats+i; - - // store the name - strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); - strupr(levelflat->name); - - // store the flat lump number - levelflat->lumpnum = R_GetFlatNumForName(flatname); - -#ifndef ZDEBUG - CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); -#endif - - numlevelflats++; - } - - // level flat id - return (INT32)i; -} - static int sector_set(lua_State *L) { sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); diff --git a/src/p_saveg.c b/src/p_saveg.c index 5e457ca3..2144a3f9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -509,10 +509,9 @@ static void P_NetArchiveWorld(void) // // flats // - // P_AddLevelFlat should not add but just return the number - if (ss->floorpic != P_AddLevelFlat(ms->floorpic, levelflats)) + if (ss->floorpic != P_CheckLevelFlat(ms->floorpic)) diff |= SD_FLOORPIC; - if (ss->ceilingpic != P_AddLevelFlat(ms->ceilingpic, levelflats)) + if (ss->ceilingpic != P_CheckLevelFlat(ms->ceilingpic)) diff |= SD_CEILPIC; if (ss->lightlevel != SHORT(ms->lightlevel)) @@ -752,12 +751,12 @@ static void P_NetUnArchiveWorld(void) sectors[i].ceilingheight = READFIXED(get); if (diff & SD_FLOORPIC) { - sectors[i].floorpic = P_AddLevelFlat((char *)get, levelflats); + sectors[i].floorpic = P_AddLevelFlatRuntime((char *)get); get += 8; } if (diff & SD_CEILPIC) { - sectors[i].ceilingpic = P_AddLevelFlat((char *)get, levelflats); + sectors[i].ceilingpic = P_AddLevelFlatRuntime((char *)get); get += 8; } if (diff & SD_LIGHT) diff --git a/src/p_setup.c b/src/p_setup.c index d6563735..ae6aa153 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -574,6 +574,69 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) return (INT32)i; } +// help function for Lua and $$$.sav reading +// same as P_AddLevelFlat, except this is not setup so we must realloc levelflats to fit in the new flat +// no longer a static func in lua_maplib.c because p_saveg.c also needs it +// +INT32 P_AddLevelFlatRuntime(const char *flatname) +{ + size_t i; + levelflat_t *levelflat = levelflats; + + // + // first scan through the already found flats + // + for (i = 0; i < numlevelflats; i++, levelflat++) + if (strnicmp(levelflat->name,flatname,8)==0) + break; + + // that flat was already found in the level, return the id + if (i == numlevelflats) + { + // allocate new flat memory + levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL); + levelflat = levelflats+i; + + // store the name + strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); + strupr(levelflat->name); + + // store the flat lump number + levelflat->lumpnum = R_GetFlatNumForName(flatname); + +#ifndef ZDEBUG + CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); +#endif + + numlevelflats++; + } + + // level flat id + return (INT32)i; +} + +// help function for $$$.sav checking +// this simply returns the flat # for the name given +// +INT32 P_CheckLevelFlat(const char *flatname) +{ + size_t i; + levelflat_t *levelflat = levelflats; + + // + // scan through the already found flats + // + for (i = 0; i < numlevelflats; i++, levelflat++) + if (strnicmp(levelflat->name,flatname,8)==0) + break; + + if (i == numlevelflats) + return 0; // ??? flat was not found, this should not happen! + + // level flat id + return (INT32)i; +} + static void P_LoadSectors(lumpnum_t lumpnum) { UINT8 *data; diff --git a/src/p_setup.h b/src/p_setup.h index 0d735fd7..3bca1104 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -47,6 +47,8 @@ typedef struct extern size_t numlevelflats; extern levelflat_t *levelflats; INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat); +INT32 P_AddLevelFlatRuntime(const char *flatname); +INT32 P_CheckLevelFlat(const char *flatname); extern size_t nummapthings; extern mapthing_t *mapthings;