From ea8ca1a1ab7e748babbd5ffba24a7f1dcbdaa571 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 12 Sep 2025 15:36:58 +0200 Subject: [PATCH] copy initial map state on mapload for Netarchiving + cleanup like this we dont have to reopen the mapdata 3 times each time we prepare a netsave also allows us to directly compare sector and line properties this should save a bit of time when someone joins or resynchs with gamestate system this is based on some UDMF work from srb2 --- src/p_saveg.c | 438 +++++++++++++++++++++++++++----------------------- src/p_setup.c | 37 +++-- src/p_setup.h | 3 + 3 files changed, 261 insertions(+), 217 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index b3641b57e..025d3fa9a 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -515,45 +515,87 @@ static void P_NetUnArchivePlayers(savebuffer_t *save, boolean reloading) #define LD_S2BOTTEX 0x04 #define LD_S2MIDTEX 0x08 -// -// P_NetArchiveWorld -// -static void P_NetArchiveWorld(savebuffer_t *save) +#define FD_FLAGS 0x01 +#define FD_ALPHA 0x02 + +// Check if any of the sector's FOFs differ from how they spawned +static boolean CheckFFloorDiff(const sector_t *ss) +{ + ffloor_t *rover; + + for (rover = ss->ffloors; rover; rover = rover->next) + { + if (rover->flags != rover->spawnflags + || rover->alpha != rover->spawnalpha) + { + return true; // we found an FOF that changed! + // don't bother checking for more, we do that later + } + } + + return false; +} + +// Special case: save the stats of all modified ffloors along with their ffloor "number"s +// we don't bother with ffloors that haven't changed, that would just add to savegame even more than is really needed +static void ArchiveFFloors(savebuffer_t *save, const sector_t *ss) +{ + size_t j = 0; // ss->ffloors is saved as ffloor #0, ss->ffloors->next is #1, etc + ffloor_t *rover; + UINT8 fflr_diff; + + for (rover = ss->ffloors; rover; rover = rover->next) + { + fflr_diff = 0; // reset diff flags + + if (rover->flags != rover->spawnflags) + fflr_diff |= FD_FLAGS; + if (rover->alpha != rover->spawnalpha) + fflr_diff |= FD_ALPHA; + + if (fflr_diff) + { + WRITEUINT16(save->p, j); // save ffloor "number" + WRITEUINT8(save->p, fflr_diff); + + if (fflr_diff & FD_FLAGS) + WRITEUINT32(save->p, rover->flags); + if (fflr_diff & FD_ALPHA) + WRITEINT16(save->p, rover->alpha); + } + + j++; + } + + WRITEUINT16(save->p, 0xffff); +} + +static void ArchiveSectors(savebuffer_t *save) { size_t i; - const line_t *li = lines; - const side_t *si; - UINT8 *put; - - // reload the map just to see difference - virtres_t* virt = vres_GetMap(lastloadedmaplumpnum); - mapsector_t *ms = (mapsector_t*) vres_Find(virt, "SECTORS")->data; - mapsidedef_t *msd = (mapsidedef_t*) vres_Find(virt, "SIDEDEFS")->data; - maplinedef_t *mld = (maplinedef_t*) vres_Find(virt, "LINEDEFS")->data; const sector_t *ss = sectors; + const sector_t *spawnss = spawnsectors; UINT8 diff, diff2; - WRITEUINT32(save->p, ARCHIVEBLOCK_WORLD); - put = save->p; - - for (i = 0; i < numsectors; i++, ss++, ms++) + for (i = 0; i < numsectors; i++, ss++, spawnss++) { diff = diff2 = 0; - if (ss->floorheight != SHORT(ms->floorheight)<floorheight != spawnss->floorheight) diff |= SD_FLOORHT; - if (ss->ceilingheight != SHORT(ms->ceilingheight)<ceilingheight != spawnss->ceilingheight) diff |= SD_CEILHT; + // // flats // - if (ss->floorpic != P_CheckLevelFlat(ms->floorpic)) + if (ss->floorpic != spawnss->floorpic) diff |= SD_FLOORPIC; - if (ss->ceilingpic != P_CheckLevelFlat(ms->ceilingpic)) + if (ss->ceilingpic != spawnss->ceilingpic) diff |= SD_CEILPIC; - if (ss->lightlevel != SHORT(ms->lightlevel)) + if (ss->lightlevel != spawnss->lightlevel) diff |= SD_LIGHT; - if (ss->special != SHORT(ms->special)) + if (ss->special != spawnss->special) diff |= SD_SPECIAL; if (ss->floor_xoffs != ss->spawn_flr_xoffs) @@ -569,205 +611,214 @@ static void P_NetArchiveWorld(savebuffer_t *save) if (ss->ceilingpic_angle != ss->spawn_flrpic_angle) diff2 |= SD_CEILANG; - if (ss->tag != SHORT(ms->tag)) + if (ss->tag != spawnss->tag) diff2 |= SD_TAG; if (ss->nexttag != ss->spawn_nexttag || ss->firsttag != ss->spawn_firsttag) diff2 |= SD_TAGLIST; - // Check if any of the sector's FOFs differ from how they spawned - if (ss->ffloors) - { - ffloor_t *rover; - for (rover = ss->ffloors; rover; rover = rover->next) - { - if (rover->flags != rover->spawnflags - || rover->alpha != rover->spawnalpha) - { - diff |= SD_FFLOORS; // we found an FOF that changed! - break; // don't bother checking for more, we do that later - } - } - } + if (ss->ffloors && CheckFFloorDiff(ss)) + diff |= SD_FFLOORS; if (diff2) diff |= SD_DIFF2; if (diff) { - WRITEUINT16(put, i); - WRITEUINT8(put, diff); + WRITEUINT16(save->p, i); + WRITEUINT8(save->p, diff); + if (diff & SD_DIFF2) - WRITEUINT8(put, diff2); + WRITEUINT8(save->p, diff2); if (diff & SD_FLOORHT) - WRITEFIXED(put, ss->floorheight); + WRITEFIXED(save->p, ss->floorheight); if (diff & SD_CEILHT) - WRITEFIXED(put, ss->ceilingheight); + WRITEFIXED(save->p, ss->ceilingheight); if (diff & SD_FLOORPIC) - WRITEMEM(put, levelflats[ss->floorpic].name, 8); + WRITEMEM(save->p, levelflats[ss->floorpic].name, 8); if (diff & SD_CEILPIC) - WRITEMEM(put, levelflats[ss->ceilingpic].name, 8); + WRITEMEM(save->p, levelflats[ss->ceilingpic].name, 8); if (diff & SD_LIGHT) - WRITEINT16(put, ss->lightlevel); + WRITEINT16(save->p, ss->lightlevel); if (diff & SD_SPECIAL) - WRITEINT16(put, ss->special); + WRITEINT16(save->p, ss->special); if (diff2 & SD_FXOFFS) - WRITEFIXED(put, ss->floor_xoffs); + WRITEFIXED(save->p, ss->floor_xoffs); if (diff2 & SD_FYOFFS) - WRITEFIXED(put, ss->floor_yoffs); + WRITEFIXED(save->p, ss->floor_yoffs); if (diff2 & SD_CXOFFS) - WRITEFIXED(put, ss->ceiling_xoffs); + WRITEFIXED(save->p, ss->ceiling_xoffs); if (diff2 & SD_CYOFFS) - WRITEFIXED(put, ss->ceiling_yoffs); + WRITEFIXED(save->p, ss->ceiling_yoffs); if (diff2 & SD_TAG) // save only the tag - WRITEINT16(put, ss->tag); + WRITEINT16(save->p, ss->tag); if (diff2 & SD_FLOORANG) - WRITEANGLE(put, ss->floorpic_angle); + WRITEANGLE(save->p, ss->floorpic_angle); if (diff2 & SD_CEILANG) - WRITEANGLE(put, ss->ceilingpic_angle); + WRITEANGLE(save->p, ss->ceilingpic_angle); if (diff2 & SD_TAGLIST) // save both firsttag and nexttag { // either of these could be changed even if tag isn't - WRITEINT32(put, ss->firsttag); - WRITEINT32(put, ss->nexttag); + WRITEINT32(save->p, ss->firsttag); + WRITEINT32(save->p, ss->nexttag); } - // Special case: save the stats of all modified ffloors along with their ffloor "number"s - // we don't bother with ffloors that haven't changed, that would just add to savegame even more than is really needed if (diff & SD_FFLOORS) - { - size_t j = 0; // ss->ffloors is saved as ffloor #0, ss->ffloors->next is #1, etc - ffloor_t *rover; - UINT8 fflr_diff; - for (rover = ss->ffloors; rover; rover = rover->next) - { - fflr_diff = 0; // reset diff flags - if (rover->flags != rover->spawnflags) - fflr_diff |= 1; - if (rover->alpha != rover->spawnalpha) - fflr_diff |= 2; - - if (fflr_diff) - { - WRITEUINT16(put, j); // save ffloor "number" - WRITEUINT8(put, fflr_diff); - if (fflr_diff & 1) - WRITEUINT32(put, rover->flags); - if (fflr_diff & 2) - WRITEINT16(put, rover->alpha); - } - j++; - } - WRITEUINT16(put, 0xffff); - } + ArchiveFFloors(save, ss); } } - WRITEUINT16(put, 0xffff); + WRITEUINT16(save->p, 0xffff); +} - // do lines - for (i = 0; i < numlines; i++, mld++, li++) +static void ArchiveLines(savebuffer_t *save) +{ + size_t i; + const line_t *li = lines; + const line_t *spawnli = spawnlines; + const side_t *si; + const side_t *spawnsi; + UINT8 diff, diff2; + + for (i = 0; i < numlines; i++, spawnli++, li++) { diff = diff2 = 0; - if (li->special != SHORT(mld->special)) + if (li->special != spawnli->special) diff |= LD_SPECIAL; - if (SHORT(mld->special) == 321 || SHORT(mld->special) == 322) // only reason li->callcount would be non-zero is if either of these are involved + if (spawnli->special == 321 || spawnli->special == 322) // only reason li->callcount would be non-zero is if either of these are involved diff |= LD_CLLCOUNT; if (li->sidenum[0] != 0xffff) { si = &sides[li->sidenum[0]]; - if (si->textureoffset != SHORT(msd[li->sidenum[0]].textureoffset)<sidenum[0]]; + + if (si->textureoffset != spawnsi[li->sidenum[0]].textureoffset) diff |= LD_S1TEXOFF; //SoM: 4/1/2000: Some textures are colormaps. Don't worry about invalid textures. - if (R_CheckTextureNumForName(msd[li->sidenum[0]].toptexture) != -1 - && si->toptexture != R_TextureNumForName(msd[li->sidenum[0]].toptexture)) + if (si->toptexture != spawnsi[li->sidenum[0]].toptexture) diff |= LD_S1TOPTEX; - if (R_CheckTextureNumForName(msd[li->sidenum[0]].bottomtexture) != -1 - && si->bottomtexture != R_TextureNumForName(msd[li->sidenum[0]].bottomtexture)) + if (si->bottomtexture != spawnsi[li->sidenum[0]].bottomtexture) diff |= LD_S1BOTTEX; - if (R_CheckTextureNumForName(msd[li->sidenum[0]].midtexture) != -1 - && si->midtexture != R_TextureNumForName(msd[li->sidenum[0]].midtexture)) + if (si->midtexture != spawnsi[li->sidenum[0]].midtexture) diff |= LD_S1MIDTEX; } if (li->sidenum[1] != 0xffff) { si = &sides[li->sidenum[1]]; - if (si->textureoffset != SHORT(msd[li->sidenum[1]].textureoffset)<sidenum[1]]; + + if (si->textureoffset != spawnsi[li->sidenum[1]].textureoffset) diff2 |= LD_S2TEXOFF; - if (R_CheckTextureNumForName(msd[li->sidenum[1]].toptexture) != -1 - && si->toptexture != R_TextureNumForName(msd[li->sidenum[1]].toptexture)) + if (si->toptexture != spawnsi[li->sidenum[1]].toptexture) diff2 |= LD_S2TOPTEX; - if (R_CheckTextureNumForName(msd[li->sidenum[1]].bottomtexture) != -1 - && si->bottomtexture != R_TextureNumForName(msd[li->sidenum[1]].bottomtexture)) + if (si->bottomtexture != spawnsi[li->sidenum[1]].bottomtexture) diff2 |= LD_S2BOTTEX; - if (R_CheckTextureNumForName(msd[li->sidenum[1]].midtexture) != -1 - && si->midtexture != R_TextureNumForName(msd[li->sidenum[1]].midtexture)) + if (si->midtexture != spawnsi[li->sidenum[1]].midtexture) diff2 |= LD_S2MIDTEX; + if (diff2) diff |= LD_DIFF2; } if (diff) { - WRITEINT16(put, i); - WRITEUINT8(put, diff); + WRITEINT16(save->p, i); + WRITEUINT8(save->p, diff); if (diff & LD_DIFF2) - WRITEUINT8(put, diff2); + WRITEUINT8(save->p, diff2); if (diff & LD_FLAG) - WRITEINT16(put, li->flags); + WRITEINT16(save->p, li->flags); if (diff & LD_SPECIAL) - WRITEINT16(put, li->special); + WRITEINT16(save->p, li->special); if (diff & LD_CLLCOUNT) - WRITEINT16(put, li->callcount); + WRITEINT16(save->p, li->callcount); si = &sides[li->sidenum[0]]; if (diff & LD_S1TEXOFF) - WRITEFIXED(put, si->textureoffset); + WRITEFIXED(save->p, si->textureoffset); if (diff & LD_S1TOPTEX) - WRITEINT32(put, si->toptexture); + WRITEINT32(save->p, si->toptexture); if (diff & LD_S1BOTTEX) - WRITEINT32(put, si->bottomtexture); + WRITEINT32(save->p, si->bottomtexture); if (diff & LD_S1MIDTEX) - WRITEINT32(put, si->midtexture); + WRITEINT32(save->p, si->midtexture); si = &sides[li->sidenum[1]]; if (diff2 & LD_S2TEXOFF) - WRITEFIXED(put, si->textureoffset); + WRITEFIXED(save->p, si->textureoffset); if (diff2 & LD_S2TOPTEX) - WRITEINT32(put, si->toptexture); + WRITEINT32(save->p, si->toptexture); if (diff2 & LD_S2BOTTEX) - WRITEINT32(put, si->bottomtexture); + WRITEINT32(save->p, si->bottomtexture); if (diff2 & LD_S2MIDTEX) - WRITEINT32(put, si->midtexture); + WRITEINT32(save->p, si->midtexture); } } - WRITEUINT16(put, 0xffff); - R_ClearTextureNumCache(false); - vres_Free(virt); - save->p = put; + WRITEUINT16(save->p, 0xffff); } // -// P_NetUnArchiveWorld +// P_NetArchiveWorld // -static void P_NetUnArchiveWorld(savebuffer_t *save) +static void P_NetArchiveWorld(savebuffer_t *save) +{ + WRITEUINT32(save->p, ARCHIVEBLOCK_WORLD); + + ArchiveSectors(save); + ArchiveLines(save); + R_ClearTextureNumCache(false); +} + +static void UnArchiveFFloors(savebuffer_t *save, const sector_t *ss) +{ + UINT16 j = 0; // number of current ffloor in loop + UINT16 fflr_i; // saved ffloor "number" of next modified ffloor + UINT16 fflr_diff; // saved ffloor diff + ffloor_t *rover; + + rover = ss->ffloors; + if (!rover) // it is assumed sectors[i].ffloors actually exists, but just in case... + I_Error("Sector does not have any ffloors!"); + + fflr_i = READUINT16(save->p); // get first modified ffloor's number ready + for (;;) // for some reason the usual for (rover = x; ...) thing doesn't work here? + { + if (fflr_i == 0xffff) // end of modified ffloors list, let's stop already + break; + // should NEVER need to be checked + //if (rover == NULL) + //break; + if (j != fflr_i) // this ffloor was not modified + { + j++; + rover = rover->next; + continue; + } + + fflr_diff = READUINT8(save->p); + + if (fflr_diff & FD_FLAGS) + rover->flags = (ffloortype_e)READUINT32(save->p); + if (fflr_diff & FD_ALPHA) + rover->alpha = READINT16(save->p); + + fflr_i = READUINT16(save->p); // get next ffloor "number" ready + + j++; + rover = rover->next; + } +} + +static void UnArchiveSectors(savebuffer_t *save) { UINT16 i; - line_t *li; - side_t *si; - UINT8 *get; UINT8 diff, diff2; - if (READUINT32(save->p) != ARCHIVEBLOCK_WORLD) - I_Error("Bad $$$.sav at archive block World"); - - get = save->p; - for (;;) { - i = READUINT16(get); + i = READUINT16(save->p); if (i == 0xffff) break; @@ -775,137 +826,118 @@ static void P_NetUnArchiveWorld(savebuffer_t *save) if (i > numsectors) I_Error("Invalid sector number %u from server (expected end at %s)", i, sizeu1(numsectors)); - diff = READUINT8(get); + diff = READUINT8(save->p); if (diff & SD_DIFF2) - diff2 = READUINT8(get); + diff2 = READUINT8(save->p); else diff2 = 0; if (diff & SD_FLOORHT) - sectors[i].floorheight = READFIXED(get); + sectors[i].floorheight = READFIXED(save->p); if (diff & SD_CEILHT) - sectors[i].ceilingheight = READFIXED(get); + sectors[i].ceilingheight = READFIXED(save->p); if (diff & SD_FLOORPIC) { - sectors[i].floorpic = P_AddLevelFlatRuntime((char *)get); - get += 8; + sectors[i].floorpic = P_AddLevelFlatRuntime((char *)save->p); + save->p += 8; } if (diff & SD_CEILPIC) { - sectors[i].ceilingpic = P_AddLevelFlatRuntime((char *)get); - get += 8; + sectors[i].ceilingpic = P_AddLevelFlatRuntime((char *)save->p); + save->p += 8; } if (diff & SD_LIGHT) - sectors[i].lightlevel = READINT16(get); + sectors[i].lightlevel = READINT16(save->p); if (diff & SD_SPECIAL) - sectors[i].special = READINT16(get); + sectors[i].special = READINT16(save->p); if (diff2 & SD_FXOFFS) - sectors[i].floor_xoffs = READFIXED(get); + sectors[i].floor_xoffs = READFIXED(save->p); if (diff2 & SD_FYOFFS) - sectors[i].floor_yoffs = READFIXED(get); + sectors[i].floor_yoffs = READFIXED(save->p); if (diff2 & SD_CXOFFS) - sectors[i].ceiling_xoffs = READFIXED(get); + sectors[i].ceiling_xoffs = READFIXED(save->p); if (diff2 & SD_CYOFFS) - sectors[i].ceiling_yoffs = READFIXED(get); + sectors[i].ceiling_yoffs = READFIXED(save->p); if (diff2 & SD_TAG) - sectors[i].tag = READINT16(get); // DON'T use P_ChangeSectorTag + sectors[i].tag = READINT16(save->p); // DON'T use P_ChangeSectorTag if (diff2 & SD_TAGLIST) { - sectors[i].firsttag = READINT32(get); - sectors[i].nexttag = READINT32(get); + sectors[i].firsttag = READINT32(save->p); + sectors[i].nexttag = READINT32(save->p); } if (diff2 & SD_FLOORANG) - sectors[i].floorpic_angle = READANGLE(get); + sectors[i].floorpic_angle = READANGLE(save->p); if (diff2 & SD_CEILANG) - sectors[i].ceilingpic_angle = READANGLE(get); + sectors[i].ceilingpic_angle = READANGLE(save->p); if (diff & SD_FFLOORS) - { - UINT16 j = 0; // number of current ffloor in loop - UINT16 fflr_i; // saved ffloor "number" of next modified ffloor - UINT16 fflr_diff; // saved ffloor diff - ffloor_t *rover; - - rover = sectors[i].ffloors; - if (!rover) // it is assumed sectors[i].ffloors actually exists, but just in case... - I_Error("Sector does not have any ffloors!"); - - fflr_i = READUINT16(get); // get first modified ffloor's number ready - for (;;) // for some reason the usual for (rover = x; ...) thing doesn't work here? - { - if (fflr_i == 0xffff) // end of modified ffloors list, let's stop already - break; - // should NEVER need to be checked - //if (rover == NULL) - //break; - if (j != fflr_i) // this ffloor was not modified - { - j++; - rover = rover->next; - continue; - } - - fflr_diff = READUINT8(get); - - if (fflr_diff & 1) - rover->flags = READUINT32(get); - if (fflr_diff & 2) - rover->alpha = READINT16(get); - - fflr_i = READUINT16(get); // get next ffloor "number" ready - - j++; - rover = rover->next; - } - } + UnArchiveFFloors(save, §ors[i]); } +} + +static void UnArchiveLines(savebuffer_t *save) +{ + UINT16 i; + line_t *li; + side_t *si; + UINT8 diff, diff2; for (;;) { - i = READUINT16(get); + i = READUINT16(save->p); if (i == 0xffff) break; if (i > numlines) I_Error("Invalid line number %u from server", i); - diff = READUINT8(get); + diff = READUINT8(save->p); li = &lines[i]; if (diff & LD_DIFF2) - diff2 = READUINT8(get); + diff2 = READUINT8(save->p); else diff2 = 0; if (diff & LD_FLAG) - li->flags = READINT16(get); + li->flags = READINT16(save->p); if (diff & LD_SPECIAL) - li->special = READINT16(get); + li->special = READINT16(save->p); if (diff & LD_CLLCOUNT) - li->callcount = READINT16(get); + li->callcount = READINT16(save->p); si = &sides[li->sidenum[0]]; if (diff & LD_S1TEXOFF) - si->textureoffset = READFIXED(get); + si->textureoffset = READFIXED(save->p); if (diff & LD_S1TOPTEX) - si->toptexture = READINT32(get); + si->toptexture = READINT32(save->p); if (diff & LD_S1BOTTEX) - si->bottomtexture = READINT32(get); + si->bottomtexture = READINT32(save->p); if (diff & LD_S1MIDTEX) - si->midtexture = READINT32(get); + si->midtexture = READINT32(save->p); si = &sides[li->sidenum[1]]; if (diff2 & LD_S2TEXOFF) - si->textureoffset = READFIXED(get); + si->textureoffset = READFIXED(save->p); if (diff2 & LD_S2TOPTEX) - si->toptexture = READINT32(get); + si->toptexture = READINT32(save->p); if (diff2 & LD_S2BOTTEX) - si->bottomtexture = READINT32(get); + si->bottomtexture = READINT32(save->p); if (diff2 & LD_S2MIDTEX) - si->midtexture = READINT32(get); + si->midtexture = READINT32(save->p); } +} - save->p = get; +// +// P_NetUnArchiveWorld +// +static void P_NetUnArchiveWorld(savebuffer_t *save) +{ + if (READUINT32(save->p) != ARCHIVEBLOCK_WORLD) + I_Error("Bad $$$.sav at archive block World"); + + UnArchiveSectors(save); + UnArchiveLines(save); } // diff --git a/src/p_setup.c b/src/p_setup.c index c8849b95d..f683ceece 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -111,6 +111,9 @@ node_t *nodes; line_t *lines; side_t *sides; mapthing_t *mapthings; +sector_t *spawnsectors; +line_t *spawnlines; +side_t *spawnsides; INT32 numstarposts; boolean levelloading; UINT8 levelfadecol; @@ -2024,10 +2027,10 @@ static void P_LoadMapData(const virtres_t* virt) I_Error("LINEDEFS lump not found"); // Traditional doom map format just assumes the number of elements from the lump sizes. - numvertexes = virtvertexes->size / sizeof (mapvertex_t); - numsectors = virtsectors->size / sizeof (mapsector_t); - numsides = virtsidedefs->size / sizeof (mapsidedef_t); - numlines = virtlinedefs->size / sizeof (maplinedef_t); + numvertexes = virtvertexes->size / sizeof(mapvertex_t); + numsectors = virtsectors->size / sizeof(mapsector_t); + numsides = virtsidedefs->size / sizeof(mapsidedef_t); + numlines = virtlinedefs->size / sizeof(maplinedef_t); nummapthings = virtthings->size / (5 * sizeof (INT16)); if (numvertexes <= 0) @@ -2039,11 +2042,11 @@ static void P_LoadMapData(const virtres_t* virt) if (numlines <= 0) I_Error("Level has no linedefs"); - vertexes = Z_Calloc(numvertexes * sizeof (*vertexes), PU_LEVEL, NULL); - sectors = Z_Calloc(numsectors * sizeof (*sectors), PU_LEVEL, NULL); - sides = Z_Calloc(numsides * sizeof (*sides), PU_LEVEL, NULL); - lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL); - mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL); + vertexes = Z_Calloc(numvertexes * sizeof(*vertexes), PU_LEVEL, NULL); + sectors = Z_Calloc(numsectors * sizeof(*sectors), PU_LEVEL, NULL); + sides = Z_Calloc(numsides * sizeof(*sides), PU_LEVEL, NULL); + lines = Z_Calloc(numlines * sizeof(*lines), PU_LEVEL, NULL); + mapthings = Z_Calloc(nummapthings * sizeof(*mapthings), PU_LEVEL, NULL); // Strict map data P_LoadRawVertexes(virtvertexes->data); @@ -2051,6 +2054,15 @@ static void P_LoadMapData(const virtres_t* virt) P_LoadRawLineDefs(virtlinedefs->data); P_SetupLines(); P_LoadRawSideDefs2(virtsidedefs->data); + + // Copy relevant map data for NetArchive purposes. + spawnsectors = Z_Calloc(numsectors * sizeof(*sectors), PU_LEVEL, NULL); + spawnlines = Z_Calloc(numlines * sizeof(*lines), PU_LEVEL, NULL); + spawnsides = Z_Calloc(numsides * sizeof(*sides), PU_LEVEL, NULL); + + memcpy(spawnsectors, sectors, numsectors * sizeof(*sectors)); + memcpy(spawnlines, lines, numlines * sizeof(*lines)); + memcpy(spawnsides, sides, numsides * sizeof(*sides)); } /** Sets up a sky texture to use for the level. @@ -2096,9 +2108,7 @@ static void P_LevelInitStuff(boolean reloadinggamestate) // special stage tokens, emeralds, and ring total tokenbits = 0; runemeraldmanager = false; - nummaprings = 0; - nummapboxes = 0; - numgotboxes = 0; + nummaprings = nummapboxes = numgotboxes = 0; // emerald hunt hunt1 = hunt2 = hunt3 = NULL; @@ -2108,6 +2118,7 @@ static void P_LevelInitStuff(boolean reloadinggamestate) countdowntimer = mapheaderinfo[gamemap-1]->countdown * TICRATE; else countdowntimer = 0; + countdowntimeup = false; // clear ctf pointers @@ -2124,8 +2135,6 @@ static void P_LevelInitStuff(boolean reloadinggamestate) // special stage stagefailed = false; - // Reset temporary record data - //memset(&ntemprecords, 0, sizeof(nightsdata_t)); // earthquake camera memset(&quake,0,sizeof(struct quake)); diff --git a/src/p_setup.h b/src/p_setup.h index 5d4a3b9da..6d76c05ab 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -63,6 +63,9 @@ INT32 P_CheckLevelFlat(const char *flatname); extern size_t nummapthings; extern mapthing_t *mapthings; +extern sector_t *spawnsectors; +extern line_t *spawnlines; +extern side_t *spawnsides; void P_SetupLevelSky(INT32 skynum, boolean global); boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate);