2021-11-25 20:42:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-11-25 21:33:55 +00:00
|
|
|
#include "build.h"
|
2021-11-25 20:42:49 +00:00
|
|
|
|
|
|
|
class DCoreActor
|
|
|
|
{
|
|
|
|
// common part of the game actors
|
|
|
|
protected:
|
|
|
|
int index;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2021-12-04 21:04:16 +00:00
|
|
|
// These two are needed because we cannot rely on the ones in the sprites for unlinking.
|
|
|
|
int link_stat;
|
|
|
|
sectortype* link_sector;
|
|
|
|
DCoreActor* prevStat, * nextStat;
|
|
|
|
DCoreActor* prevSect, * nextSect;
|
|
|
|
|
2021-12-05 08:20:41 +00:00
|
|
|
virtual ~DCoreActor() = default;
|
|
|
|
virtual void Serialize(FSerializer& arc);
|
|
|
|
|
2021-12-03 20:36:32 +00:00
|
|
|
bool exists() const
|
|
|
|
{
|
|
|
|
return (unsigned)s().statnum < MAXSTATUS;
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
spritetype& s() const
|
2021-11-25 20:42:49 +00:00
|
|
|
{
|
|
|
|
return sprite[index];
|
|
|
|
}
|
|
|
|
|
2021-12-03 21:45:54 +00:00
|
|
|
spriteext_t& sx() const
|
|
|
|
{
|
|
|
|
return spriteext[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
spritesmooth_t& sm() const
|
|
|
|
{
|
|
|
|
return spritesmooth[index];
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
int GetIndex() const
|
2021-11-25 20:42:49 +00:00
|
|
|
{
|
|
|
|
// For error printing only! This is only identical with the sprite index for items spawned at map start.
|
|
|
|
return s().time;
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
int GetSpriteIndex() const
|
2021-11-25 20:42:49 +00:00
|
|
|
{
|
|
|
|
// this is only here to mark places that need changing later! It will be removed once the sprite array goes.
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
sectortype* sector() const
|
2021-11-25 20:42:49 +00:00
|
|
|
{
|
|
|
|
return s().sector();
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
bool insector() const
|
|
|
|
{
|
|
|
|
return s().insector();
|
|
|
|
}
|
2021-11-25 20:42:49 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// holds pointers to the game-side actors.
|
|
|
|
inline DCoreActor* actorArray[16384];
|
|
|
|
extern TArray<sectortype> sector;
|
|
|
|
extern TArray<walltype> wall;
|
|
|
|
|
|
|
|
|
|
|
|
// Masking these into the object index to keep it in 16 bit was probably the single most dumbest and pointless thing Build ever did.
|
|
|
|
// Gonna be fun to globally replace these to finally lift the limit this imposes on map size.
|
|
|
|
// Names taken from DukeGDX
|
|
|
|
enum EHitBits
|
|
|
|
{
|
|
|
|
kHitNone = 0,
|
|
|
|
kHitTypeMask = 0xC000,
|
|
|
|
kHitTypeMaskSW = 0x1C000, // SW has one more relevant bit
|
|
|
|
kHitIndexMask = 0x3FFF,
|
|
|
|
kHitSector = 0x4000,
|
|
|
|
kHitWall = 0x8000,
|
|
|
|
kHitSprite = 0xC000,
|
|
|
|
kHitVoid = 0x10000, // SW only
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-11-25 22:28:28 +00:00
|
|
|
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DCoreActor*& w, DCoreActor** def)
|
|
|
|
{
|
|
|
|
int index = w ? w->GetSpriteIndex() : -1;
|
|
|
|
Serialize(arc, keyname, index, nullptr);
|
|
|
|
if (arc.isReading()) w = index == -1 ? nullptr : actorArray[index];
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2021-11-25 20:42:49 +00:00
|
|
|
// This serves as input/output for all functions dealing with collisions, hits, etc.
|
|
|
|
// Not all utilities use all variables.
|
|
|
|
struct HitInfoBase
|
|
|
|
{
|
|
|
|
vec3_t hitpos;
|
|
|
|
sectortype* hitSector;
|
|
|
|
walltype* hitWall;
|
2021-11-25 21:33:55 +00:00
|
|
|
DCoreActor* hitActor;
|
2021-11-25 20:42:49 +00:00
|
|
|
|
2021-11-26 12:41:15 +00:00
|
|
|
void clearObj()
|
|
|
|
{
|
|
|
|
hitSector = nullptr;
|
|
|
|
hitWall = nullptr;
|
|
|
|
hitActor = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct THitInfo : public HitInfoBase
|
|
|
|
{
|
|
|
|
T* actor() const { return static_cast<T*>(hitActor); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct CollisionBase
|
|
|
|
{
|
|
|
|
int type;
|
2021-11-26 13:26:03 +00:00
|
|
|
int exbits; // extended game-side info (only used by Exhumed)
|
2021-11-26 12:41:15 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
// can only have one at a time
|
|
|
|
sectortype* hitSector;
|
|
|
|
walltype* hitWall;
|
|
|
|
DCoreActor* hitActor;
|
|
|
|
};
|
2021-11-25 20:42:49 +00:00
|
|
|
|
|
|
|
void invalidate()
|
|
|
|
{
|
|
|
|
type = -1; // something invalid that's not a valid hit type.
|
2021-11-26 12:41:15 +00:00
|
|
|
hitSector = nullptr;
|
2021-11-25 20:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int setNone()
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
return kHitNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
int setSector(int num)
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitSector;
|
|
|
|
hitSector = §or[num];
|
|
|
|
return kHitSector;
|
|
|
|
}
|
|
|
|
|
2021-11-26 00:01:16 +00:00
|
|
|
int setSector(sectortype* num)
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitSector;
|
|
|
|
hitSector = num;
|
|
|
|
return kHitSector;
|
|
|
|
}
|
|
|
|
|
2021-11-25 20:42:49 +00:00
|
|
|
int setWall(int num)
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitWall;
|
|
|
|
hitWall = &wall[num];
|
|
|
|
return kHitWall;
|
|
|
|
}
|
|
|
|
|
2021-11-26 00:01:16 +00:00
|
|
|
int setWall(walltype* num)
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitWall;
|
|
|
|
hitWall = num;
|
|
|
|
return kHitWall;
|
|
|
|
}
|
|
|
|
|
2021-11-25 20:42:49 +00:00
|
|
|
int setSprite(int num)
|
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitSprite;
|
2021-11-25 21:33:55 +00:00
|
|
|
hitActor = actorArray[num];
|
2021-11-25 20:42:49 +00:00
|
|
|
return kHitSprite;
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
int setSprite(DCoreActor* num)
|
2021-11-25 20:42:49 +00:00
|
|
|
{
|
|
|
|
*this = {};
|
|
|
|
type = kHitSprite;
|
|
|
|
hitActor = num;
|
|
|
|
return kHitSprite;
|
|
|
|
}
|
|
|
|
|
2021-11-26 12:41:15 +00:00
|
|
|
int setVoid()
|
|
|
|
{
|
|
|
|
hitSector = nullptr;
|
2021-11-25 20:42:49 +00:00
|
|
|
type = kHitVoid;
|
2021-11-26 12:41:15 +00:00
|
|
|
return kHitVoid;
|
2021-11-25 20:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this hack job needs to go. We still need it for the time being.
|
|
|
|
int setFromEngine(int value)
|
|
|
|
{
|
2021-11-26 12:41:15 +00:00
|
|
|
int type = value & kHitTypeMaskSW;
|
2021-11-25 20:42:49 +00:00
|
|
|
if (type == kHitSector) setSector(value & kHitIndexMask);
|
|
|
|
else if (type == kHitWall) setWall(value & kHitIndexMask);
|
|
|
|
else if (type == kHitSprite) setSprite(value & kHitIndexMask);
|
|
|
|
else setNone();
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
};
|
2021-11-25 21:33:55 +00:00
|
|
|
|
2021-11-26 12:00:33 +00:00
|
|
|
template<class T>
|
2021-11-26 12:41:15 +00:00
|
|
|
struct TCollision : public CollisionBase
|
2021-11-26 12:00:33 +00:00
|
|
|
{
|
2021-11-26 12:41:15 +00:00
|
|
|
T* actor() const { return static_cast<T*>(hitActor); }
|
2021-11-26 12:00:33 +00:00
|
|
|
};
|
2021-11-25 21:33:55 +00:00
|
|
|
|
2021-11-26 12:41:15 +00:00
|
|
|
|
2021-12-04 21:04:16 +00:00
|
|
|
struct ActorStatList
|
|
|
|
{
|
|
|
|
DCoreActor* firstEntry, * lastEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ActorStatList statList[MAXSTATUS];
|
2021-11-26 12:41:15 +00:00
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
// Iterator wrappers that return an actor pointer, not an index.
|
|
|
|
template<class TActor>
|
2021-12-04 21:04:16 +00:00
|
|
|
class TStatIterator
|
2021-11-25 21:33:55 +00:00
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
DCoreActor* next;
|
2021-11-25 21:33:55 +00:00
|
|
|
public:
|
2021-12-04 21:04:16 +00:00
|
|
|
TStatIterator(int stat)
|
|
|
|
{
|
|
|
|
next = statList[stat].firstEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset(int stat)
|
2021-11-25 21:33:55 +00:00
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
next = statList[stat].firstEntry;
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TActor* Next()
|
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
auto n = next;
|
|
|
|
if (next) next = next->nextStat;
|
|
|
|
return static_cast<TActor*>(n);
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TActor* Peek()
|
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
return static_cast<TActor*>(next);
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class TActor>
|
2021-12-04 21:04:16 +00:00
|
|
|
class TSectIterator
|
2021-11-25 21:33:55 +00:00
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
DCoreActor* next;
|
2021-11-25 21:33:55 +00:00
|
|
|
public:
|
2021-12-04 21:04:16 +00:00
|
|
|
//[[deprecated]]
|
|
|
|
TSectIterator(int stat)
|
|
|
|
{
|
|
|
|
next = sector[stat].firstEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
TSectIterator(sectortype* stat)
|
2021-11-25 21:33:55 +00:00
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
next = stat->firstEntry;
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:04:16 +00:00
|
|
|
//[[deprecated]]
|
|
|
|
void Reset(int stat)
|
2021-11-25 21:33:55 +00:00
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
next = sector[stat].firstEntry;
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:04:16 +00:00
|
|
|
void Reset(sectortype* stat)
|
|
|
|
{
|
|
|
|
next = stat->firstEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
TActor* Next()
|
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
auto n = next;
|
|
|
|
if (next) next = next->nextSect;
|
|
|
|
return static_cast<TActor*>(n);
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TActor* Peek()
|
|
|
|
{
|
2021-12-04 21:04:16 +00:00
|
|
|
return static_cast<TActor*>(next);
|
2021-11-25 21:33:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// An iterator to iterate over all sprites.
|
|
|
|
template<class TActor>
|
|
|
|
class TSpriteIterator
|
|
|
|
{
|
|
|
|
TStatIterator<TActor> it;
|
|
|
|
int stat = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TSpriteIterator() : it(0) {}
|
|
|
|
|
|
|
|
TActor* Next()
|
|
|
|
{
|
|
|
|
while (stat < MAXSTATUS)
|
|
|
|
{
|
|
|
|
auto ac = it.Next();
|
|
|
|
if (ac) return ac;
|
|
|
|
stat++;
|
|
|
|
if (stat < MAXSTATUS) it.Reset(stat);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-12-03 20:36:32 +00:00
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
stat = 0;
|
|
|
|
it.Reset(0);
|
|
|
|
}
|
2021-11-25 21:33:55 +00:00
|
|
|
};
|
|
|
|
|
2021-11-26 20:52:01 +00:00
|
|
|
using CoreSectIterator = TSectIterator<DCoreActor>;
|
|
|
|
|
2021-12-04 21:04:16 +00:00
|
|
|
DCoreActor* InsertActor(sectortype* sector, int stat, bool forcetail = false);
|
|
|
|
int DeleteActor(DCoreActor* actor);
|
|
|
|
void ChangeActorSect(DCoreActor* actor, sectortype* sector, bool forcetail = false);
|
|
|
|
int ChangeActorStat(DCoreActor* actor, int nStatus, bool forcetail = false);
|
|
|
|
void InitSpriteLists();
|
2021-11-26 20:52:01 +00:00
|
|
|
|
|
|
|
|
2021-12-03 19:20:33 +00:00
|
|
|
void SetActorZ(DCoreActor* actor, const vec3_t* newpos);
|
|
|
|
void SetActor(DCoreActor* actor, const vec3_t* newpos);
|
2021-11-26 20:52:01 +00:00
|
|
|
|
2021-12-03 19:20:33 +00:00
|
|
|
inline void SetActor(DCoreActor* actor, const vec3_t& newpos)
|
2021-11-26 20:52:01 +00:00
|
|
|
{
|
2021-12-03 19:20:33 +00:00
|
|
|
SetActor(actor, &newpos);
|
2021-11-26 20:52:01 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
|
2021-11-26 12:41:15 +00:00
|
|
|
|
|
|
|
inline int clipmove(vec3_t& pos, sectortype** const sect, int xvect, int yvect,
|
|
|
|
int const walldist, int const ceildist, int const flordist, unsigned const cliptype, CollisionBase& result, int clipmoveboxtracenum = 3)
|
|
|
|
{
|
|
|
|
int sectno = *sect ? sector.IndexOf(*sect) : -1;
|
2021-12-04 00:05:18 +00:00
|
|
|
result = clipmove_(&pos, §no, xvect, yvect, walldist, ceildist, flordist, cliptype, clipmoveboxtracenum);
|
2021-11-26 12:41:15 +00:00
|
|
|
*sect = sectno == -1 ? nullptr : §or[sectno];
|
2021-12-04 00:05:18 +00:00
|
|
|
return result.type;
|
2021-11-26 12:41:15 +00:00
|
|
|
}
|
2021-11-26 17:59:28 +00:00
|
|
|
|
2021-11-26 19:41:03 +00:00
|
|
|
inline int pushmove(vec3_t* const vect, sectortype** const sect, int32_t const walldist, int32_t const ceildist, int32_t const flordist,
|
|
|
|
uint32_t const cliptype, bool clear = true)
|
|
|
|
{
|
|
|
|
int sectno = *sect ? sector.IndexOf(*sect) : -1;
|
|
|
|
int res = pushmove_(vect, §no, walldist, ceildist, flordist, cliptype, clear);
|
|
|
|
*sect = sectno == -1 ? nullptr : §or[sectno];
|
|
|
|
return res;
|
|
|
|
}
|
2021-12-04 18:08:50 +00:00
|
|
|
|
|
|
|
inline tspriteptr_t renderAddTsprite(tspritetype* tsprite, int& spritesortcnt, DCoreActor* actor)
|
|
|
|
{
|
|
|
|
if (spritesortcnt >= MAXSPRITESONSCREEN) return nullptr;
|
|
|
|
auto tspr = &tsprite[spritesortcnt++];
|
|
|
|
tspr->copyfrom(&actor->s());
|
|
|
|
tspr->clipdist = 0;
|
|
|
|
tspr->ownerActor = actor;
|
|
|
|
return tspr;
|
|
|
|
}
|
|
|
|
|