diff --git a/src/edata.cpp b/src/edata.cpp index d9a62707c..258c2a187 100644 --- a/src/edata.cpp +++ b/src/edata.cpp @@ -764,7 +764,7 @@ void ProcessEDSectors() { if (lines[i].special == Static_Init && lines[i].args[1] == Init_EDSector) { - sectorrecord[lines[i].frontsector - &level.sectors[0]] = lines[i].args[0]; + sectorrecord[lines[i].frontsector->Index()] = lines[i].args[0]; lines[i].special = 0; } } diff --git a/src/g_level.h b/src/g_level.h index c31e11d6f..5808df138 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -448,7 +448,6 @@ struct FLevelLocals bool IsFreelookAllowed() const; }; - struct cluster_info_t { int cluster; diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index bebdb3e8a..3fc022cf8 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -381,7 +381,7 @@ static void PrepareTransparentDoors(sector_t * sector) static void AddToVertex(const sector_t * sec, TArray & list) { - int secno = int(sec-&level.sectors[0]); + int secno = sec->Index(); for(unsigned i=0;iSector - &level.sectors[0]) * level.sectors.Size(); + int pnum = players[consoleplayer].camera->Sector->Index() * level.sectors.Size(); AActor *actor; TThinkerIterator iterator; @@ -360,7 +360,7 @@ void P_RunEffects () if (actor->effects) { // Only run the effect if the actor is potentially visible - int rnum = pnum + int(actor->Sector - &level.sectors[0]); + int rnum = pnum + actor->Sector->Index(); if (rejectmatrix == NULL || !(rejectmatrix[rnum>>3] & (1 << (rnum & 7)))) P_RunEffect (actor, actor->effects); } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 9ef5a6d55..3bdf3718d 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -3961,9 +3961,9 @@ void AActor::Tick () sector_t *sec = node->m_sector; DVector2 scrollv; - if (level.Scrolls.Size() > unsigned(sec-&level.sectors[0])) + if (level.Scrolls.Size() > unsigned(sec->Index())) { - scrollv = level.Scrolls[sec - &level.sectors[0]]; + scrollv = level.Scrolls[sec->Index()]; } else { diff --git a/src/p_pusher.cpp b/src/p_pusher.cpp index b0f18c0b5..8a4032b40 100644 --- a/src/p_pusher.cpp +++ b/src/p_pusher.cpp @@ -406,8 +406,7 @@ void P_SpawnPushers () if (thing->GetClass()->TypeName == NAME_PointPusher || thing->GetClass()->TypeName == NAME_PointPuller) { - new DPusher (DPusher::p_push, l->args[3] ? l : NULL, l->args[2], - 0, thing, int(thing->Sector - &level.sectors[0])); + new DPusher (DPusher::p_push, l->args[3] ? l : NULL, l->args[2], 0, thing, thing->Sector->Index()); } } } diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index d2e8efa3e..954b1ac36 100644 --- a/src/p_scroll.cpp +++ b/src/p_scroll.cpp @@ -441,7 +441,7 @@ void P_SpawnScrollers(void) { // if 1, then displacement // if 2, then accelerative (also if 3) - control = int(l->sidedef[0]->sector - &level.sectors[0]); + control = l->sidedef[0]->sector->Index(); if (l->args[1] & 2) accel = 1; } @@ -478,7 +478,7 @@ void P_SpawnScrollers(void) if (line->args[0] == l->args[0] && (line->args[1] & 1)) { - new DScroller(EScroll::sc_ceiling, -dx, dy, control, int(line->frontsector - &level.sectors[0]), accel); + new DScroller(EScroll::sc_ceiling, -dx, dy, control, line->frontsector->Index(), accel); } } break; @@ -498,7 +498,7 @@ void P_SpawnScrollers(void) if (line->args[0] == l->args[0] && (line->args[1] & 2)) { - new DScroller(EScroll::sc_floor, -dx, dy, control, int(line->frontsector - &level.sectors[0]), accel); + new DScroller(EScroll::sc_floor, -dx, dy, control, line->frontsector->Index(), accel); } } } @@ -516,7 +516,7 @@ void P_SpawnScrollers(void) if (line->args[0] == l->args[0] && (line->args[1] & 4)) { - new DScroller (EScroll::sc_carry, dx, dy, control, int(line->frontsector-&level.sectors[0]), accel); + new DScroller (EScroll::sc_carry, dx, dy, control, line->frontsector->Index(), accel); } } } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 963f14945..e03b7ac23 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -3179,11 +3179,11 @@ static void P_GroupLines (bool buildmap) auto li = &lines[i]; if (li->frontsector != NULL) { - li->frontsector->Lines[linesDoneInEachSector[li->frontsector - &level.sectors[0]]++] = li; + li->frontsector->Lines[linesDoneInEachSector[li->frontsector->Index()]++] = li; } if (li->backsector != NULL && li->backsector != li->frontsector) { - li->backsector->Lines[linesDoneInEachSector[li->backsector - &level.sectors[0]]++] = li; + li->backsector->Lines[linesDoneInEachSector[li->backsector->Index()]++] = li; } } diff --git a/src/p_sight.cpp b/src/p_sight.cpp index bb3dbdd68..eb62e505a 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -821,7 +821,7 @@ bool P_CheckSight (AActor *t1, AActor *t2, int flags) const sector_t *s1 = t1->Sector; const sector_t *s2 = t2->Sector; - int pnum = int(s1 - &level.sectors[0]) * level.sectors.Size() + int(s2 - &level.sectors[0]); + int pnum = int(s1->Index()) * level.sectors.Size() + int(s2->Index()); // // check for trivial rejection diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 0f098f36b..b3cf9c597 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -433,7 +433,7 @@ void P_PlayerInSpecialSector (player_t *player, sector_t * sector) if (sector->isSecret()) { sector->ClearSecret(); - P_GiveSecret(player->mo, true, true, int(sector - &level.sectors[0])); + P_GiveSecret(player->mo, true, true, sector->Index()); } } @@ -1157,7 +1157,7 @@ void P_InitSectorSpecial(sector_t *sector, int special) case dScroll_EastLavaDamage: P_SetupSectorDamage(sector, 5, 32, 256, NAME_Fire, SECF_DMGTERRAINFX); - P_CreateScroller(EScroll::sc_floor, -4., 0, -1, int(sector - &level.sectors[0]), 0); + P_CreateScroller(EScroll::sc_floor, -4., 0, -1, sector->Index(), 0); keepspecial = true; break; @@ -1215,14 +1215,14 @@ void P_InitSectorSpecial(sector_t *sector, int special) int i = sector->special - Scroll_North_Slow; double dx = hexenScrollies[i][0] / 2.; double dy = hexenScrollies[i][1] / 2.; - P_CreateScroller(EScroll::sc_floor, dx, dy, -1, int(sector-&level.sectors[0]), 0); + P_CreateScroller(EScroll::sc_floor, dx, dy, -1, sector->Index(), 0); } else if (sector->special >= Carry_East5 && sector->special <= Carry_East35) { // Heretic scroll special // Only east scrollers also scroll the texture P_CreateScroller(EScroll::sc_floor, - -0.5 * (1 << ((sector->special & 0xff) - Carry_East5)), 0, -1, int(sector-&level.sectors[0]), 0); + -0.5 * (1 << ((sector->special & 0xff) - Carry_East5)), 0, -1, sector->Index(), 0); } keepspecial = true; break; diff --git a/src/p_tags.cpp b/src/p_tags.cpp index cb6a405e8..dc71e2663 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -45,11 +45,6 @@ FTagManager tagManager; // //----------------------------------------------------------------------------- -static inline int sectindex(const sector_t *sector) -{ - return (int)(intptr_t)(sector - &level.sectors[0]); -} - static inline int lineindex(const line_t *line) { return (int)(intptr_t)(line - lines); @@ -194,7 +189,7 @@ void FTagManager::HashTags() bool FTagManager::SectorHasTags(const sector_t *sector) const { - int i = sectindex(sector); + int i = sector->Index(); return SectorHasTags(i); } @@ -206,7 +201,7 @@ bool FTagManager::SectorHasTags(const sector_t *sector) const int FTagManager::GetFirstSectorTag(const sector_t *sect) const { - int i = sectindex(sect); + int i = sect->Index(); return SectorHasTags(i) ? allTags[startForSector[i]].tag : 0; } @@ -238,7 +233,7 @@ bool FTagManager::SectorHasTag(int i, int tag) const bool FTagManager::SectorHasTag(const sector_t *sector, int tag) const { - return SectorHasTag(sectindex(sector), tag); + return SectorHasTag(sector->Index(), tag); } //----------------------------------------------------------------------------- diff --git a/src/p_tags.h b/src/p_tags.h index 9649ace1a..17719de6f 100644 --- a/src/p_tags.h +++ b/src/p_tags.h @@ -90,7 +90,7 @@ public: if (tag == 0) { searchtag = INT_MIN; - start = (line == NULL || line->backsector == NULL)? -1 : (int)(line->backsector - &level.sectors[0]); + start = (line == NULL || line->backsector == NULL)? -1 : line->backsector->Index(); } else { diff --git a/src/r_defs.h b/src/r_defs.h index 4b820a3a0..70816838c 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -23,7 +23,6 @@ #ifndef __R_DEFS_H__ #define __R_DEFS_H__ -#include #include "doomdef.h" #include "templates.h" #include "memarena.h" @@ -660,6 +659,7 @@ public: double FindLowestCeilingPoint(vertex_t **v) const; double FindHighestFloorPoint(vertex_t **v) const; void RemoveForceField(); + int Index() const { return int(this - &level.sectors[0]); } void AdjustFloorClip () const; void SetColor(int r, int g, int b, int desat);