From 238046655c13329a150d65e27d344bf93f38792c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 31 Mar 2015 17:09:19 +0200 Subject: [PATCH] - wrapped all accesses to the sector tag into accessor functions, as preparation for allowing multiple tags per sector. --- src/compatibility.cpp | 2 +- src/fragglescript/t_func.cpp | 18 ++++-------------- src/g_strife/a_strifestuff.cpp | 2 +- src/p_acs.cpp | 4 ++-- src/p_floor.cpp | 2 +- src/p_lights.cpp | 2 +- src/p_linkedsectors.cpp | 2 +- src/p_lnspec.cpp | 6 +++--- src/p_mobj.cpp | 2 +- src/p_sectors.cpp | 30 ++++++++++++++++++++++++++++++ src/p_setup.cpp | 20 ++++++-------------- src/p_teleport.cpp | 4 ++-- src/p_udmf.cpp | 2 +- src/p_writemap.cpp | 2 +- src/p_xlat.cpp | 2 +- src/r_defs.h | 5 +++++ 16 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/compatibility.cpp b/src/compatibility.cpp index fd309ec8be..ff3a67e613 100644 --- a/src/compatibility.cpp +++ b/src/compatibility.cpp @@ -551,7 +551,7 @@ void SetCompatibilityParams() { if ((unsigned)CompatParams[i + 1] < (unsigned)numsectors) { - sectors[CompatParams[i + 1]].tag = CompatParams[i + 2]; + sectors[CompatParams[i + 1]].SetTag(CompatParams[i + 2]); } i += 3; break; diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 0bddcd7fd6..0359aa4230 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -1158,7 +1158,7 @@ void FParser::SF_ObjSector(void) } t_return.type = svt_int; - t_return.value.i = mo ? mo->Sector->tag : 0; // nullptr check + t_return.value.i = mo ? mo->Sector->GetTag() : 0; // nullptr check } //========================================================================== @@ -4291,7 +4291,7 @@ void FParser::SF_KillInSector() while ((mo=it.Next())) { - if (mo->flags3&MF3_ISMONSTER && mo->Sector->tag==tag) P_DamageMobj(mo, NULL, NULL, 1000000, NAME_Massacre); + if (mo->flags3&MF3_ISMONSTER && mo->Sector->HasTag(tag)) P_DamageMobj(mo, NULL, NULL, 1000000, NAME_Massacre); } } } @@ -4388,19 +4388,9 @@ void FParser::SF_ChangeTag() { for (int secnum = -1; (secnum = P_FindSectorFromTag (t_argv[0].value.i, secnum)) >= 0; ) { - sectors[secnum].tag=t_argv[1].value.i; - } - - // Recreate the hash tables - int i; - - for (i=numsectors; --i>=0; ) sectors[i].firsttag = -1; - for (i=numsectors; --i>=0; ) - { - int j = (unsigned) sectors[i].tag % (unsigned) numsectors; - sectors[i].nexttag = sectors[j].firsttag; - sectors[j].firsttag = i; + sectors[secnum].SetTag(t_argv[1].value.i); } + sector_t::HashTags(); } } diff --git a/src/g_strife/a_strifestuff.cpp b/src/g_strife/a_strifestuff.cpp index 95b0030a09..e8dff183fa 100644 --- a/src/g_strife/a_strifestuff.cpp +++ b/src/g_strife/a_strifestuff.cpp @@ -636,7 +636,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CheckTerrain) } else if ((sec->special & 0xFF) == Scroll_StrifeCurrent) { - int anglespeed = sec->tag - 100; + int anglespeed = sec->GetTag() - 100; fixed_t speed = (anglespeed % 10) << (FRACBITS - 4); angle_t finean = (anglespeed / 10) << (32-3); finean >>= ANGLETOFINESHIFT; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 5556507b78..3dd0cfef0d 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -3211,7 +3211,7 @@ do_count: if (actor->health > 0 && (kind == NULL || actor->IsA (kind))) { - if (actor->Sector->tag == tag || tag == -1) + if (actor->Sector->HasTag(tag) || tag == -1) { // Don't count items in somebody's inventory if (!actor->IsKindOf (RUNTIME_CLASS(AInventory)) || @@ -3231,7 +3231,7 @@ do_count: if (actor->health > 0 && (kind == NULL || actor->IsA (kind))) { - if (actor->Sector->tag == tag || tag == -1) + if (actor->Sector->HasTag(tag) || tag == -1) { // Don't count items in somebody's inventory if (!actor->IsKindOf (RUNTIME_CLASS(AInventory)) || diff --git a/src/p_floor.cpp b/src/p_floor.cpp index 9a5a6eaf82..231ccd5a36 100644 --- a/src/p_floor.cpp +++ b/src/p_floor.cpp @@ -572,7 +572,7 @@ static int P_FindSectorFromTagLinear (int tag, int start) { for (int i=start+1;iGetSector()->tag == tag) + if (effect->GetSector()->HasTag(tag)) { effect->Destroy(); } diff --git a/src/p_linkedsectors.cpp b/src/p_linkedsectors.cpp index 2d06bc0431..acf1d69066 100644 --- a/src/p_linkedsectors.cpp +++ b/src/p_linkedsectors.cpp @@ -278,7 +278,7 @@ static void RemoveTaggedSectors(extsector_t::linked::plane &scrollplane, int tag { for(int i = scrollplane.Sectors.Size()-1; i>=0; i--) { - if (scrollplane.Sectors[i].Sector->tag == tag) + if (scrollplane.Sectors[i].Sector->HasTag(tag)) { scrollplane.Sectors.Delete(i); } diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index b550eeb770..76f7a03715 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -1266,7 +1266,7 @@ FUNC(LS_Thing_Destroy) while (actor) { AActor *temp = iterator.Next (); - if (actor->flags & MF_SHOOTABLE && actor->Sector->tag == arg2) + if (actor->flags & MF_SHOOTABLE && actor->Sector->HasTag(arg2)) P_DamageMobj (actor, NULL, it, arg1 ? TELEFRAG_DAMAGE : actor->health, NAME_None); actor = temp; } @@ -1279,7 +1279,7 @@ FUNC(LS_Thing_Destroy) while (actor) { AActor *temp = iterator.Next (); - if (actor->flags & MF_SHOOTABLE && (arg2 == 0 || actor->Sector->tag == arg2)) + if (actor->flags & MF_SHOOTABLE && (arg2 == 0 || actor->Sector->HasTag(arg2))) P_DamageMobj (actor, NULL, it, arg1 ? TELEFRAG_DAMAGE : actor->health, NAME_None); actor = temp; } @@ -2167,7 +2167,7 @@ static void SetScroller (int tag, DScroller::EScrollType type, fixed_t dx, fixed { if (scroller->IsType (type)) { - if (sectors[scroller->GetAffectee ()].tag == tag) + if (sectors[scroller->GetAffectee ()].HasTag(tag)) { i++; scroller->SetRate (dx, dy); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 2571413c85..ffb12fddd9 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -3437,7 +3437,7 @@ void AActor::Tick () } else if (scrolltype == Scroll_StrifeCurrent) { // Strife scroll special - int anglespeed = sec->tag - 100; + int anglespeed = sec->GetTag() - 100; fixed_t carryspeed = DivScale32 (anglespeed % 10, 16*CARRYFACTOR); angle_t fineangle = (anglespeed / 10) << (32-3); fineangle >>= ANGLETOFINESHIFT; diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 904c76c1b3..f34eadb440 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -825,6 +825,36 @@ sector_t *sector_t::GetHeightSec() const } +bool sector_t::HasTag(int checktag) const +{ + return tag == checktag; +} + +void sector_t::SetTag(int tagnum, bool discardall) +{ + tag = tagnum; +} + +int sector_t::GetTag() const +{ + return tag; +} + +void sector_t::HashTags() +{ + int i; + + for (i=numsectors; --i>=0; ) // Initially make all slots empty. + sectors[i].firsttag = -1; + for (i=numsectors; --i>=0; ) // Proceed from last to first sector + { // so that lower sectors appear first + int j = (unsigned) sectors[i].tag % (unsigned) numsectors; // Hash func + sectors[i].nexttag = sectors[j].firsttag; // Prepend sector to chain + sectors[j].firsttag = i; + } +} + + bool secplane_t::CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const { bool copy = false; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 80c84ffde7..990a18ae50 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1514,7 +1514,7 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex) else // [RH] Translate to new sector special ss->special = P_TranslateSectorSpecial (LittleShort(ms->special)); ss->secretsector = !!(ss->special&SECRET_MASK); - ss->tag = LittleShort(ms->tag); + ss->SetTag(LittleShort(ms->tag)); ss->thinglist = NULL; ss->touching_thinglist = NULL; // phares 3/14/98 ss->seqType = defSeqType; @@ -2495,7 +2495,7 @@ void P_ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec, intmaps for (s = 0; s < numsectors; s++) { - if (sectors[s].tag == tag) + if (sectors[s].HasTag(tag)) { if (!colorgood) color = sectors[s].ColorMap->Color; if (!foggood) fog = sectors[s].ColorMap->Fade; @@ -3131,9 +3131,9 @@ static void P_GroupLines (bool buildmap) { if (sector->linecount == 0) { - Printf ("Sector %i (tag %i) has no lines\n", i, sector->tag); + Printf ("Sector %i (tag %i) has no lines\n", i, sector->GetTag()); // 0 the sector's tag so that no specials can use it - sector->tag = 0; + sector->SetTag(0); } else { @@ -3309,18 +3309,10 @@ void P_LoadBehavior (MapData * map) // Hash the sector tags across the sectors and linedefs. static void P_InitTagLists () { - int i; - - for (i=numsectors; --i>=0; ) // Initially make all slots empty. - sectors[i].firsttag = -1; - for (i=numsectors; --i>=0; ) // Proceed from last to first sector - { // so that lower sectors appear first - int j = (unsigned) sectors[i].tag % (unsigned) numsectors; // Hash func - sectors[i].nexttag = sectors[j].firsttag; // Prepend sector to chain - sectors[j].firsttag = i; - } + sector_t::HashTags(); // killough 4/17/98: same thing, only for linedefs + int i; for (i=numlines; --i>=0; ) // Initially make all slots empty. lines[i].firstid = -1; diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 3e3b03c4e2..e30457b154 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -250,7 +250,7 @@ static AActor *SelectTeleDest (int tid, int tag, bool norandom) int count = 0; while ( (searcher = iterator.Next ()) ) { - if (tag == 0 || searcher->Sector->tag == tag) + if (tag == 0 || searcher->Sector->HasTag(tag)) { count++; } @@ -289,7 +289,7 @@ static AActor *SelectTeleDest (int tid, int tag, bool norandom) while (count > 0) { searcher = iterator.Next (); - if (tag == 0 || searcher->Sector->tag == tag) + if (tag == 0 || searcher->Sector->HasTag(tag)) { count--; } diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 31634ee811..4ad3c3efc3 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1316,7 +1316,7 @@ public: continue; case NAME_Id: - sec->tag = (short)CheckInt(key); + sec->SetTag((short)CheckInt(key), false); continue; default: diff --git a/src/p_writemap.cpp b/src/p_writemap.cpp index 83ed40b5b5..e21eb506e8 100644 --- a/src/p_writemap.cpp +++ b/src/p_writemap.cpp @@ -262,7 +262,7 @@ static int WriteSECTORS (FILE *file) uppercopy (ms.ceilingpic, GetTextureName (sectors[i].GetTexture(sector_t::ceiling))); ms.lightlevel = LittleShort((short)sectors[i].lightlevel); ms.special = LittleShort(sectors[i].special); - ms.tag = LittleShort(sectors[i].tag); + ms.tag = LittleShort(sectors[i].GetTag()); fwrite (&ms, sizeof(ms), 1, file); } return numsectors * sizeof(ms); diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index be2d154c38..68780fdba5 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -304,7 +304,7 @@ void P_TranslateTeleportThings () while ( (dest = iterator.Next()) ) { - if (dest->Sector->tag == 0) + if (dest->Sector->GetTag() == 0) { dest->tid = 1; dest->AddToHash (); diff --git a/src/r_defs.h b/src/r_defs.h index dd21365087..5cdbb9f825 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -633,6 +633,11 @@ struct sector_t return pos == floor? floorplane:ceilingplane; } + bool HasTag(int checktag) const; + void SetTag(int tagnum, bool discardall = true); + int GetTag() const; + static void HashTags(); + bool PlaneMoving(int pos);