From ac2a3c443f06d16cfba096efd65db32e9c6b7959 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Sep 2022 18:27:02 +0200 Subject: [PATCH] - got rid of all deprecated updatesector variants. This required a few changes in the map loader and render interface. --- source/build/src/clip.cpp | 14 +++++--------- source/core/maploader.cpp | 22 ++++++++++++---------- source/core/maptypes.h | 4 ++-- source/core/rendering/hw_entrypoint.cpp | 8 ++++---- source/core/rendering/render.h | 2 +- source/core/updatesector.h | 6 ------ source/games/blood/src/blood.cpp | 4 +--- source/games/blood/src/db.cpp | 8 ++++---- source/games/blood/src/db.h | 2 +- source/games/blood/src/view.cpp | 2 +- source/games/duke/src/premap.cpp | 4 ++-- source/games/duke/src/render.cpp | 2 +- source/games/exhumed/src/init.cpp | 4 ++-- source/games/exhumed/src/view.cpp | 2 +- source/games/sw/src/draw.cpp | 2 +- source/games/sw/src/game.cpp | 4 ++-- 16 files changed, 40 insertions(+), 50 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index dd8a4ad4a..7a9ac89a9 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -295,14 +295,6 @@ static int32_t getwalldist(vec2_t const in, int const wallnum) static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist) { -#if 0 - if (enginecompatibility_mode != ENGINECOMPATIBILITY_NONE) - { - updatesector(pos.x, pos.y, sectnum); - return; - } -#endif - if (inside_p(pos.X, pos.Y, *sectnum)) return; @@ -722,7 +714,11 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, if ((tempint ^ tempint2) < 0) { if (enginecompatibility_mode == ENGINECOMPATIBILITY_19961112) - updatesector(pos->X, pos->Y, sectnum); + { + auto sectp = §or[*sectnum]; + updatesector(DVector2(pos->X * inttoworld, pos->Y * inttoworld), §p); + *sectnum = sectp ? ::sectnum(sectp) : -1; + } return clipReturn; } } diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index da7ed7118..c391ff58c 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -432,29 +432,29 @@ void fixSectors() } } -void validateStartSector(const char* filename, const DVector3& pos, int* cursectnum, unsigned numsectors, bool noabort) +void validateStartSector(const char* filename, const DVector3& pos, sectortype** cursect, unsigned numsectors, bool noabort) { - if ((unsigned)(*cursectnum) >= numsectors) + if (*cursect == nullptr) { sectortype* sect = nullptr; updatesectorz(pos, §); if (!sect) updatesector(pos, §); if (sect || noabort) { - Printf(PRINT_HIGH, "Error in map %s: Start sector %d out of range. Max. sector is %d\n", filename, *cursectnum, numsectors); - *cursectnum = sect? sectnum(sect) : 0; + Printf(PRINT_HIGH, "Error in map %s: Start sector %d out of range. Max. sector is %d\n", filename, sectnum(*cursect), numsectors); + *cursect = sect? sect : §or[0]; } else { - I_Error("Unable to start map %s: Start sector %d out of range. Max. sector is %d. No valid location at start spot\n", filename, *cursectnum, numsectors); + I_Error("Unable to start map %s: Start sector %d out of range. Max. sector is %d. No valid location at start spot\n", filename, sectnum(*cursect), numsectors); } } } -void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites) +void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, sectortype** cursect, SpawnSpriteDef& sprites) { inputState.ClearAllInput(); @@ -470,7 +470,8 @@ void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, int* pos->Y = fr.ReadInt32() * maptoworld; pos->Z = fr.ReadInt32() * zmaptoworld; *ang = fr.ReadInt16() & 2047; - *cursectnum = fr.ReadUInt16(); + + int cursectnum = fr.ReadUInt16(); // Get the basics out before loading the data so that we can set up the global storage. unsigned numsectors = fr.ReadUInt16(); @@ -533,7 +534,8 @@ void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, int* //Must be last. fixSectors(); - updatesector(*pos, cursectnum); + *cursect = validSectorIndex(cursectnum) ? §or[cursectnum] : nullptr; + updatesector(*pos, cursect); guniqhudid = 0; fr.Seek(0, FileReader::SeekSet); auto buffer = fr.Read(); @@ -547,7 +549,7 @@ void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, int* wallbackup = wall; sectorbackup = sector; - validateStartSector(filename, *pos, cursectnum, numsectors); + validateStartSector(filename, *pos, cursect, numsectors); } @@ -725,7 +727,7 @@ void loadMapBackup(const char* filename) { DVector3 fpos; int16_t scratch; - int scratch2; + sectortype* scratch2; SpawnSpriteDef scratch3; if (isBlood()) diff --git a/source/core/maptypes.h b/source/core/maptypes.h index b3c82c050..c0c320179 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -722,11 +722,11 @@ struct SpawnSpriteDef; void allocateMapArrays(int numwall, int numsector, int numsprites); void validateSprite(spritetype& spr, int secno, int index); void fixSectors(); -void loadMap(const char *filename, int flags, DVector3 *pos, int16_t *ang, int *cursectnum, SpawnSpriteDef& sprites); +void loadMap(const char *filename, int flags, DVector3 *pos, int16_t *ang, sectortype** cursect, SpawnSpriteDef& sprites); TArray loadMapWalls(const char* filename); void loadMapBackup(const char* filename); void loadMapHack(const char* filename, const uint8_t*, SpawnSpriteDef& sprites); -void validateStartSector(const char* filename, const DVector3& pos, int* cursectnum, unsigned numsectors, bool noabort = false); +void validateStartSector(const char* filename, const DVector3& pos, sectortype** cursectnum, unsigned numsectors, bool noabort = false); // should only be used to read angles from map-loaded data (for proper documentation) constexpr DAngle mapangle(int mapang) diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index f41a25754..f3ebd8dac 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -305,12 +305,12 @@ static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime) void animatecamsprite(double s); -void render_drawrooms(DCoreActor* playersprite, const DVector3& position, int sectnum, DAngle angle, fixedhoriz horizon, DAngle rollang, double interpfrac, float fov) +void render_drawrooms(DCoreActor* playersprite, const DVector3& position, sectortype* sect, DAngle angle, fixedhoriz horizon, DAngle rollang, double interpfrac, float fov) { checkRotatedWalls(); - updatesector(position, §num); - if (sectnum < 0) return; + updatesector(position.XY(), §); + if (sectnum == nullptr) return; iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; checkBenchActive(); @@ -319,7 +319,7 @@ void render_drawrooms(DCoreActor* playersprite, const DVector3& position, int se ResetProfilingData(); // Get this before everything else - FRenderViewpoint r_viewpoint = SetupViewpoint(playersprite, position, sectnum, angle, horizon, rollang, fov); + FRenderViewpoint r_viewpoint = SetupViewpoint(playersprite, position, sectnum(sect), angle, horizon, rollang, fov); r_viewpoint.TicFrac = !cl_capfps ? interpfrac : 1.; screen->mLights->Clear(); diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h index ba43b0b16..2706040c8 100644 --- a/source/core/rendering/render.h +++ b/source/core/rendering/render.h @@ -5,7 +5,7 @@ class FSerializer; struct IntRect; -void render_drawrooms(DCoreActor* playersprite, const DVector3& position, int sectnum, DAngle angle, fixedhoriz horizon, DAngle rollang, double interpfrac, float fov = -1); +void render_drawrooms(DCoreActor* playersprite, const DVector3& position, sectortype* sectnum, DAngle angle, fixedhoriz horizon, DAngle rollang, double interpfrac, float fov = -1); void render_camtex(DCoreActor* playersprite, const DVector3& position, sectortype* sect, DAngle angle, fixedhoriz horizon, DAngle rollang, FGameTexture* camtex, IntRect& rect, double interpfrac); struct PortalDesc diff --git a/source/core/updatesector.h b/source/core/updatesector.h index 3485c8844..2d750cb24 100644 --- a/source/core/updatesector.h +++ b/source/core/updatesector.h @@ -95,12 +95,6 @@ inline void updatesector(const DVector2& pos, sectortype** const sectp) } -// This is still needed for map startup. -inline void updatesector(const DVector3& pos, int* sectno) -{ - DoUpdateSector(pos.X, pos.Y, pos.Z, sectno, MAXUPDATESECTORDIST, inside0); -} - inline void updatesectorz(const DVector3& pos, sectortype** const sectp) { int sectno = *sectp ? sector.IndexOf(*sectp) : -1; diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 7723b51bf..ede339eca 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -251,10 +251,8 @@ void StartLevel(MapRecord* level, bool newgame) #endif //drawLoadingScreen(); BloodSpawnSpriteDef sprites; - int startsectno; DVector3 startpos; - dbLoadMap(currentLevel->fileName, startpos, &startang, &startsectno, nullptr, sprites); - startsector = §or[startsectno]; + dbLoadMap(currentLevel->fileName, startpos, &startang, &startsector, nullptr, sprites); SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); STAT_NewLevel(currentLevel->fileName); TITLE_InformName(currentLevel->name); diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 5654e9570..85faf224c 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -130,7 +130,7 @@ unsigned int dbReadMapCRC(const char* pPath) // //--------------------------------------------------------------------------- -void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* cursectnum, unsigned int* pCRC, BloodSpawnSpriteDef& sprites) +void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, sectortype** cursect, unsigned int* pCRC, BloodSpawnSpriteDef& sprites) { const int nXSectorSize = 60; const int nXSpriteSize = 56; @@ -216,7 +216,7 @@ void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* cursectnum, } gMapRev = mapHeader.revision; allocateMapArrays(mapHeader.numwalls, mapHeader.numsectors, mapHeader.numsprites); - *cursectnum = mapHeader.sect; + *cursect = validSectorIndex(mapHeader.sect)? §or[mapHeader.sect] : nullptr; if (encrypted) { @@ -664,7 +664,7 @@ void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* cursectnum, sectionGeometry.SetSize(sections.Size()); wallbackup = wall; sectorbackup = sector; - validateStartSector(mapname.GetChars(), pos, cursectnum, mapHeader.numsectors, true); + validateStartSector(mapname.GetChars(), pos, cursect, mapHeader.numsectors, true); } @@ -679,6 +679,6 @@ END_BLD_NS void qloadboard(const char* filename, uint8_t flags, DVector3* dapos, int16_t* daang) { Blood::BloodSpawnSpriteDef sprites; - int sp; + sectortype* sp; Blood::dbLoadMap(filename, *dapos, daang, &sp, nullptr, sprites); } diff --git a/source/games/blood/src/db.h b/source/games/blood/src/db.h index 8856871dd..2810989aa 100644 --- a/source/games/blood/src/db.h +++ b/source/games/blood/src/db.h @@ -101,7 +101,7 @@ DBloodActor* InsertSprite(sectortype* pSector, int nStat); int DeleteSprite(DBloodActor* actor); unsigned int dbReadMapCRC(const char* pPath); -void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* pSector, unsigned int* pCRC, BloodSpawnSpriteDef& sprites); +void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, sectortype** pSector, unsigned int* pCRC, BloodSpawnSpriteDef& sprites); END_BLD_NS diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 54b3ed46d..27fefc64f 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -739,7 +739,7 @@ void viewDrawScreen(bool sceneonly) fixedhoriz deliriumPitchI = interpolatedvalue(q16horiz(deliriumPitchO), q16horiz(deliriumPitch), interpfrac); auto bakCstat = pPlayer->actor->spr.cstat; pPlayer->actor->spr.cstat |= (gViewPos == 0) ? CSTAT_SPRITE_INVISIBLE : CSTAT_SPRITE_TRANSLUCENT | CSTAT_SPRITE_TRANS_FLIP; - render_drawrooms(pPlayer->actor, cPos, sectnum(pSector), cA, cH + deliriumPitchI, rotscrnang, interpfrac); + render_drawrooms(pPlayer->actor, cPos, pSector, cA, cH + deliriumPitchI, rotscrnang, interpfrac); pPlayer->actor->spr.cstat = bakCstat; bDeliriumOld = bDelirium && gDeliriumBlur; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 66aca1671..36611c2f1 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -994,12 +994,12 @@ static int LoadTheMap(MapRecord *mi, player_struct*p, int gamemode) } currentLevel = mi; - int sect; + sectortype* sect; SpawnSpriteDef sprites; DVector3 pos; loadMap(mi->fileName, isShareware(), &pos, &lbang, §, sprites); p->pos = pos; - p->cursector = §or[sect]; + p->cursector = sect; SECRET_SetMapName(mi->DisplayName(), mi->name); STAT_NewLevel(mi->fileName); diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index febe91b2e..b0c60c8d1 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -364,7 +364,7 @@ void displayrooms(int snum, double interpfrac, bool sceneonly) auto cstat = viewer->spr.cstat; if (camview) viewer->spr.cstat = CSTAT_SPRITE_INVISIBLE; if (!sceneonly) drawweapon(interpfrac); - render_drawrooms(viewer, cpos, sectnum(sect), cang, choriz, rotscrnang, interpfrac, fov); + render_drawrooms(viewer, cpos, sect, cang, choriz, rotscrnang, interpfrac, fov); viewer->spr.cstat = cstat; //GLInterface.SetMapFog(false); diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 29b85f8df..6a1868163 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -143,12 +143,12 @@ uint8_t LoadLevel(MapRecord* map) nStopSound = 66; } - int initsect; + sectortype* initsect; SpawnSpriteDef spawned; int16_t mapang; loadMap(currentLevel->fileName, 0, &initpos, &mapang, &initsect, spawned); inita = DAngle::fromBuild(mapang); - initsectp = §or[initsect]; + initsectp = initsect; auto actors = spawnactors(spawned); int i; diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index dd472ac89..ab9995fd9 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -316,7 +316,7 @@ void DrawView(double interpfrac, bool sceneonly) if (!nFreeze && !sceneonly) DrawWeapons(interpfrac); - render_drawrooms(nullptr, nCamerapos, sectnum(pSector), nCameraang, nCamerapan, rotscrnang, interpfrac); + render_drawrooms(nullptr, nCamerapos, pSector, nCameraang, nCamerapan, rotscrnang, interpfrac); if (HavePLURemap()) { diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index d8076924e..ddc9495a0 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1324,7 +1324,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly) UpdatePanel(interpfrac); UpdateWallPortalState(); - render_drawrooms(pp->actor, tpos, sectnum(tsect), tang, thoriz, trotscrnang, interpfrac); + render_drawrooms(pp->actor, tpos, tsect, tang, thoriz, trotscrnang, interpfrac); RestorePortalState(); if (sceneonly) diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index c9d04005d..b9a367a23 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -404,13 +404,13 @@ void InitLevel(MapRecord *maprec) int16_t ang; currentLevel = maprec; - int cursect; + sectortype* cursect; SpawnSpriteDef sprites; DVector3 ppos; loadMap(maprec->fileName, SW_SHAREWARE ? 1 : 0, &ppos, &ang, &cursect, sprites); Player[0].pos = ppos; spawnactors(sprites); - Player[0].cursector = §or[cursect]; + Player[0].cursector = cursect; SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); STAT_NewLevel(currentLevel->fileName);