From 902593198b3b8f7cb5314375707085d483b9e85b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2015 09:37:06 +0200 Subject: [PATCH] - wrapped all line ID accesss just like sector tags --- src/fragglescript/t_func.cpp | 17 +++++++++-------- src/p_3dfloors.cpp | 2 +- src/p_3dmidtex.cpp | 2 +- src/p_lnspec.cpp | 4 ++-- src/p_sectors.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/p_setup.cpp | 33 +++++++++++---------------------- src/p_spec.cpp | 4 ++-- src/p_udmf.cpp | 31 ++++++++++++++++++++++++++++--- src/p_xlat.cpp | 3 ++- src/r_defs.h | 7 +++++++ 10 files changed, 99 insertions(+), 40 deletions(-) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 7650b174e8..0251b8fba3 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -4382,16 +4382,17 @@ void FParser::SF_SetLineTrigger() FLineIdIterator itr(id); while ((i = itr.Next()) >= 0) { - if (t_argc==2) tag=lines[i].id; + if (t_argc == 2) tag = lines[i].GetMainId(); maplinedef_t mld; - mld.special=spec; - mld.tag=tag; - mld.flags=0; + mld.special = spec; + mld.tag = tag; + mld.flags = 0; int f = lines[i].flags; - P_TranslateLineDef(&lines[i], &mld); - lines[i].id=tag; - lines[i].flags = (lines[i].flags & (ML_MONSTERSCANACTIVATE|ML_REPEAT_SPECIAL|ML_SPAC_MASK|ML_FIRSTSIDEONLY)) | - (f & ~(ML_MONSTERSCANACTIVATE|ML_REPEAT_SPECIAL|ML_SPAC_MASK|ML_FIRSTSIDEONLY)); + P_TranslateLineDef(&lines[i], &mld); + lines[i].ClearIds(); + lines[i].SetMainId(tag); + lines[i].flags = (lines[i].flags & (ML_MONSTERSCANACTIVATE | ML_REPEAT_SPECIAL | ML_SPAC_MASK | ML_FIRSTSIDEONLY)) | + (f & ~(ML_MONSTERSCANACTIVATE | ML_REPEAT_SPECIAL | ML_SPAC_MASK | ML_FIRSTSIDEONLY)); } } diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index 5d63751c2a..a59b781121 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -844,7 +844,7 @@ void P_Spawn3DFloors (void) { if (line->args[1]&8) { - line->id = line->args[4]; + line->SetMainId(line->args[4]); } else { diff --git a/src/p_3dmidtex.cpp b/src/p_3dmidtex.cpp index 4939f55dc7..ff0d3a1814 100644 --- a/src/p_3dmidtex.cpp +++ b/src/p_3dmidtex.cpp @@ -167,7 +167,7 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c { line_t *ln = sectors[sec].lines[line]; - if (lineid != 0 && ln->id != lineid) continue; + if (lineid != 0 && !ln->HasId(lineid)) continue; if (ln->frontsector == NULL || ln->backsector == NULL || !(ln->flags & ML_3DMIDTEX)) { diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 16d0402f39..16372b2061 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -2063,7 +2063,7 @@ static void SetWallScroller (int id, int sidechoice, fixed_t dx, fixed_t dy, int { int wallnum = scroller->GetWallNum (); - if (wallnum >= 0 && sides[wallnum].linedef->id == id && + if (wallnum >= 0 && sides[wallnum].linedef->HasId(id) && int(sides[wallnum].linedef->sidedef[sidechoice] - sides) == wallnum && Where == scroller->GetScrollParts()) { @@ -2082,7 +2082,7 @@ static void SetWallScroller (int id, int sidechoice, fixed_t dx, fixed_t dy, int while ( (collect.Obj = iterator.Next ()) ) { if ((collect.RefNum = ((DScroller *)collect.Obj)->GetWallNum ()) != -1 && - sides[collect.RefNum].linedef->id == id && + sides[collect.RefNum].linedef->HasId(id) && int(sides[collect.RefNum].linedef->sidedef[sidechoice] - sides) == collect.RefNum && Where == ((DScroller *)collect.Obj)->GetScrollParts()) { diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index d96540351f..7061af7886 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -859,6 +859,42 @@ void sector_t::HashTags() } } +void line_t::SetMainId(int newid) +{ + id = newid; +} + +int line_t::GetMainId() const +{ + return id; +} + +void line_t::ClearIds() +{ + id = -1; +} + +bool line_t::HasId(int checkid) const +{ + return id == checkid; +} + + +void line_t::HashIds() +{ + // 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; + for (i=numlines; --i>=0; ) // Proceed from last to first linedef + { // so that lower linedefs appear first + int j = (unsigned) lines[i].id % (unsigned) numlines; // Hash func + lines[i].nextid = lines[j].firstid; // Prepend linedef to chain + lines[j].firstid = i; + } +} + bool secplane_t::CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 62270567c2..9c47e1fdc8 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1920,40 +1920,40 @@ void P_SetLineID (line_t *ld) case Line_SetIdentification: if (!(level.flags2 & LEVEL2_HEXENHACK)) { - ld->id = ld->args[0] + 256 * ld->args[4]; + ld->SetMainId(ld->args[0] + 256 * ld->args[4]); ld->flags |= ld->args[1]<<16; } else { - ld->id = ld->args[0]; + ld->SetMainId(ld->args[0]); } ld->special = 0; break; case TranslucentLine: - ld->id = ld->args[0]; + ld->SetMainId(ld->args[0]); ld->flags |= ld->args[3]<<16; break; case Teleport_Line: case Scroll_Texture_Model: - ld->id = ld->args[0]; + ld->SetMainId(ld->args[0]); break; case Polyobj_StartLine: - ld->id = ld->args[3]; + ld->SetMainId(ld->args[3]); break; case Polyobj_ExplicitLine: - ld->id = ld->args[4]; + ld->SetMainId(ld->args[4]); break; case Plane_Align: - ld->id = ld->args[2]; + ld->SetMainId(ld->args[2]); break; case Static_Init: - if (ld->args[1] == Init_SectorLink) ld->id = ld->args[0]; + if (ld->args[1] == Init_SectorLink) ld->SetMainId(ld->args[0]); break; } } @@ -2038,7 +2038,7 @@ void P_FinishLoadingLineDef(line_t *ld, int alpha) { for (j = 0; j < numlines; j++) { - if (lines[j].id == ld->args[0]) + if (lines[j].HasId(ld->args[0])) { lines[j].Alpha = alpha; if (additive) @@ -2233,7 +2233,7 @@ void P_LoadLineDefs2 (MapData * map) ld->v1 = &vertexes[LittleShort(mld->v1)]; ld->v2 = &vertexes[LittleShort(mld->v2)]; ld->Alpha = FRACUNIT; // [RH] Opaque by default - ld->id = -1; + ld->ClearIds(); P_SetSideNum (&ld->sidedef[0], LittleShort(mld->sidenum[0])); P_SetSideNum (&ld->sidedef[1], LittleShort(mld->sidenum[1])); @@ -3310,18 +3310,7 @@ void P_LoadBehavior (MapData * map) static void P_InitTagLists () { 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; - for (i=numlines; --i>=0; ) // Proceed from last to first linedef - { // so that lower linedefs appear first - int j = (unsigned) lines[i].id % (unsigned) numlines; // Hash func - lines[i].nextid = lines[j].firstid; // Prepend linedef to chain - lines[j].firstid = i; - } + line_t::HashIds(); } void P_GetPolySpots (MapData * map, TArray &spots, TArray &anchors) diff --git a/src/p_spec.cpp b/src/p_spec.cpp index c072122b86..8dbb73f371 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -279,11 +279,11 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType) } // some old WADs use this method to create walls that change the texture when shot. else if (activationType == SPAC_Impact && // only for shootable triggers - (level.flags2 & LEVEL2_DUMMYSWITCHES) && // this is only a compatibility setting for an old hack! + (level.flags2 & LEVEL2_DUMMYSWITCHES) && // this is only a compatibility setting for an old hack! !repeat && // only non-repeatable triggers (specialGeneric_Crusher) && // not for Boom's generalized linedefs special && // not for lines without a special - line->args[0] == line->id && // Safety check: exclude edited UDMF linedefs or ones that don't map the tag to args[0] + line->HasId(line->args[0]) && // Safety check: exclude edited UDMF linedefs or ones that don't map the tag to args[0] line->args[0] && // only if there's a tag (which is stored in the first arg) P_FindFirstSectorFromTag (line->args[0]) == -1) // only if no sector is tagged to this linedef { diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index aab952f214..75ad855fee 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -780,7 +780,7 @@ public: memset(ld, 0, sizeof(*ld)); ld->Alpha = FRACUNIT; - ld->id = -1; + ld->ClearIds(); ld->sidedef[0] = ld->sidedef[1] = NULL; if (level.flags2 & LEVEL2_CLIPMIDTEX) ld->flags |= ML_CLIP_MIDTEX; if (level.flags2 & LEVEL2_WRAPMIDTEX) ld->flags |= ML_WRAP_MIDTEX; @@ -813,7 +813,7 @@ public: continue; case NAME_Id: - ld->id = CheckInt(key); + ld->SetMainId(CheckInt(key)); continue; case NAME_Sidefront: @@ -1040,6 +1040,19 @@ public: break; } +#if 0 // for later + if (if (namespace_bits & (Zd)) && !strnicmp(key.GetChars(), "Id", 2)) + { + char *endp; + int num = strtol(key.GetChars(), &endp, 10); + if (num > 0 && *endp == NULL) + { + // only allow ID## with ## as a proper number + ld->SetId((short)CheckInt(key), false); + } + } +#endif + if (!strnicmp("user_", key.GetChars(), 5)) { AddUserKey(key, UDMF_Line, index); @@ -1053,7 +1066,7 @@ public: maplinedef_t mld; memset(&mld, 0, sizeof(mld)); mld.special = ld->special; - mld.tag = ld->id; + mld.tag = ld->GetMainId(); P_TranslateLineDef(ld, &mld); ld->flags = saved | (ld->flags&(ML_MONSTERSCANACTIVATE|ML_REPEAT_SPECIAL|ML_FIRSTSIDEONLY)); } @@ -1497,6 +1510,18 @@ public: default: break; } +#if 0 // for later + if (namespace_bits & (Zd)) && !strnicmp(key.GetChars(), "Id", 2)) + { + char *endp; + int num = strtol(key.GetChars(), &endp, 10); + if (num > 0 && *endp == NULL) + { + // only allow ID## with ## as a proper number + sec->SetTag((short)CheckInt(key), false); + } + } +#endif if (!strnicmp("user_", key.GetChars(), 5)) { diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 2d48e6053d..ef1e928492 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -104,7 +104,8 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld) // line also needs to have its ID set to the same as its tag. // An external conversion program would need to do this more // intelligently. - ld->id = tag; + ld->ClearIds(); + ld->SetMainId(tag); // 0 specials are never translated. if (special == 0) diff --git a/src/r_defs.h b/src/r_defs.h index 41821cb625..1865777d32 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -905,6 +905,13 @@ struct line_t sector_t *frontsector, *backsector; int validcount; // if == validcount, already checked int locknumber; // [Dusk] lock number for special + + + void SetMainId(int newid); + int GetMainId() const; + void ClearIds(); + bool HasId(int id) const; + static void HashIds(); }; // phares 3/14/98