- added script exports for Duke's iterators

This commit is contained in:
Christoph Oelckers 2022-01-26 00:16:21 +01:00
parent 5bc8b1c2d3
commit c27976b2e5
5 changed files with 245 additions and 0 deletions

View file

@ -708,6 +708,13 @@ struct AFuncDesc
extern FieldDesc const *const VMGlobal_##name##_HookPtr; \
MSVC_FSEG FieldDesc const *const VMGlobal_##name##_HookPtr GCC_FSEG = &VMGlobal_##name;
#define DEFINE_GLOBAL_UNSIZED(name) \
static const FieldDesc VMGlobal_##name = { "", #name, (size_t)&name, ~0u, 0 }; \
extern FieldDesc const *const VMGlobal_##name##_HookPtr; \
MSVC_FSEG FieldDesc const *const VMGlobal_##name##_HookPtr GCC_FSEG = &VMGlobal_##name;
class AActor;

View file

@ -19,3 +19,4 @@
#include "src/sbar.cpp"
#include "src/sectors.cpp"
#include "src/spawn.cpp"
#include "src/vmiterators.cpp"

View file

@ -398,6 +398,14 @@ void GameInterface::app_init()
S_ParseDeveloperCommentary();
}
// For now just a placeholder. Later this will contain all static level data.
struct DukeLevel
{
};
DukeLevel dlevel;
DEFINE_FIELD(DDukeActor, ownerActor)
DEFINE_FIELD(DDukeActor, hitOwnerActor)
DEFINE_FIELD(DDukeActor, cgg)
@ -417,4 +425,5 @@ DEFINE_FIELD(DDukeActor, seek_actor)
DEFINE_FIELD(DDukeActor, flags1)
DEFINE_FIELD(DDukeActor, flags2)
DEFINE_GLOBAL_UNSIZED(dlevel)
END_DUKE_NS

View file

@ -0,0 +1,196 @@
//-----------------------------------------------------------------------------
//
// 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(int Sectnum)
: it(Sectnum)
{
}
};
IMPLEMENT_CLASS(DDukeSectIterator, true, false);
static DDukeSectIterator *CreateSectIterator(int Sectnum)
{
return Create<DDukeSectIterator>(Sectnum);
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, CreateSectorIterator, CreateSectIterator)
{
PARAM_PROLOGUE;
PARAM_INT(Sectnum);
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

View file

@ -40,3 +40,35 @@ class DukeActor : CoreActor native
flagdef NoInterpolate: flags1, 20;
}
extend struct _
{
native DukeLevel dlevel;
}
// The level struct is a wrapper to group all level related global variables and static functions into one object.
// 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(int sect);
native static DukeSpriteIterator CreateSpriteIterator();
}
class DukeStatIterator native
{
native DukeActor Next();
native void Reset(int stat);
}
class DukeSectIterator native
{
native DukeActor Next();
native void Reset(int sect);
}
class DukeSpriteIterator native
{
native DukeActor Next();
native void Reset();
}