- moved the tag manager into FLevelLocals

This commit is contained in:
Christoph Oelckers 2019-01-24 01:53:05 +01:00
parent 7e9340f3b7
commit 97495e1857
10 changed files with 51 additions and 78 deletions

View file

@ -296,33 +296,6 @@ PClassActor *T_ClassType(const svalue_t &arg)
return PClass::FindActor(stringvalue(arg)); return PClass::FindActor(stringvalue(arg));
} }
//==========================================================================
//
// Finds a sector from a tag. This has been extended to allow looking for
// sectors directly by passing a negative value
//
//==========================================================================
class FSSectorTagIterator : public FSectorTagIterator
{
public:
FSSectorTagIterator(int tag)
: FSectorTagIterator(tag)
{
if (tag < 0)
{
searchtag = INT_MIN;
start = tag == -32768? 0 : -tag < (int)level.sectors.Size()? -tag : -1;
}
}
};
inline int T_FindFirstSectorFromTag(int tagnum)
{
FSSectorTagIterator it(tagnum);
return it.Next();
}
//========================================================================== //==========================================================================
// //
// Get an ammo type // Get an ammo type
@ -1518,7 +1491,7 @@ void FParser::SF_StartSectorSound(void)
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
int i=-1; int i=-1;
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
sector = &Level->sectors[i]; sector = &Level->sectors[i];
@ -1555,7 +1528,7 @@ void FParser::SF_FloorHeight(void)
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
auto &sec = Level->sectors[i]; auto &sec = Level->sectors[i];
@ -1574,7 +1547,7 @@ void FParser::SF_FloorHeight(void)
} }
else else
{ {
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ {
script_error("sector not found with tagnum %i\n", tagnum); script_error("sector not found with tagnum %i\n", tagnum);
@ -1610,7 +1583,7 @@ void FParser::SF_MoveFloor(void)
// move all sectors with tag // move all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((secnum = itr.Next()) >= 0) while ((secnum = itr.Next()) >= 0)
{ {
P_CreateFloor(&Level->sectors[secnum], DFloor::floorMoveToValue, NULL, platspeed, destheight, crush, 0, false, false); P_CreateFloor(&Level->sectors[secnum], DFloor::floorMoveToValue, NULL, platspeed, destheight, crush, 0, false, false);
@ -1645,7 +1618,7 @@ void FParser::SF_CeilingHeight(void)
dest = floatvalue(t_argv[1]); dest = floatvalue(t_argv[1]);
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
auto &sec = Level->sectors[i]; auto &sec = Level->sectors[i];
@ -1664,7 +1637,7 @@ void FParser::SF_CeilingHeight(void)
} }
else else
{ {
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ {
script_error("sector not found with tagnum %i\n", tagnum); script_error("sector not found with tagnum %i\n", tagnum);
@ -1702,7 +1675,7 @@ void FParser::SF_MoveCeiling(void)
silent=t_argc>4 ? intvalue(t_argv[4]):1; silent=t_argc>4 ? intvalue(t_argv[4]):1;
// move all sectors with tag // move all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((secnum = itr.Next()) >= 0) while ((secnum = itr.Next()) >= 0)
{ {
P_CreateCeiling(&Level->sectors[secnum], DCeiling::ceilMoveToValue, NULL, tagnum, platspeed, platspeed, destheight, crush, silent | 4, 0, DCeiling::ECrushMode::crushDoom); P_CreateCeiling(&Level->sectors[secnum], DCeiling::ceilMoveToValue, NULL, tagnum, platspeed, platspeed, destheight, crush, silent | 4, 0, DCeiling::ECrushMode::crushDoom);
@ -1727,7 +1700,7 @@ void FParser::SF_LightLevel(void)
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
// argv is sector tag // argv is sector tag
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ {
@ -1741,7 +1714,7 @@ void FParser::SF_LightLevel(void)
int i = -1; int i = -1;
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
Level->sectors[i].SetLightLevel(intvalue(t_argv[1])); Level->sectors[i].SetLightLevel(intvalue(t_argv[1]));
@ -1882,7 +1855,7 @@ void FParser::SF_FloorTexture(void)
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
// argv is sector tag // argv is sector tag
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ script_error("sector not found with tagnum %i\n", tagnum); return;} { script_error("sector not found with tagnum %i\n", tagnum); return;}
@ -1895,7 +1868,7 @@ void FParser::SF_FloorTexture(void)
FTextureID picnum = TexMan.GetTextureID(t_argv[1].string, ETextureType::Flat, FTextureManager::TEXMAN_Overridable); FTextureID picnum = TexMan.GetTextureID(t_argv[1].string, ETextureType::Flat, FTextureManager::TEXMAN_Overridable);
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
Level->sectors[i].SetTexture(sector_t::floor, picnum); Level->sectors[i].SetTexture(sector_t::floor, picnum);
@ -1934,7 +1907,7 @@ void FParser::SF_SectorColormap(void)
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
// argv is sector tag // argv is sector tag
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ script_error("sector not found with tagnum %i\n", tagnum); return;} { script_error("sector not found with tagnum %i\n", tagnum); return;}
@ -1945,7 +1918,7 @@ void FParser::SF_SectorColormap(void)
{ {
uint32_t cm = R_ColormapNumForName(t_argv[1].value.s); uint32_t cm = R_ColormapNumForName(t_argv[1].value.s);
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
sectors[i].midmap=cm; sectors[i].midmap=cm;
@ -1972,7 +1945,7 @@ void FParser::SF_CeilingTexture(void)
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
// argv is sector tag // argv is sector tag
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ script_error("sector not found with tagnum %i\n", tagnum); return;} { script_error("sector not found with tagnum %i\n", tagnum); return;}
@ -1985,7 +1958,7 @@ void FParser::SF_CeilingTexture(void)
FTextureID picnum = TexMan.GetTextureID(t_argv[1].string, ETextureType::Flat, FTextureManager::TEXMAN_Overridable); FTextureID picnum = TexMan.GetTextureID(t_argv[1].string, ETextureType::Flat, FTextureManager::TEXMAN_Overridable);
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
Level->sectors[i].SetTexture(sector_t::ceiling, picnum); Level->sectors[i].SetTexture(sector_t::ceiling, picnum);
@ -3700,7 +3673,7 @@ void FParser::SF_SetColor(void)
{ {
tagnum = intvalue(t_argv[0]); tagnum = intvalue(t_argv[0]);
secnum = T_FindFirstSectorFromTag(tagnum); secnum = Level->FindFirstSectorFromTag(tagnum);
if(secnum < 0) if(secnum < 0)
{ {
@ -3721,7 +3694,7 @@ void FParser::SF_SetColor(void)
else return; else return;
// set all sectors with tag // set all sectors with tag
FSSectorTagIterator itr(tagnum); auto itr = Level->GetSectorTagIterator(tagnum);
while ((i = itr.Next()) >= 0) while ((i = itr.Next()) >= 0)
{ {
Level->sectors[i].SetColor(color, 0); Level->sectors[i].SetColor(color, 0);

View file

@ -103,6 +103,8 @@ struct FLevelData
TArray<FPlayerStart> AllPlayerStarts; TArray<FPlayerStart> AllPlayerStarts;
FBehaviorContainer Behaviors; FBehaviorContainer Behaviors;
FTagManager tagManager;
}; };
struct FLevelLocals : public FLevelData struct FLevelLocals : public FLevelData
@ -121,15 +123,15 @@ struct FLevelLocals : public FLevelData
FSectorTagIterator GetSectorTagIterator(int tag) FSectorTagIterator GetSectorTagIterator(int tag)
{ {
return FSectorTagIterator(tag); return FSectorTagIterator(tagManager, tag);
} }
FSectorTagIterator GetSectorTagIterator(int tag, line_t *line) FSectorTagIterator GetSectorTagIterator(int tag, line_t *line)
{ {
return FSectorTagIterator(tag, line); return FSectorTagIterator(tagManager, tag, line);
} }
FLineIdIterator GetLineIdIterator(int tag) FLineIdIterator GetLineIdIterator(int tag)
{ {
return FLineIdIterator(tag); return FLineIdIterator(tagManager, tag);
} }
template<class T> TThinkerIterator<T> GetThinkerIterator(FName subtype = NAME_None) template<class T> TThinkerIterator<T> GetThinkerIterator(FName subtype = NAME_None)
{ {

View file

@ -394,7 +394,7 @@ DEFINE_ACTION_FUNCTION(DLevelCompatibility, ClearSectorTags)
{ {
PARAM_SELF_PROLOGUE(DLevelCompatibility); PARAM_SELF_PROLOGUE(DLevelCompatibility);
PARAM_INT(sector); PARAM_INT(sector);
tagManager.RemoveSectorTags(sector); self->Level->tagManager.RemoveSectorTags(sector);
return 0; return 0;
} }
@ -406,7 +406,7 @@ DEFINE_ACTION_FUNCTION(DLevelCompatibility, AddSectorTag)
if ((unsigned)sector < self->Level->sectors.Size()) if ((unsigned)sector < self->Level->sectors.Size())
{ {
tagManager.AddSectorTag(sector, tag); self->Level->tagManager.AddSectorTag(sector, tag);
} }
return 0; return 0;
} }
@ -415,7 +415,7 @@ DEFINE_ACTION_FUNCTION(DLevelCompatibility, ClearLineIDs)
{ {
PARAM_SELF_PROLOGUE(DLevelCompatibility); PARAM_SELF_PROLOGUE(DLevelCompatibility);
PARAM_INT(line); PARAM_INT(line);
tagManager.RemoveLineIDs(line); self->Level->tagManager.RemoveLineIDs(line);
return 0; return 0;
} }
@ -427,7 +427,7 @@ DEFINE_ACTION_FUNCTION(DLevelCompatibility, AddLineID)
if ((unsigned)line < self->Level->lines.Size()) if ((unsigned)line < self->Level->lines.Size())
{ {
tagManager.AddLineID(line, tag); self->Level->tagManager.AddLineID(line, tag);
} }
return 0; return 0;
} }

View file

@ -583,7 +583,7 @@ void MapLoader::ProcessEDLinedef(line_t *ld, int recordnum)
ld->flags = (ld->flags&~fmask) | eld->flags; ld->flags = (ld->flags&~fmask) | eld->flags;
ld->setAlpha(eld->alpha); ld->setAlpha(eld->alpha);
memcpy(ld->args, eld->args, sizeof(ld->args)); memcpy(ld->args, eld->args, sizeof(ld->args));
tagManager.AddLineID(Index(ld), eld->tag); Level->tagManager.AddLineID(Index(ld), eld->tag);
} }
void MapLoader::ProcessEDSector(sector_t *sec, int recordnum) void MapLoader::ProcessEDSector(sector_t *sec, int recordnum)

View file

@ -1111,7 +1111,7 @@ void MapLoader::LoadSectors (MapData *map, FMissingTextureTracker &missingtex)
ss->special = LittleShort(ms->special); ss->special = LittleShort(ms->special);
else // [RH] Translate to new sector special else // [RH] Translate to new sector special
ss->special = P_TranslateSectorSpecial (LittleShort(ms->special)); ss->special = P_TranslateSectorSpecial (LittleShort(ms->special));
tagManager.AddSectorTag(i, LittleShort(ms->tag)); Level->tagManager.AddSectorTag(i, LittleShort(ms->tag));
ss->thinglist = nullptr; ss->thinglist = nullptr;
ss->touching_thinglist = nullptr; // phares 3/14/98 ss->touching_thinglist = nullptr; // phares 3/14/98
ss->sectorportal_thinglist = nullptr; ss->sectorportal_thinglist = nullptr;
@ -1529,7 +1529,7 @@ void MapLoader::SetLineID (int i, line_t *ld)
} }
if (setid != -1) if (setid != -1)
{ {
tagManager.AddLineID(i, setid); Level->tagManager.AddLineID(i, setid);
} }
} }
} }
@ -1753,7 +1753,7 @@ void MapLoader::LoadLineDefs (MapData * map)
// do not assign the tag for Extradata lines. // do not assign the tag for Extradata lines.
if (ld->special != Static_Init || (ld->args[1] != Init_EDLine && ld->args[1] != Init_EDSector)) if (ld->special != Static_Init || (ld->args[1] != Init_EDLine && ld->args[1] != Init_EDSector))
{ {
tagManager.AddLineID(i, mld->tag); Level->tagManager.AddLineID(i, mld->tag);
} }
#ifndef NO_EDATA #ifndef NO_EDATA
if (ld->special == Static_Init && ld->args[1] == Init_EDLine) if (ld->special == Static_Init && ld->args[1] == Init_EDLine)
@ -2755,7 +2755,7 @@ void MapLoader::GroupLines (bool buildmap)
{ {
Printf ("Sector %i (tag %i) has no lines\n", i, Level->GetFirstSectorTag(Index(sector))); Printf ("Sector %i (tag %i) has no lines\n", i, Level->GetFirstSectorTag(Index(sector)));
// 0 the sector's tag so that no specials can use it // 0 the sector's tag so that no specials can use it
tagManager.RemoveSectorTags(i); Level->tagManager.RemoveSectorTags(i);
} }
else else
{ {
@ -2810,7 +2810,7 @@ void MapLoader::GroupLines (bool buildmap)
} }
// killough 1/30/98: Create xref tables for tags // killough 1/30/98: Create xref tables for tags
tagManager.HashTags(); Level->tagManager.HashTags();
if (!buildmap) if (!buildmap)
{ {

View file

@ -856,7 +856,7 @@ public:
case NAME_Id: case NAME_Id:
lineid = CheckInt(key); lineid = CheckInt(key);
tagManager.AddLineID(index, lineid); Level->tagManager.AddLineID(index, lineid);
continue; continue;
case NAME_Sidefront: case NAME_Sidefront:
@ -1127,7 +1127,7 @@ public:
// scan the string as long as valid numbers can be found // scan the string as long as valid numbers can be found
while (sc.CheckNumber()) while (sc.CheckNumber())
{ {
if (sc.Number != 0) tagManager.AddLineID(index, sc.Number); if (sc.Number != 0) Level->tagManager.AddLineID(index, sc.Number);
} }
} }
@ -1513,7 +1513,7 @@ public:
continue; continue;
case NAME_Id: case NAME_Id:
tagManager.AddSectorTag(index, CheckInt(key)); Level->tagManager.AddSectorTag(index, CheckInt(key));
continue; continue;
default: default:
@ -1908,7 +1908,7 @@ public:
// scan the string as long as valid numbers can be found // scan the string as long as valid numbers can be found
while (sc.CheckNumber()) while (sc.CheckNumber())
{ {
if (sc.Number != 0) tagManager.AddSectorTag(index, sc.Number); if (sc.Number != 0) Level->tagManager.AddSectorTag(index, sc.Number);
} }
} }

View file

@ -904,7 +904,7 @@ void MapLoader::Spawn3DFloors ()
{ {
if (line.args[1]&8) if (line.args[1]&8)
{ {
tagManager.AddLineID(line.Index(), line.args[4]); Level->tagManager.AddLineID(line.Index(), line.args[4]);
} }
else else
{ {

View file

@ -39,8 +39,6 @@
#include "g_levellocals.h" #include "g_levellocals.h"
#include "vm.h" #include "vm.h"
FTagManager tagManager;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// //
@ -318,7 +316,7 @@ void FTagManager::DumpTags()
CCMD(dumptags) CCMD(dumptags)
{ {
tagManager.DumpTags(); level.tagManager.DumpTags();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -76,16 +76,15 @@ public: // The ones below are called by functions that cannot be declared as fri
void DumpTags(); void DumpTags();
}; };
extern FTagManager tagManager;
class FSectorTagIterator class FSectorTagIterator
{ {
friend struct FLevelLocals; friend struct FLevelLocals;
protected: protected:
int searchtag; int searchtag;
int start; int start;
FTagManager &tagManager;
FSectorTagIterator() FSectorTagIterator(FTagManager &tm) : tagManager(tm)
{ {
// For DSectorTagIterator // For DSectorTagIterator
} }
@ -110,13 +109,13 @@ protected:
} }
} }
FSectorTagIterator(int tag) FSectorTagIterator(FTagManager &tm, int tag) : tagManager(tm)
{ {
Init(tag); Init(tag);
} }
// Special constructor for actions that treat tag 0 as 'back of activation line' // Special constructor for actions that treat tag 0 as 'back of activation line'
FSectorTagIterator(int tag, line_t *line) FSectorTagIterator(FTagManager &tm, int tag, line_t *line) : tagManager(tm)
{ {
Init(tag, line); Init(tag, line);
} }
@ -131,8 +130,9 @@ class FLineIdIterator
protected: protected:
int searchtag; int searchtag;
int start; int start;
FTagManager &tagManager;
FLineIdIterator(int id) FLineIdIterator(FTagManager &tm, int id) : tagManager(tm)
{ {
searchtag = id; searchtag = id;
start = tagManager.IDHashFirst[((unsigned int)id) % FTagManager::TAG_HASH_SIZE]; start = tagManager.IDHashFirst[((unsigned int)id) % FTagManager::TAG_HASH_SIZE];

View file

@ -243,7 +243,7 @@ class DSectorTagIterator : public DObject, public FSectorTagIterator
{ {
DECLARE_ABSTRACT_CLASS(DSectorTagIterator, DObject); DECLARE_ABSTRACT_CLASS(DSectorTagIterator, DObject);
public: public:
DSectorTagIterator(int tag, line_t *line) DSectorTagIterator(FTagManager &tm, int tag, line_t *line) : FSectorTagIterator(tm)
{ {
if (line == nullptr) Init(tag); if (line == nullptr) Init(tag);
else Init(tag, line); else Init(tag, line);
@ -254,7 +254,7 @@ IMPLEMENT_CLASS(DSectorTagIterator, true, false);
static DSectorTagIterator *CreateSTI(int tag, line_t *line) static DSectorTagIterator *CreateSTI(int tag, line_t *line)
{ {
return Create<DSectorTagIterator>(tag, line); return Create<DSectorTagIterator>(level.tagManager, tag, line);
} }
DEFINE_ACTION_FUNCTION_NATIVE(DSectorTagIterator, Create, CreateSTI) DEFINE_ACTION_FUNCTION_NATIVE(DSectorTagIterator, Create, CreateSTI)
@ -262,7 +262,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DSectorTagIterator, Create, CreateSTI)
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(tag); PARAM_INT(tag);
PARAM_POINTER(line, line_t); PARAM_POINTER(line, line_t);
ACTION_RETURN_POINTER(Create<DSectorTagIterator>(tag, line)); ACTION_RETURN_POINTER(CreateSTI(tag, line));
} }
int NextSTI(DSectorTagIterator *self) int NextSTI(DSectorTagIterator *self)
@ -299,8 +299,8 @@ class DLineIdIterator : public DObject, public FLineIdIterator
{ {
DECLARE_ABSTRACT_CLASS(DLineIdIterator, DObject); DECLARE_ABSTRACT_CLASS(DLineIdIterator, DObject);
public: public:
DLineIdIterator(int tag) DLineIdIterator(FTagManager &tm, int tag)
: FLineIdIterator(tag) : FLineIdIterator(tm, tag)
{ {
} }
}; };
@ -310,14 +310,14 @@ IMPLEMENT_CLASS(DLineIdIterator, true, false);
static DLineIdIterator *CreateLTI(int tag) static DLineIdIterator *CreateLTI(int tag)
{ {
return Create<DLineIdIterator>(tag); return Create<DLineIdIterator>(level.tagManager, tag);
} }
DEFINE_ACTION_FUNCTION_NATIVE(DLineIdIterator, Create, CreateLTI) DEFINE_ACTION_FUNCTION_NATIVE(DLineIdIterator, Create, CreateLTI)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(tag); PARAM_INT(tag);
ACTION_RETURN_POINTER(Create<DLineIdIterator>(tag)); ACTION_RETURN_POINTER(CreateLTI(tag));
} }
int NextLTI(DLineIdIterator *self) int NextLTI(DLineIdIterator *self)