From 20c56f6dda598dffd10ae6c50b25f21e17bf73b5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 9 Mar 2017 17:05:51 +0100 Subject: [PATCH] - added SectorTagIterator and LineIDIterator script classes. --- src/p_maputl.cpp | 10 +---- src/p_tags.cpp | 62 +++++++++++++++++++++++++++++++ src/p_tags.h | 25 ++++++++++--- wadsrc/static/zscript/mapdata.txt | 13 +++++++ 4 files changed, 97 insertions(+), 13 deletions(-) diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 7f97adeac0..c4fe47f31a 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -1243,17 +1243,11 @@ void FMultiBlockThingsIterator::Reset() class DBlockThingsIterator : public DObject, public FMultiBlockThingsIterator { - DECLARE_CLASS(DBlockThingsIterator, DObject); + DECLARE_ABSTRACT_CLASS(DBlockThingsIterator, DObject); FPortalGroupArray check; -protected: - DBlockThingsIterator() - :FMultiBlockThingsIterator(check) - { - } public: FMultiBlockThingsIterator::CheckResult cres; -public: bool Next() { return FMultiBlockThingsIterator::Next(&cres); @@ -1276,7 +1270,7 @@ public: } }; -IMPLEMENT_CLASS(DBlockThingsIterator, false, false); +IMPLEMENT_CLASS(DBlockThingsIterator, true, false); DEFINE_ACTION_FUNCTION(DBlockThingsIterator, Create) { diff --git a/src/p_tags.cpp b/src/p_tags.cpp index 9e7d60d608..748e25ca31 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -362,3 +362,65 @@ int FLineIdIterator::Next() start = tagManager.allIDs[start].nexttag; return ret; } + +class DSectorTagIterator : public DObject, public FSectorTagIterator +{ + DECLARE_ABSTRACT_CLASS(DSectorTagIterator, DObject); +public: + DSectorTagIterator(int tag, line_t *line) + { + if (line == nullptr) Init(tag); + else Init(tag, line); + } +}; + +IMPLEMENT_CLASS(DSectorTagIterator, true, false); + +DEFINE_ACTION_FUNCTION(DSectorTagIterator, Create) +{ + PARAM_PROLOGUE; + PARAM_INT(tag); + PARAM_POINTER_DEF(line, line_t); + ACTION_RETURN_POINTER(new DSectorTagIterator(tag, line)); +} + +DEFINE_ACTION_FUNCTION(DSectorTagIterator, Next) +{ + PARAM_SELF_PROLOGUE(DSectorTagIterator); + ACTION_RETURN_INT(self->Next()); +} + +DEFINE_ACTION_FUNCTION(DSectorTagIterator, NextCompat) +{ + PARAM_SELF_PROLOGUE(DSectorTagIterator); + PARAM_BOOL(compat); + PARAM_INT(secnum); + ACTION_RETURN_INT(self->NextCompat(compat, secnum)); +} + + +class DLineIdIterator : public DObject, public FLineIdIterator +{ + DECLARE_ABSTRACT_CLASS(DLineIdIterator, DObject); +public: + DLineIdIterator(int tag) + : FLineIdIterator(tag) + { + } +}; + +IMPLEMENT_CLASS(DLineIdIterator, true, false); + +DEFINE_ACTION_FUNCTION(DLineIdIterator, Create) +{ + PARAM_PROLOGUE; + PARAM_INT(tag); + ACTION_RETURN_POINTER(new DLineIdIterator(tag)); +} + +DEFINE_ACTION_FUNCTION(DLineIdIterator, Next) +{ + PARAM_SELF_PROLOGUE(DLineIdIterator); + ACTION_RETURN_INT(self->Next()); +} + diff --git a/src/p_tags.h b/src/p_tags.h index 17719de6fb..3af2580ec8 100644 --- a/src/p_tags.h +++ b/src/p_tags.h @@ -77,20 +77,23 @@ protected: int searchtag; int start; -public: - FSectorTagIterator(int tag) + FSectorTagIterator() + { + // For DSectorTagIterator + } + + void Init(int tag) { searchtag = tag; start = tag == 0 ? 0 : tagManager.TagHashFirst[((unsigned int)tag) % FTagManager::TAG_HASH_SIZE]; } - // Special constructor for actions that treat tag 0 as 'back of activation line' - FSectorTagIterator(int tag, line_t *line) + void Init(int tag, line_t *line) { if (tag == 0) { searchtag = INT_MIN; - start = (line == NULL || line->backsector == NULL)? -1 : line->backsector->Index(); + start = (line == NULL || line->backsector == NULL) ? -1 : line->backsector->Index(); } else { @@ -99,6 +102,18 @@ public: } } +public: + FSectorTagIterator(int tag) + { + Init(tag); + } + + // Special constructor for actions that treat tag 0 as 'back of activation line' + FSectorTagIterator(int tag, line_t *line) + { + Init(tag, line); + } + int Next(); int NextCompat(bool compat, int secnum); }; diff --git a/wadsrc/static/zscript/mapdata.txt b/wadsrc/static/zscript/mapdata.txt index 3d18f9f5ed..9b752ba40d 100644 --- a/wadsrc/static/zscript/mapdata.txt +++ b/wadsrc/static/zscript/mapdata.txt @@ -440,3 +440,16 @@ struct Sector native play } } + +class SectorTagIterator : Object native +{ + native static SectorTagIterator(int tag, line defline = null); + native int Next(); + native int NextCompat(bool compat, int secnum); +} + +class LineIdIterator : Object native +{ + native static LineIdIterator(int tag); + native int Next(); +}