- added coreactor.h

This commit is contained in:
Christoph Oelckers 2021-11-25 21:42:49 +01:00
parent e526686d1e
commit 52c80f187a
10 changed files with 167 additions and 42 deletions

View file

@ -90,7 +90,6 @@ enum {
RS_CENTERORIGIN = (1<<30), RS_CENTERORIGIN = (1<<30),
}; };
#include "buildtypes.h" #include "buildtypes.h"
using uspriteptr_t = spritetype const *; using uspriteptr_t = spritetype const *;
@ -693,18 +692,6 @@ extern int32_t(*animateoffs_replace)(int const tilenum, int fakevar);
extern void(*initspritelists_replace)(void); extern void(*initspritelists_replace)(void);
extern int32_t(*changespritesect_replace)(int16_t spritenum, int16_t newsectnum); extern int32_t(*changespritesect_replace)(int16_t spritenum, int16_t newsectnum);
// 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,
kHitIndexMask = 0x3FFF,
kHitSector = 0x4000,
kHitWall = 0x8000,
kHitSprite = 0xC000,
};
void updateModelInterpolation(); void updateModelInterpolation();

141
source/core/coreactor.h Normal file
View file

@ -0,0 +1,141 @@
#pragma once
#include <stdint.h>
#include "buildtypes.h"
class DCoreActor
{
// common part of the game actors
protected:
int index;
public:
spritetype& s()
{
return sprite[index];
}
int GetIndex()
{
// For error printing only! This is only identical with the sprite index for items spawned at map start.
return s().time;
}
int GetSpriteIndex()
{
// this is only here to mark places that need changing later! It will be removed once the sprite array goes.
return index;
}
sectortype* sector()
{
return s().sector();
}
};
// 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
};
// This serves as input/output for all functions dealing with collisions, hits, etc.
// Not all utilities use all variables.
template<class TActor>
struct HitInfoBase
{
static_assert(std::is_convertible_v<TActor*, DCoreActor*>, "Actor class for Collision needs to inherit from DCoreActor");
int type;
vec3_t hitpos;
sectortype* hitSector;
walltype* hitWall;
TActor* hitActor;
HitInfoBase() = default;
explicit HitInfoBase(int legacyval) { setFromEngine(legacyval); }
void invalidate()
{
*this = {};
type = -1; // something invalid that's not a valid hit type.
}
int setNone()
{
*this = {};
return kHitNone;
}
int setSector(int num)
{
*this = {};
type = kHitSector;
hitSector = &sector[num];
return kHitSector;
}
int setWall(int num)
{
*this = {};
type = kHitWall;
hitWall = &wall[num];
return kHitWall;
}
int setSprite(int num)
{
*this = {};
type = kHitSprite;
hitActor = static_cast<TActor*>(actorArray[num]);
return kHitSprite;
}
int setSprite(TActor* num)
{
*this = {};
type = kHitSprite;
hitActor = num;
return kHitSprite;
}
int setVoid()
{
*this = {};
type = kHitVoid;
return kHitVoid;
}
// this hack job needs to go. We still need it for the time being.
int setFromEngine(int value)
{
type = value & kHitTypeMaskSW;
if (type == kHitSector) setSector(value & kHitIndexMask);
else if (type == kHitWall) setWall(value & kHitIndexMask);
else if (type == kHitSprite) setSprite(value & kHitIndexMask);
else setNone();
return type;
}
};

View file

@ -425,6 +425,10 @@ void GameInterface::loadPalette(void)
void GameInterface::app_init() void GameInterface::app_init()
{ {
for (int i = 0; i < MAXSPRITES; i++)
{
actorArray[i] = &bloodActors[i];
}
InitCheats(); InitCheats();
memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS)); memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS));
gGameOptions.nMonsterSettings = !userConfig.nomonsters; gGameOptions.nMonsterSettings = !userConfig.nomonsters;

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "coreactor.h"
BEGIN_BLD_NS BEGIN_BLD_NS
class DBloodActor; class DBloodActor;
@ -90,11 +92,8 @@ struct SPRITEHIT
Collision hit, ceilhit, florhit; Collision hit, ceilhit, florhit;
}; };
// Due to the messed up array storage of all the game data we cannot do any direct references here yet. We have to access everything via wrapper functions for now. class DBloodActor : public DCoreActor
// Note that the indexing is very inconsistent - partially by sprite index, partially by xsprite index.
class DBloodActor
{ {
int index;
DBloodActor* base(); DBloodActor* base();
public: public:
@ -116,7 +115,11 @@ public:
int cumulDamage; int cumulDamage;
bool interpolated; bool interpolated;
DBloodActor() :index(int(this - base())) {} DBloodActor()
{
index = (int(this - base()));
}
DBloodActor& operator=(const DBloodActor& other) = default; DBloodActor& operator=(const DBloodActor& other) = default;
void Clear() void Clear()
@ -138,10 +141,7 @@ public:
bool hasX() { return hasx; } bool hasX() { return hasx; }
void addX() { hasx = true; } void addX() { hasx = true; }
spritetype& s() { return sprite[index]; }
XSPRITE& x() { return xsprite; } // calling this does not validate the xsprite! XSPRITE& x() { return xsprite; } // calling this does not validate the xsprite!
int GetIndex() { return s().time; } // For error printing only! This is only identical with the sprite index for items spawned at map start.
int GetSpriteIndex() { return index; } // this is only here to mark places that need changing later!
void SetOwner(DBloodActor* own) void SetOwner(DBloodActor* own)
{ {
@ -237,11 +237,6 @@ public:
return true; return true;
} }
} }
sectortype* sector()
{
return s().sector();
}
}; };
extern DBloodActor bloodActors[kMaxSprites]; extern DBloodActor bloodActors[kMaxSprites];

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "coreactor.h"
#include "names.h" #include "names.h"
#include "packet.h" #include "packet.h"
#include "d_net.h" #include "d_net.h"

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "coreactor.h"
BEGIN_PS_NS BEGIN_PS_NS
class DExhumedActor; class DExhumedActor;

View file

@ -39,6 +39,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "build.h" #include "build.h"
#include "d_net.h" #include "d_net.h"
#include "gamefuncs.h" #include "gamefuncs.h"
#include "coreactor.h"
#include "mytypes.h" #include "mytypes.h"
#include "sounds.h" #include "sounds.h"

View file

@ -404,7 +404,7 @@ int DoBloodSpray(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:
@ -603,7 +603,7 @@ int DoPhosphorus(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:
@ -818,7 +818,7 @@ int DoChemBomb(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:
@ -1053,7 +1053,7 @@ int DoCaltrops(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:

View file

@ -145,12 +145,6 @@ public:
}; };
enum EHitBitsSW
{
kHitTypeMaskSW = 0x1C000,
kHitSky = 0x10000, // SW only
};
inline int Collision::setNone() inline int Collision::setNone()
{ {
@ -186,7 +180,7 @@ inline int Collision::setSprite(DSWActor* num)
return kHitSprite; return kHitSprite;
} }
int Collision::setSky() { setNone(); type = kHitSky; return kHitSky; } int Collision::setSky() { setNone(); type = kHitVoid; return kHitVoid; }
inline int Collision::setFromEngine(int value) inline int Collision::setFromEngine(int value)
{ {

View file

@ -4300,7 +4300,7 @@ bool WeaponMoveHit(DSWActor* actor)
default: default:
break; break;
case kHitSky: case kHitVoid:
SetSuicide(actor); SetSuicide(actor);
return true; return true;
@ -8474,7 +8474,7 @@ int DoGrenade(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:
@ -8705,7 +8705,7 @@ int DoVulcanBoulder(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite:
@ -9090,7 +9090,7 @@ int DoMine(DSWActor* actor)
// check to see if you hit a sprite // check to see if you hit a sprite
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return 0; return 0;
case kHitSprite: case kHitSprite:
@ -19197,7 +19197,7 @@ int DoShrapVelocity(DSWActor* actor)
{ {
switch (u->coll.type) switch (u->coll.type)
{ {
case kHitSky: case kHitVoid:
KillActor(actor); KillActor(actor);
return true; return true;
case kHitSprite: case kHitSprite: