From deae234afa19687879004ce6397135b8b1955f64 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 17 Jul 2024 12:21:05 +0200 Subject: [PATCH] Revert "clean up mapload code a little more" This reverts commit 79a5d174a54ea0bbabba485d83e7d9f21372f4a2. --- src/p_setup.c | 74 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 2b4799c5f..e5f947a87 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -496,7 +496,6 @@ FUNCINLINE static ATTRINLINE void P_LoadRawSubsectors(void *data) size_t numlevelflats; levelflat_t *levelflats; -levelflat_t *foundflats; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) @@ -622,8 +621,18 @@ static void P_LoadRawSectors(UINT8 *data) { mapsector_t *ms = (mapsector_t *)data; sector_t *ss = sectors; + levelflat_t *foundflats; + size_t i; + // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. + //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty + foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); + if (foundflats == NULL) + I_Error("Ran out of memory while loading sectors\n"); + + numlevelflats = 0; + // For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss. for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -684,6 +693,16 @@ static void P_LoadRawSectors(UINT8 *data) ss->floorspeed = 0; ss->ceilspeed = 0; } + + // set the sky flat num + skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); + + // copy table for global usage + levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); + free(foundflats); + + // search for animated flats and set up + P_SetupLevelFlatAnims(); } // @@ -1470,7 +1489,7 @@ static void P_LoadRawSideDefs2(void *data) // always process if back sidedef, because we need that - symbol sd->text = Z_Malloc(7, PU_LEVEL, NULL); - if (i == 1 || !(msd->toptexture[0] == '-' || msd->toptexture[1] == '\0')) + if (i == 1 || msd->toptexture[0] != '-' || msd->toptexture[1] != '\0') { M_Memcpy(process,msd->toptexture,8); process[8] = '\0'; @@ -1559,6 +1578,7 @@ static void P_LoadRawSideDefs2(void *data) break; } } + R_ClearTextureNumCache(true); } static boolean LineInBlock(fixed_t cx1, fixed_t cy1, fixed_t cx2, fixed_t cy2, fixed_t bx1, fixed_t by1) @@ -2075,33 +2095,12 @@ static void P_LoadMapData(const virtres_t* virt) lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL); mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL); - // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. - //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty - foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); - if (foundflats == NULL) - I_Error("Ran out of memory while loading sectors\n"); - - numlevelflats = 0; - // Strict map data P_LoadRawVertexes(virtvertexes->data); P_LoadRawSectors(virtsectors->data); P_LoadRawLineDefs(virtlinedefs->data); P_SetupLines(); P_LoadRawSideDefs2(virtsidedefs->data); - P_PrepareRawThings(virtthings->data); - - R_ClearTextureNumCache(true); - - // set the sky flat num - skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); - - // copy table for global usage - levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); - free(foundflats); - - // search for animated flats and set up - P_SetupLevelFlatAnims(); } /** Sets up a sky texture to use for the level. @@ -2260,6 +2259,9 @@ void P_LoadThingsOnly(void) mobj_t *mo; thinker_t *think; + virtres_t* virt = vres_GetMap(lastloadedmaplumpnum); + virtlump_t* vth = vres_Find(virt, "THINGS"); + for (think = thinkercap.next; think != &thinkercap; think = think->next) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) @@ -2273,8 +2275,11 @@ void P_LoadThingsOnly(void) P_LevelInitStuff(); + P_PrepareRawThings(vth->data); P_LoadThings(); + vres_Free(virt); + P_SpawnSecretItems(true); } @@ -2342,6 +2347,8 @@ static void P_LoadMapFromFile(void) P_LoadLineDefs2(); P_GroupLines(); + P_PrepareRawThings(vres_Find(virt, "THINGS")->data); + P_MakeMapMD5(virt, &mapmd5); vres_Free(virt); @@ -2550,7 +2557,28 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) static boolean P_CanSave(void) { +#if 0 + // Saving is completely ignored under these conditions: + if ((cursaveslot < 0) // Playing without saving + || (modifiedgame && !savemoddata) // Game is modified + || (netgame || multiplayer) // Not in single-player + || (demo.playback || demo.recording || metalrecording) // Currently in demo + || (players[consoleplayer].lives <= 0) // Completely dead + || (modeattacking || ultimatemode || G_IsSpecialStage(gamemap))) // Specialized instances + return false; + + if (mapheaderinfo[gamemap-1]->saveoverride == SAVE_ALWAYS) + return true; // Saving should ALWAYS happen! + else if (mapheaderinfo[gamemap-1]->saveoverride == SAVE_NEVER) + return false; // Saving should NEVER happen! + + // Default condition: In a non-hidden map, at the beginning of a zone or on a completed save-file, and not on save reload. + return (!(mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) + && (mapheaderinfo[gamemap-1]->actnum < 2 || gamecomplete) + && (gamemap != lastmapsaved)); +#else return false; // SRB2Kart: no SP, no saving. +#endif } /** Loads a level from a lump or external wad.