diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index eb05509f5..fa511a48d 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -44,6 +44,7 @@ This file is a combination of code from the following sources: #include "names.h" #include "stats.h" #include "constants.h" +#include "dukeactor.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h new file mode 100644 index 000000000..6c936306a --- /dev/null +++ b/source/games/duke/src/dukeactor.h @@ -0,0 +1,50 @@ +#pragma once +#include "dobject.h" +#include "build.h" + +BEGIN_DUKE_NS + + +// Iterator wrappers that return an actor pointer, not an index. +class DukeStatIterator : public StatIterator +{ +public: + DukeStatIterator(int stat) : StatIterator(stat) + { + } + + DDukeActor *Next() + { + int n = NextIndex(); + return n >= 0? &hittype[n] : nullptr; + } + + DDukeActor *Peek() + { + int n = PeekIndex(); + return n >= 0? &hittype[n] : nullptr; + } +}; + +class DukeSectIterator : public SectIterator +{ +public: + DukeSectIterator(int stat) : SectIterator(stat) + { + } + + DDukeActor *Next() + { + int n = NextIndex(); + return n >= 0? &hittype[n] : nullptr; + } + + DDukeActor *Peek() + { + int n = PeekIndex(); + return n >= 0? &hittype[n] : nullptr; + } +}; + + +END_DUKE_NS diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index ed0c46ba8..2c9c0e4a9 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -44,11 +44,12 @@ struct weaponhit floorz = ceilingz = lastvx = lastvy = bposx = bposy = bposz = aflags = 0; memset(temp_data, 0, sizeof(temp_data)); } + int GetIndex() const { return this - array(); } }; extern weaponhit hittype[MAXSPRITES + 1]; inline weaponhit* weaponhit::array() { return hittype; } -using DDukeActor = weaponhit; // we do not really want that stupid name in our interface (but also not rename the struct yet.) +using DDukeActor = weaponhit; // we do not really want that stupid name in our interface (but also not rename the struct yet.) The preceding 'D' is for the DObject interface this should be transitioned to later. struct animwalltype {