diff --git a/source/common/engine/serializer.h b/source/common/engine/serializer.h index b4342ae6c..4797ca20d 100644 --- a/source/common/engine/serializer.h +++ b/source/common/engine/serializer.h @@ -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 +template >*/> FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) { DObject *v = static_cast(value); diff --git a/source/core/coreactor.h b/source/core/coreactor.h index a34da0b9f..951e31bbe 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -3,7 +3,6 @@ #include #include "build.h" #include "iterators.h" -#include "serializer.h" class DCoreActor { @@ -54,7 +53,6 @@ extern TArray 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 +struct THitInfo : public HitInfoBase +{ + T* actor() { return static_cast(hitActor); } +}; // Iterator wrappers that return an actor pointer, not an index. template @@ -299,6 +304,5 @@ inline int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_ hitinfo.hitSector = hd.sect == -1? nullptr : §or[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; } diff --git a/source/core/savegamehelp.h b/source/core/savegamehelp.h index 561c71d03..8dbd9ce43 100644 --- a/source/core/savegamehelp.h +++ b/source/core/savegamehelp.h @@ -3,6 +3,7 @@ #include "resourcefile.h" #include "build.h" #include "gamefuncs.h" +#include "coreactor.h" extern FixedBitArray 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 +inline FSerializer& Serialize(FSerializer& arc, const char* keyname, THitInfo& w, THitInfo* 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; +} + diff --git a/source/games/blood/src/actor.h b/source/games/blood/src/actor.h index f7bdde833..ec73f35ba 100644 --- a/source/games/blood/src/actor.h +++ b/source/games/blood/src/actor.h @@ -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; enum DAMAGE_TYPE { kDamageFall = 0, diff --git a/source/games/blood/src/bloodactor.h b/source/games/blood/src/bloodactor.h index 3c5e047d9..3d0e3b861 100644 --- a/source/games/blood/src/bloodactor.h +++ b/source/games/blood/src/bloodactor.h @@ -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(hitActor); - } -}; extern HitInfo gHitInfo; diff --git a/source/games/blood/src/loadsave.cpp b/source/games/blood/src/loadsave.cpp index bc618e97c..212c3eb95 100644 --- a/source/games/blood/src/loadsave.cpp +++ b/source/games/blood/src/loadsave.cpp @@ -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)) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 046eb47ab..1f7819299 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -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(hitActor); - } -}; +using HitInfo = THitInfo; struct animwalltype { diff --git a/source/games/exhumed/src/exhumedactor.h b/source/games/exhumed/src/exhumedactor.h index 800cf57fd..c3c35e3de 100644 --- a/source/games/exhumed/src/exhumedactor.h +++ b/source/games/exhumed/src/exhumedactor.h @@ -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(hitActor); - } -}; +using HitInfo = THitInfo; // Iterator wrappers that return an actor pointer, not an index. class ExhumedStatIterator : public StatIterator diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 573a28654..d2864a074 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -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; void FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sectnum, int32_t xvect, int32_t yvect, int32_t zvect, diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 0adf3ec79..251e39fb6 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -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(hitActor); - } -}; // Iterator wrappers that return an actor pointer, not an index. class SWStatIterator : public StatIterator