mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +00:00
- reimplemented Duke's scripted actor iterators in a more lightweight fashion.
This now works without allocating garbage collected objects.
This commit is contained in:
parent
c32a695384
commit
de51b65ead
4 changed files with 83 additions and 206 deletions
|
@ -20,4 +20,3 @@
|
|||
#include "src/sectors.cpp"
|
||||
#include "src/spawn.cpp"
|
||||
#include "src/vmexports.cpp"
|
||||
#include "src/vmiterators.cpp"
|
||||
|
|
|
@ -411,4 +411,77 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, setpos, dukeplayer_setpos)
|
|||
}
|
||||
|
||||
|
||||
static DDukeActor* duke_firstStat(DukeStatIterator* it, int statnum)
|
||||
{
|
||||
it->Reset(statnum);
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeStatIterator, First, duke_firstStat)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeStatIterator);
|
||||
PARAM_INT(Sect);
|
||||
ACTION_RETURN_POINTER(duke_firstStat(self, Sect));
|
||||
}
|
||||
|
||||
static DDukeActor* duke_nextStat(DukeStatIterator* it)
|
||||
{
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeStatIterator, Next, duke_nextStat)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeStatIterator);
|
||||
ACTION_RETURN_POINTER(duke_nextStat(self));
|
||||
}
|
||||
|
||||
static DDukeActor* duke_firstSect(DukeSectIterator* it, sectortype* sect)
|
||||
{
|
||||
if (sect == nullptr) return nullptr;
|
||||
it->Reset(sect);
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeSectIterator, First, duke_firstSect)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeSectIterator);
|
||||
PARAM_POINTER(sect, sectortype);
|
||||
ACTION_RETURN_POINTER(duke_firstSect(self, sect));
|
||||
}
|
||||
|
||||
static DDukeActor* duke_nextSect(DukeSectIterator* it)
|
||||
{
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeSectIterator, Next, duke_nextSect)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeSectIterator);
|
||||
ACTION_RETURN_POINTER(duke_nextSect(self));
|
||||
}
|
||||
|
||||
static DDukeActor* duke_firstSprite(DukeSpriteIterator* it)
|
||||
{
|
||||
it->Reset();
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeSpriteIterator, First, duke_firstSprite)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeSpriteIterator);
|
||||
ACTION_RETURN_POINTER(duke_firstSprite(self));
|
||||
}
|
||||
|
||||
static DDukeActor* duke_nextSprite(DukeSpriteIterator* it)
|
||||
{
|
||||
return it->Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeSpriteIterator, Next, duke_nextSprite)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(DukeSpriteIterator);
|
||||
ACTION_RETURN_POINTER(duke_nextSprite(self));
|
||||
}
|
||||
|
||||
|
||||
END_DUKE_NS
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright 2016-2022 Christoph Oelckers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VM iterators
|
||||
//
|
||||
// These classes are thin wrappers which wrap the standard iterators into a DObject
|
||||
// so that the VM can use them
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// scriptable stat iterator
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
class DDukeStatIterator : public DObject
|
||||
{
|
||||
DECLARE_ABSTRACT_CLASS(DDukeStatIterator, DObject)
|
||||
|
||||
public:
|
||||
|
||||
DukeStatIterator it;
|
||||
|
||||
DDukeStatIterator(int statnum)
|
||||
: it(statnum)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS(DDukeStatIterator, true, false);
|
||||
|
||||
static DDukeStatIterator *CreateStatIterator(int statnum)
|
||||
{
|
||||
return Create<DDukeStatIterator>(statnum);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, CreateStatIterator, CreateStatIterator)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(statnum);
|
||||
ACTION_RETURN_OBJECT(CreateStatIterator(statnum));
|
||||
}
|
||||
|
||||
static DDukeActor *NextStat(DDukeStatIterator *self)
|
||||
{
|
||||
return self->it.Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeStatIterator, Next, NextStat)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeStatIterator);
|
||||
ACTION_RETURN_OBJECT(NextStat(self));
|
||||
}
|
||||
|
||||
static void ResetStat(DDukeStatIterator *self, int stat)
|
||||
{
|
||||
self->it.Reset(stat);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeStatIterator, Reset, ResetStat)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeStatIterator);
|
||||
PARAM_INT(stat);
|
||||
ResetStat(self, stat);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// scriptable sector iterator
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
class DDukeSectIterator : public DObject
|
||||
{
|
||||
DECLARE_ABSTRACT_CLASS(DDukeSectIterator, DObject)
|
||||
|
||||
public:
|
||||
|
||||
DukeSectIterator it;
|
||||
|
||||
DDukeSectIterator(sectortype* Sectnum)
|
||||
: it(Sectnum)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS(DDukeSectIterator, true, false);
|
||||
|
||||
static DDukeSectIterator *CreateSectIterator(sectortype* Sectnum)
|
||||
{
|
||||
return Create<DDukeSectIterator>(Sectnum);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, CreateSectorIterator, CreateSectIterator)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_POINTER(Sectnum, sectortype);
|
||||
ACTION_RETURN_OBJECT(CreateSectIterator(Sectnum));
|
||||
}
|
||||
|
||||
static DDukeActor *NextSect(DDukeSectIterator *self)
|
||||
{
|
||||
return self->it.Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeSectIterator, Next, NextSect)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeSectIterator);
|
||||
ACTION_RETURN_OBJECT(NextSect(self));
|
||||
}
|
||||
|
||||
static void ResetSect(DDukeSectIterator *self, int Sect)
|
||||
{
|
||||
self->it.Reset(Sect);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeSectIterator, Reset, ResetSect)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeSectIterator);
|
||||
PARAM_INT(Sect);
|
||||
ResetSect(self, Sect);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// scriptable sprite iterator
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
class DDukeSpriteIterator : public DObject
|
||||
{
|
||||
DECLARE_ABSTRACT_CLASS(DDukeSpriteIterator, DObject)
|
||||
|
||||
public:
|
||||
|
||||
DukeSpriteIterator it;
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS(DDukeSpriteIterator, true, false);
|
||||
|
||||
static DDukeSpriteIterator *CreateSpriteIterator()
|
||||
{
|
||||
return Create<DDukeSpriteIterator>();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, CreateSpriteIterator, CreateSpriteIterator)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
ACTION_RETURN_OBJECT(CreateSpriteIterator());
|
||||
}
|
||||
|
||||
static DDukeActor *NextSprite(DDukeSpriteIterator *self)
|
||||
{
|
||||
return self->it.Next();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeSpriteIterator, Next, NextSprite)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeSpriteIterator);
|
||||
ACTION_RETURN_OBJECT(NextSprite(self));
|
||||
}
|
||||
|
||||
static void ResetSprite(DDukeSpriteIterator *self)
|
||||
{
|
||||
self->it.Reset();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DDukeSpriteIterator, Reset, ResetSprite)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DDukeSpriteIterator);
|
||||
ResetSprite(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
END_DUKE_NS
|
|
@ -86,25 +86,26 @@ extend struct _
|
|||
// On the script side we do not really want scattered global data that is publicly accessible.
|
||||
struct DukeLevel
|
||||
{
|
||||
native static DukeStatIterator CreateStatIterator(int stat);
|
||||
native static DukeSectIterator CreateSectorIterator(sectortype sect);
|
||||
native static DukeSpriteIterator CreateSpriteIterator();
|
||||
}
|
||||
|
||||
class DukeStatIterator native
|
||||
struct DukeStatIterator
|
||||
{
|
||||
private DukeActor nextp;
|
||||
native DukeActor Next();
|
||||
native void Reset(int stat);
|
||||
native DukeActor First(int stat);
|
||||
}
|
||||
|
||||
class DukeSectIterator native
|
||||
struct DukeSectIterator
|
||||
{
|
||||
private DukeActor nextp;
|
||||
native DukeActor Next();
|
||||
native void Reset(int sect);
|
||||
native DukeActor First(sectortype sect);
|
||||
}
|
||||
|
||||
class DukeSpriteIterator native
|
||||
struct DukeSpriteIterator
|
||||
{
|
||||
private DukeActor nextp;
|
||||
private int stat;
|
||||
native DukeActor Next();
|
||||
native void Reset();
|
||||
native DukeActor First();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue