- moved parts of the HitInfo subclasses into the backend.

All the game code now needs to do is a single 'using' statement.
This commit is contained in:
Christoph Oelckers 2021-11-26 13:00:33 +01:00
parent a5ccd2ccd2
commit 96b9572905
10 changed files with 36 additions and 55 deletions

View file

@ -235,7 +235,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI
FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString *def);
FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def);
template<class T>
template <typename T/*, typename = std::enable_if_t<std::is_base_of_v<DObject, T>>*/>
FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **)
{
DObject *v = static_cast<DObject*>(value);

View file

@ -3,7 +3,6 @@
#include <stdint.h>
#include "build.h"
#include "iterators.h"
#include "serializer.h"
class DCoreActor
{
@ -54,7 +53,6 @@ extern TArray<walltype> wall;
enum EHitBits
{
kHitNone = 0,
kHitTypeHitscan = 1, // hitscan results are not exclusive
kHitTypeMask = 0xC000,
kHitTypeMaskSW = 0x1C000, // SW has one more relevant bit
kHitIndexMask = 0x3FFF,
@ -78,15 +76,16 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DCoreActor*
// Not all utilities use all variables.
struct HitInfoBase
{
int type;
//int type;
vec3_t hitpos;
sectortype* hitSector;
walltype* hitWall;
DCoreActor* hitActor;
HitInfoBase() = default;
explicit HitInfoBase(int legacyval) { setFromEngine(legacyval); }
//HitInfoBase() = default;
//explicit HitInfoBase(int legacyval) { setFromEngine(legacyval); }
#if 0
void invalidate()
{
*this = {};
@ -164,6 +163,7 @@ struct HitInfoBase
else setNone();
return type;
}
#endif
void clearObj()
{
@ -173,6 +173,11 @@ struct HitInfoBase
}
};
template<class T>
struct THitInfo : public HitInfoBase
{
T* actor() { return static_cast<T*>(hitActor); }
};
// Iterator wrappers that return an actor pointer, not an index.
template<class TActor>
@ -299,6 +304,5 @@ inline int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_
hitinfo.hitSector = hd.sect == -1? nullptr : &sector[hd.sect];
hitinfo.hitWall = hd.wall == -1? nullptr : &wall[hd.wall];
hitinfo.hitActor = hd.sprite == -1? nullptr : actorArray[hd.sprite];
hitinfo.type = kHitTypeHitscan;
return res;
}

View file

@ -3,6 +3,7 @@
#include "resourcefile.h"
#include "build.h"
#include "gamefuncs.h"
#include "coreactor.h"
extern FixedBitArray<MAXSPRITES> activeSprites;
@ -23,7 +24,7 @@ void M_Autosave();
#define SAVEGAME_EXT ".dsave"
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, spritetype*& w, spritetype** def)
template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, spritetype*& w, spritetype** def)
{
int ndx = w ? int(w - sprite) : -1;
arc(keyname, ndx);
@ -31,7 +32,7 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, spritetype*
return arc;
}
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def)
template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def)
{
int ndx = w ? sectnum(w) : -1;
arc(keyname, ndx);
@ -39,7 +40,7 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*
return arc;
}
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, walltype*& w, walltype** def)
template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, walltype*& w, walltype** def)
{
int ndx = w ? wallnum(w) : -1;
arc(keyname, ndx);
@ -47,3 +48,19 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, walltype*&
return arc;
}
template<class T>
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, THitInfo<T>& w, THitInfo<T>* def)
{
if (arc.BeginObject(keyname))
{
arc("sect", w.hitSector)
("sprite", w.hitActor)
("wall", w.hitWall)
("x", w.hitpos.x)
("y", w.hitpos.y)
("z", w.hitpos.z)
.EndObject();
}
return arc;
}

View file

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS
class DBloodActor;
struct HitInfo;
using HitInfo = THitInfo<DBloodActor>;
enum DAMAGE_TYPE {
kDamageFall = 0,

View file

@ -244,13 +244,6 @@ extern DBloodActor bloodActors[kMaxSprites];
inline DBloodActor* DBloodActor::base() { return bloodActors; }
// subclassed to add a game specific actor() method
struct HitInfo : public HitInfoBase
{
DBloodActor* actor() const
{
return static_cast<DBloodActor*>(hitActor);
}
};
extern HitInfo gHitInfo;

View file

@ -642,21 +642,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, XSPRITE& w, XSPRIT
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, HitInfo& w, HitInfo* def)
{
if (arc.BeginObject(keyname))
{
arc("sect", w.hitSector)
("sprite", w.hitActor)
("wall", w.hitWall)
("x", w.hitpos.x)
("y", w.hitpos.y)
("z", w.hitpos.z)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, GAMEOPTIONS& w, GAMEOPTIONS* def)
{
if (arc.BeginObject(keyname))

View file

@ -103,13 +103,7 @@ extern DDukeActor hittype[MAXSPRITES + 1];
inline DDukeActor* DDukeActor::array() { return hittype; }
// subclassed to add a game specific actor() method
struct HitInfo : public HitInfoBase
{
DDukeActor* actor() const
{
return static_cast<DDukeActor*>(hitActor);
}
};
using HitInfo = THitInfo<DDukeActor>;
struct animwalltype
{

View file

@ -141,13 +141,7 @@ inline int Collision::actorIndex(DExhumedActor* a)
inline DExhumedActor* DExhumedActor::base() { return exhumedActors; }
// subclassed to add a game specific actor() method
struct HitInfo : public HitInfoBase
{
DExhumedActor* actor() const
{
return static_cast<DExhumedActor*>(hitActor);
}
};
using HitInfo = THitInfo<DExhumedActor>;
// Iterator wrappers that return an actor pointer, not an index.
class ExhumedStatIterator : public StatIterator

View file

@ -1917,7 +1917,8 @@ inline bool FAF_ConnectArea(sectortype* sect)
bool PlayerCeilingHit(PLAYERp pp, int zlimit);
bool PlayerFloorHit(PLAYERp pp, int zlimit);
struct HitInfo;
class DSWActor;
using HitInfo = THitInfo<DSWActor>;
void FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sectnum,
int32_t xvect, int32_t yvect, int32_t zvect,

View file

@ -47,13 +47,6 @@ extern DSWActor swActors[MAXSPRITES];
inline DSWActor* DSWActor::base() { return swActors; }
// subclassed to add a game specific actor() method
struct HitInfo : public HitInfoBase
{
DSWActor* actor() const
{
return static_cast<DSWActor*>(hitActor);
}
};
// Iterator wrappers that return an actor pointer, not an index.
class SWStatIterator : public StatIterator