- while we're at it, let's also wrap line ID searches in an iterator class so that we can do multiple IDs per line later as well.

This commit is contained in:
Christoph Oelckers 2015-04-15 00:47:06 +02:00
parent 425e5b9ffc
commit 47543bb766
10 changed files with 103 additions and 57 deletions

View file

@ -2297,9 +2297,11 @@ void FParser::SF_SetLineBlocking(void)
{
blocking=blocks[blocking];
int tag=intvalue(t_argv[0]);
for (int i = -1; (i = P_FindLineFromID(tag, i)) >= 0;)
FLineIdIterator itr(tag);
int i;
while ((i = itr.Next()) >= 0)
{
lines[i].flags = (lines[i].flags & ~(ML_BLOCKING|ML_BLOCKEVERYTHING)) | blocking;
lines[i].flags = (lines[i].flags & ~(ML_BLOCKING | ML_BLOCKEVERYTHING)) | blocking;
}
}
}
@ -2318,7 +2320,9 @@ void FParser::SF_SetLineMonsterBlocking(void)
int blocking = intvalue(t_argv[1]) ? ML_BLOCKMONSTERS : 0;
int tag=intvalue(t_argv[0]);
for (int i = -1; (i = P_FindLineFromID(tag, i)) >= 0;)
FLineIdIterator itr(tag);
int i;
while ((i = itr.Next()) >= 0)
{
lines[i].flags = (lines[i].flags & ~ML_BLOCKMONSTERS) | blocking;
}
@ -2373,12 +2377,13 @@ void FParser::SF_SetLineTexture(void)
texture = stringvalue(t_argv[3]);
texturenum = TexMan.GetTexture(texture, FTexture::TEX_Wall, FTextureManager::TEXMAN_Overridable);
for (i = -1; (i = P_FindLineFromID(tag, i)) >= 0;)
FLineIdIterator itr(tag);
while ((i = itr.Next()) >= 0)
{
// bad sidedef, Hexen just SEGV'd here!
if(lines[i].sidedef[side] != NULL)
if (lines[i].sidedef[side] != NULL)
{
if (position >=0 && position <=2)
if (position >= 0 && position <= 2)
{
lines[i].sidedef[side]->SetTexture(position, texturenum);
}
@ -2392,7 +2397,8 @@ void FParser::SF_SetLineTexture(void)
int sections = intvalue(t_argv[3]);
// set all sectors with tag
for (i = -1; (i = P_FindLineFromID(tag, i)) >= 0;)
FLineIdIterator itr(tag);
while ((i = itr.Next()) >= 0)
{
side_t *sided = lines[i].sidedef[side];
if(sided != NULL)
@ -4373,7 +4379,8 @@ void FParser::SF_SetLineTrigger()
id=intvalue(t_argv[0]);
spec=intvalue(t_argv[1]);
if (t_argc>2) tag=intvalue(t_argv[2]);
for (i = -1; (i = P_FindLineFromID (id, i)) >= 0; )
FLineIdIterator itr(id);
while ((i = itr.Next()) >= 0)
{
if (t_argc==2) tag=lines[i].id;
maplinedef_t mld;

View file

@ -143,7 +143,9 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c
if (tag == 0)
{
for(int line = -1; (line = P_FindLineFromID(lineid,line)) >= 0; )
FLineIdIterator itr(lineid);
int line;
while ((line = itr.Next()) >= 0)
{
line_t *ln = &lines[line];

View file

@ -3300,7 +3300,8 @@ void DLevelScript::SetLineTexture (int lineid, int side, int position, int name)
texture = TexMan.GetTexture (texname, FTexture::TEX_Wall, FTextureManager::TEXMAN_Overridable);
while ((linenum = P_FindLineFromID (lineid, linenum)) >= 0)
FLineIdIterator itr(lineid);
while ((linenum = itr.Next()) >= 0)
{
side_t *sidedef;
@ -4458,7 +4459,7 @@ int DLevelScript::SideFromID(int id, int side)
}
else
{
int line = P_FindLineFromID(id, -1);
int line = P_FindFirstLineFromID(id);
if (line == -1) return -1;
if (lines[line].sidedef[side] == NULL) return -1;
return lines[line].sidedef[side]->Index;
@ -4474,7 +4475,7 @@ int DLevelScript::LineFromID(int id)
}
else
{
return P_FindLineFromID(id, -1);
return P_FindFirstLineFromID(id);
}
}
@ -5693,9 +5694,9 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
case ACSF_SetLineActivation:
if (argCount >= 2)
{
int line = -1;
while ((line = P_FindLineFromID(args[0], line)) >= 0)
int line;
FLineIdIterator itr(args[0]);
while ((line = itr.Next()) >= 0)
{
lines[line].activation = args[1];
}
@ -5705,7 +5706,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
case ACSF_GetLineActivation:
if (argCount > 0)
{
int line = P_FindLineFromID(args[0], -1);
int line = P_FindFirstLineFromID(args[0]);
return line >= 0 ? lines[line].activation : 0;
}
break;
@ -7999,9 +8000,10 @@ scriptwait:
case PCD_SETLINEBLOCKING:
{
int line = -1;
int line;
while ((line = P_FindLineFromID (STACK(2), line)) >= 0)
FLineIdIterator itr(STACK(2));
while ((line = itr.Next()) >= 0)
{
switch (STACK(1))
{
@ -8034,9 +8036,10 @@ scriptwait:
case PCD_SETLINEMONSTERBLOCKING:
{
int line = -1;
int line;
while ((line = P_FindLineFromID (STACK(2), line)) >= 0)
FLineIdIterator itr(STACK(2));
while ((line = itr.Next()) >= 0)
{
if (STACK(1))
lines[line].flags |= ML_BLOCKMONSTERS;
@ -8061,7 +8064,8 @@ scriptwait:
arg0 = -FName(FBehavior::StaticLookupString(arg0));
}
while ((linenum = P_FindLineFromID (STACK(7), linenum)) >= 0)
FLineIdIterator itr(STACK(7));
while ((linenum = itr.Next()) >= 0)
{
line_t *line = &lines[linenum];
line->special = specnum;

View file

@ -348,7 +348,9 @@ void P_AddSectorLinksByID(sector_t *control, int id, INTBOOL ceiling)
{
extsector_t::linked::plane &scrollplane = ceiling? control->e->Linked.Ceiling : control->e->Linked.Floor;
for(int line = -1; (line = P_FindLineFromID(id, line)) >= 0; )
FLineIdIterator itr(id);
int line;
while ((line = itr.Next()) >= 0)
{
line_t *ld = &lines[line];

View file

@ -2093,10 +2093,11 @@ static void SetWallScroller (int id, int sidechoice, fixed_t dx, fixed_t dy, int
}
size_t numcollected = Collection.Size ();
int linenum = -1;
int linenum;
// Now create scrollers for any walls that don't already have them.
while ((linenum = P_FindLineFromID (id, linenum)) >= 0)
FLineIdIterator itr(id);
while ((linenum = itr.Next()) >= 0)
{
if (lines[linenum].sidedef[sidechoice] != NULL)
{
@ -2431,30 +2432,28 @@ FUNC(LS_Sector_SetRotation)
FUNC(LS_Line_AlignCeiling)
// Line_AlignCeiling (lineid, side)
{
int line = P_FindLineFromID (arg0, -1);
bool ret = 0;
if (line < 0)
I_Error ("Sector_AlignCeiling: Lineid %d is undefined", arg0);
do
FLineIdIterator itr(arg0);
int line;
while ((line = itr.Next()) >= 0)
{
ret |= P_AlignFlat (line, !!arg1, 1);
} while ( (line = P_FindLineFromID (arg0, line)) >= 0);
}
return ret;
}
FUNC(LS_Line_AlignFloor)
// Line_AlignFloor (lineid, side)
{
int line = P_FindLineFromID (arg0, -1);
bool ret = 0;
if (line < 0)
I_Error ("Sector_AlignFloor: Lineid %d is undefined", arg0);
do
FLineIdIterator itr(arg0);
int line;
while ((line = itr.Next()) >= 0)
{
ret |= P_AlignFlat (line, !!arg1, 0);
} while ( (line = P_FindLineFromID (arg0, line)) >= 0);
}
return ret;
}
@ -2466,7 +2465,9 @@ FUNC(LS_Line_SetTextureOffset)
if (arg0 == 0 || arg3 < 0 || arg3 > 1)
return false;
for(int line = -1; (line = P_FindLineFromID (arg0, line)) >= 0; )
FLineIdIterator itr(arg0);
int line;
while ((line = itr.Next()) >= 0)
{
side_t *side = lines[line].sidedef[arg3];
if (side != NULL)
@ -2517,7 +2518,9 @@ FUNC(LS_Line_SetTextureScale)
if (arg0 == 0 || arg3 < 0 || arg3 > 1)
return false;
for(int line = -1; (line = P_FindLineFromID (arg0, line)) >= 0; )
FLineIdIterator itr(arg0);
int line;
while ((line = itr.Next()) >= 0)
{
side_t *side = lines[line].sidedef[arg3];
if (side != NULL)
@ -2588,7 +2591,9 @@ FUNC(LS_Line_SetBlocking)
if (arg2 & 1) clearflags |= flagtrans[i];
}
for(int line = -1; (line = P_FindLineFromID (arg0, line)) >= 0; )
FLineIdIterator itr(arg0);
int line;
while ((line = itr.Next()) >= 0)
{
lines[line].flags = (lines[line].flags & ~clearflags) | setflags;
}
@ -2881,8 +2886,9 @@ FUNC(LS_SetPlayerProperty)
FUNC(LS_TranslucentLine)
// TranslucentLine (id, amount, type)
{
int linenum = -1;
while ((linenum = P_FindLineFromID (arg0, linenum)) >= 0)
FLineIdIterator itr(arg0);
int linenum;
while ((linenum = itr.Next()) >= 0)
{
lines[linenum].Alpha = Scale(clamp(arg1, 0, 255), FRACUNIT, 255);
if (arg2 == 0)

View file

@ -225,7 +225,6 @@ bool EV_DoPillar (DPillar::EPillar type, line_t *line, int tag,
{
sec = &sectors[secnum];
manual_pillar:
if (sec->PlaneMoving(sector_t::floor) || sec->PlaneMoving(sector_t::ceiling))
continue;

View file

@ -45,9 +45,10 @@
static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, bool slopeCeil)
{
int linenum = -1;
int linenum;
while ((linenum = P_FindLineFromID (lineid, linenum)) != -1)
FLineIdIterator itr(lineid);
while ((linenum = itr.Next()) >= 0)
{
const line_t *line = &lines[linenum];
sector_t *sec;

View file

@ -227,18 +227,16 @@ int FSectorTagIterator::NextCompat(bool compat, int start)
// killough 4/16/98: Same thing, only for linedefs
int P_FindLineFromID (int id, int start)
int FLineIdIterator::Next()
{
start = start >= 0 ? lines[start].nextid :
lines[(unsigned) id % (unsigned) numlines].firstid;
while (start >= 0 && lines[start].id != id)
start = lines[start].nextid;
return start;
while (start != -1 && lines[start].id != searchtag) start = lines[start].nextid;
if (start == -1) return -1;
int ret = start;
start = lines[start].nextid;
return ret;
}
//============================================================================
//
// P_ActivateLine
@ -1010,7 +1008,8 @@ DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags
wallflags = WALLF_ABSLIGHTING | WALLF_NOFAKECONTRAST;
}
for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; )
FLineIdIterator itr(target);
while ((linenum = itr.Next()) >= 0)
{
if (flags & WLF_SIDE1 && lines[linenum].sidedef[0] != NULL)
{
@ -1040,7 +1039,8 @@ void DWallLightTransfer::DoTransfer (short lightlevel, int target, BYTE flags)
{
int linenum;
for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; )
FLineIdIterator itr(target);
while ((linenum = itr.Next()) >= 0)
{
line_t *line = &lines[linenum];
@ -1927,10 +1927,15 @@ static void P_SpawnScrollers(void)
// killough 3/1/98: scroll wall according to linedef
// (same direction and speed as scrolling floors)
case Scroll_Texture_Model:
for (s=-1; (s = P_FindLineFromID (l->args[0],s)) >= 0;)
{
FLineIdIterator itr(l->args[0]);
while ((s = itr.Next()) >= 0)
{
if (s != i)
new DScroller (dx, dy, lines+s, control, accel);
new DScroller(dx, dy, lines + s, control, accel);
}
break;
}
case Scroll_Texture_Offsets:
// killough 3/2/98: scroll according to sidedef offsets

View file

@ -274,6 +274,22 @@ public:
int NextCompat(bool compat, int secnum);
};
class FLineIdIterator
{
protected:
int searchtag;
int start;
public:
FLineIdIterator(int id)
{
searchtag = id;
start = lines[(unsigned) id % (unsigned) numlines].firstid;
}
int Next();
};
inline int P_FindFirstSectorFromTag(int tag)
{
@ -281,8 +297,11 @@ inline int P_FindFirstSectorFromTag(int tag)
return it.Next();
}
int P_FindLineFromID (int id, int start);
inline int P_FindFirstLineFromID(int tag)
{
FLineIdIterator it(tag);
return it.Next();
}
//
// P_LIGHTS

View file

@ -424,7 +424,8 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO
if (side || thing->flags2 & MF2_NOTELEPORT || !line || line->sidedef[1] == NULL)
return false;
for (i = -1; (i = P_FindLineFromID (id, i)) >= 0; )
FLineIdIterator itr(id);
while ((i = itr.Next()) >= 0)
{
if (line-lines == i)
continue;