- use local variables for wall_index wherever possible.

This commit is contained in:
Christoph Oelckers 2022-11-15 14:15:46 +01:00
parent 34333302f9
commit 9a676ffba6
2 changed files with 17 additions and 13 deletions

View file

@ -755,11 +755,14 @@ void setWallSectors()
auto sect = &sector[i]; auto sect = &sector[i];
auto nextsect = &sector[i + 1]; auto nextsect = &sector[i + 1];
if (sect->wall_index() < nextsect->wall_index() && sect->wall_index() + sect->wall_count() > nextsect->wall_index()) int sectstart = sect->wall_index();
int nextsectstart = nextsect->wall_index();
if (sectstart < nextsectstart && sectstart + sect->wall_count() > nextsectstart)
{ {
// We have overlapping wall ranges for two sectors. Do some analysis to see where these walls belong // We have overlapping wall ranges for two sectors. Do some analysis to see where these walls belong
int checkstart = nextsect->wall_index(); int checkstart = nextsectstart;
int checkend = sect->wall_index() + sect->wall_count(); int checkend = sectstart + sect->wall_count();
// for now assign the walls to the first sector. Final decisions are made below. // for now assign the walls to the first sector. Final decisions are made below.
nextsect->wallnum -= checkend - checkstart; nextsect->wallnum -= checkend - checkstart;
@ -776,22 +779,22 @@ void setWallSectors()
} }
return refok && point2ok; return refok && point2ok;
}; };
while (checkstart < checkend && belongs(checkstart, sect->wall_index(), checkstart, checkstart)) while (checkstart < checkend && belongs(checkstart, sectstart, checkstart, checkstart))
checkstart++; checkstart++;
sect->wallnum = checkstart - sect->wall_index(); sect->wallnum = checkstart - sectstart;
while (checkstart < checkend && belongs(checkend - 1, checkend, nextsect->wall_index() + nextsect->wall_count(), checkstart)) while (checkstart < checkend && belongs(checkend - 1, checkend, nextsectstart + nextsect->wall_count(), checkstart))
checkend--; checkend--;
nextsect->wallnum += nextsect->wall_index() - checkend; nextsect->wallnum += nextsectstart - checkend;
nextsect->wallptr = checkend; nextsect->wallptr = nextsectstart = checkend;
if (nextsect->wall_index() > sect->wall_index() + sect->wall_count()) if (nextsectstart > sectstart + sect->wall_count())
{ {
// If there's a gap, assign to the first sector. In this case we may only guess. // 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->wall_index() + sect->wall_count(), nextsect->wall_index() - 1, i, i + 1); Printf("Wall range %d - %d referenced by sectors %d and %d\n", sectstart + sect->wall_count(), nextsectstart - 1, i, i + 1);
sect->wallnum = nextsect->wall_index() - sect->wall_index(); sect->wallnum = nextsectstart - sectstart;
} }
} }
} }

View file

@ -124,8 +124,9 @@ DEFINE_ACTION_FUNCTION(DLevelPostProcessor, SplitSector)
if (sectornum < sector.Size()) if (sectornum < sector.Size())
{ {
if (firstwall >= sector[sectornum].wall_index() && firstwall < sector[sectornum].wall_index() + sector[sectornum].wall_count() && int sectstart = sector[sectornum].wall_index();
secondwall >= sector[sectornum].wall_index() && secondwall < sector[sectornum].wall_index() + sector[sectornum].wall_count()) if (firstwall >= sectstart && firstwall < sectstart + sector[sectornum].wall_count() &&
secondwall >= sectstart && secondwall < sectstart + sector[sectornum].wall_count())
hw_SetSplitSector(sectornum, firstwall, secondwall); hw_SetSplitSector(sectornum, firstwall, secondwall);
} }