Skip to content

Commit

Permalink
add CountSectorTags/CountSectorTags/CountLineIDs/GetLineID
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 authored and madame-rachelle committed Aug 2, 2023
1 parent 239a288 commit 793d6af
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/playsim/p_tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,92 @@ void FTagManager::DumpTags()
}
}

//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------

int FTagManager::CountSectorTags(const sector_t *sector)
{
int i = sector->Index();

if (SectorHasTags(i))
{
const int n = allTags.Size();

int j = startForSector[i];
int c = 0;

while(j < n && allTags[j].target == i)
{
j++;
c++;
}

return c;
}

return 0;
}

int FTagManager::GetSectorTag(const sector_t *sector, int index)
{
int i = sector->Index();

if (SectorHasTags(i))
{
const int n = allTags.Size();

int j = startForSector[i] + index;

return (j < n && allTags[j].target == i) ? allTags[j].tag : 0;
}
}

//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------

int FTagManager::CountLineIDs(const line_t *line)
{
int i = line->Index();

if (LineHasIDs(i))
{
const int n = allTags.Size();

int j = startForLine[i];
int c = 0;

while(j < n && allTags[j].target == i)
{
j++;
c++;
}

return c;
}

return 0;
}

int FTagManager::GetLineID(const line_t *line, int index)
{
int i = line->Index();

if (LineHasIDs(i))
{
const int n = allTags.Size();

int j = startForLine[i] + index;

return (j < n && allTags[j].target == i) ? allTags[j].tag : 0;
}
}

//-----------------------------------------------------------------------------
//
// RETURN NEXT SECTOR # THAT LINE TAG REFERS TO
Expand Down
6 changes: 6 additions & 0 deletions src/playsim/p_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class FTagManager
void RemoveLineIDs(int line);

void DumpTags();

int CountSectorTags(const sector_t *sector);
int GetSectorTag(const sector_t *sector, int index);

int CountLineIDs(const line_t *line);
int GetLineID(const line_t *line, int index);
};

class FSectorTagIterator
Expand Down
46 changes: 46 additions & 0 deletions src/scripting/vmthunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,29 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset)
ACTION_RETURN_INT(self->e->XFloor.attached.Size());
}

static int CountSectorTags(const sector_t *self)
{
return level.tagManager.CountSectorTags(self);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Sector, CountTags, CountSectorTags)
{
PARAM_SELF_STRUCT_PROLOGUE(sector_t);
ACTION_RETURN_INT(level.tagManager.CountSectorTags(self));
}

static int GetSectorTag(const sector_t *self, int index)
{
return level.tagManager.GetSectorTag(self, index);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Sector, GetTag, GetSectorTag)
{
PARAM_SELF_STRUCT_PROLOGUE(sector_t);
PARAM_INT(index);
ACTION_RETURN_INT(level.tagManager.GetSectorTag(self, index));
}

static int Get3DFloorTexture(F3DFloor *self, int pos)
{
if ( pos )
Expand Down Expand Up @@ -1240,6 +1263,29 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset)
ACTION_RETURN_INT(LineIndex(self));
}

static int CountLineIDs(const line_t *self)
{
return level.tagManager.CountLineIDs(self);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Line, CountIDs, CountLineIDs)
{
PARAM_SELF_STRUCT_PROLOGUE(line_t);
ACTION_RETURN_INT(level.tagManager.CountLineIDs(self));
}

static int GetLineID(const line_t *self, int index)
{
return level.tagManager.GetLineID(self, index);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Line, GetID, GetLineID)
{
PARAM_SELF_STRUCT_PROLOGUE(line_t);
PARAM_INT(index);
ACTION_RETURN_INT(level.tagManager.GetLineID(self, index));
}

//===========================================================================
//
// side_t exports
Expand Down
6 changes: 6 additions & 0 deletions wadsrc/static/zscript/mapdata.zs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ struct Line native play

native clearscope int GetHealth() const;
native void SetHealth(int newhealth);

native int CountIDs() const;
native int GetID(int index) const;
}

struct SecPlane native play
Expand Down Expand Up @@ -646,6 +649,9 @@ struct Sector native play

native clearscope int GetHealth(SectorPart part) const;
native void SetHealth(SectorPart part, int newhealth);

native int CountTags() const;
native int GetTag(int index) const;
}

class SectorTagIterator : Object native
Expand Down

0 comments on commit 793d6af

Please sign in to comment.