From 34333302f9937c499c367dbf1969bde987529681 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 15 Nov 2022 12:37:14 +0100 Subject: [PATCH] - wrapped all reading wallptr references. --- source/core/maploader.cpp | 22 +++++++++++----------- source/core/maptypes.h | 1 + source/core/postprocessor.cpp | 4 ++-- source/core/rendering/hw_sections.cpp | 2 +- source/games/duke/src/gameexec.cpp | 2 +- source/games/exhumed/src/player.cpp | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 0f13145ef..cfdbdbd09 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -421,7 +421,7 @@ void fixSectors() { for(auto& sect: sector) { - // Fix maps which do not set their wallptr to the first wall of the sector. Lo Wang In Time's map 11 is such a case. + // Fix maps which do not set their wall index to the first wall of the sector. Lo Wang In Time's map 11 is such a case. auto wp = sect.firstWall(); // Note: we do not have the 'sector' index initialized here, it would not be helpful anyway for this fix. while (wp != wall.Data() && wp[-1].twoSided() && wp[-1].nextWall()->nextWall() == &wp[-1] && wp[-1].nextWall()->nextSector() == §) @@ -755,11 +755,11 @@ void setWallSectors() auto sect = §or[i]; auto nextsect = §or[i + 1]; - if (sect->wallptr < nextsect->wallptr && sect->wallptr + sect->wall_count() > nextsect->wallptr) + if (sect->wall_index() < nextsect->wall_index() && sect->wall_index() + sect->wall_count() > nextsect->wall_index()) { // We have overlapping wall ranges for two sectors. Do some analysis to see where these walls belong - int checkstart = nextsect->wallptr; - int checkend = sect->wallptr + sect->wall_count(); + int checkstart = nextsect->wall_index(); + int checkend = sect->wall_index() + sect->wall_count(); // for now assign the walls to the first sector. Final decisions are made below. nextsect->wallnum -= checkend - checkstart; @@ -776,22 +776,22 @@ void setWallSectors() } return refok && point2ok; }; - while (checkstart < checkend && belongs(checkstart, sect->wallptr, checkstart, checkstart)) + while (checkstart < checkend && belongs(checkstart, sect->wall_index(), checkstart, checkstart)) checkstart++; - sect->wallnum = checkstart - sect->wallptr; + sect->wallnum = checkstart - sect->wall_index(); - while (checkstart < checkend && belongs(checkend - 1, checkend, nextsect->wallptr + nextsect->wall_count(), checkstart)) + while (checkstart < checkend && belongs(checkend - 1, checkend, nextsect->wall_index() + nextsect->wall_count(), checkstart)) checkend--; - nextsect->wallnum += nextsect->wallptr - checkend; + nextsect->wallnum += nextsect->wall_index() - checkend; nextsect->wallptr = checkend; - if (nextsect->wallptr > sect->wallptr + sect->wall_count()) + if (nextsect->wall_index() > sect->wall_index() + sect->wall_count()) { // If there's a gap, assign to the first sector. In this case we may only guess. - Printf("Wall range %d - %d referenced by sectors %d and %d\n", sect->wallptr + sect->wall_count(), nextsect->wallptr - 1, i, i + 1); - sect->wallnum = nextsect->wallptr - sect->wallptr; + Printf("Wall range %d - %d referenced by sectors %d and %d\n", sect->wall_index() + sect->wall_count(), nextsect->wall_index() - 1, i, i + 1); + sect->wallnum = nextsect->wall_index() - sect->wall_index(); } } } diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 26c13f821..186c2d551 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -350,6 +350,7 @@ struct sectortype int getceilingslope() const { return ceilingstat & CSTAT_SECTOR_SLOPE ? ceilingheinum : 0; } walltype* firstWall() const; walltype* lastWall() const; + int wall_index() const { return wallptr; } int wall_count() const { return wallnum; } diff --git a/source/core/postprocessor.cpp b/source/core/postprocessor.cpp index 46bcd7eeb..b890b02fb 100644 --- a/source/core/postprocessor.cpp +++ b/source/core/postprocessor.cpp @@ -124,8 +124,8 @@ DEFINE_ACTION_FUNCTION(DLevelPostProcessor, SplitSector) if (sectornum < sector.Size()) { - if (firstwall >= sector[sectornum].wallptr && firstwall < sector[sectornum].wallptr + sector[sectornum].wall_count() && - secondwall >= sector[sectornum].wallptr && secondwall < sector[sectornum].wallptr + sector[sectornum].wall_count()) + if (firstwall >= sector[sectornum].wall_index() && firstwall < sector[sectornum].wall_index() + sector[sectornum].wall_count() && + secondwall >= sector[sectornum].wall_index() && secondwall < sector[sectornum].wall_index() + sector[sectornum].wall_count()) hw_SetSplitSector(sectornum, firstwall, secondwall); } diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index 259fa9fb0..41e017fed 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -223,7 +223,7 @@ static void CollectLoops(TArray& sectors) int count = 0; for (unsigned i = 0; i < sector.Size(); i++) { - int first = sector[i].wallptr; + int first = sector[i].wall_index(); int last = first + sector[i].wall_count(); sectors.Reserve(1); sectors.Last().bugged = 0; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index a432eae5d..4a74de48d 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1052,7 +1052,7 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, switch (lLabelID) { case SECTOR_WALLPTR: - if (!bSet) SetGameVarID(lVar2, sectp->wallptr, sActor, sPlayer); + if (!bSet) SetGameVarID(lVar2, sectp->wall_index(), sActor, sPlayer); break; case SECTOR_WALLNUM: if (!bSet) SetGameVarID(lVar2, sectp->wall_count(), sActor, sPlayer); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 196dd3f6a..56521d646 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -128,7 +128,7 @@ void feebtag(const DVector3& pos, sectortype* pSector, DExhumedActor **nSprite, { *nSprite = nullptr; - int startwall = pSector->wallptr; + int startwall = pSector->wall_index(); int nWalls = pSector->wall_count();