diff --git a/source/build/include/build.h b/source/build/include/build.h index 2dd305da6..76059624c 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -90,7 +90,6 @@ enum { RS_CENTERORIGIN = (1<<30), }; - #include "buildtypes.h" 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 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(); diff --git a/source/core/coreactor.h b/source/core/coreactor.h new file mode 100644 index 000000000..913e480b6 --- /dev/null +++ b/source/core/coreactor.h @@ -0,0 +1,141 @@ +#pragma once + +#include +#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 sector; +extern TArray 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 +struct HitInfoBase +{ + static_assert(std::is_convertible_v, "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 = §or[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(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; + } +}; diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 0f908fd3e..218809613 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -425,6 +425,10 @@ void GameInterface::loadPalette(void) void GameInterface::app_init() { + for (int i = 0; i < MAXSPRITES; i++) + { + actorArray[i] = &bloodActors[i]; + } InitCheats(); memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS)); gGameOptions.nMonsterSettings = !userConfig.nomonsters; diff --git a/source/games/blood/src/bloodactor.h b/source/games/blood/src/bloodactor.h index af38b7a79..600aeabd9 100644 --- a/source/games/blood/src/bloodactor.h +++ b/source/games/blood/src/bloodactor.h @@ -1,5 +1,7 @@ #pragma once +#include "coreactor.h" + BEGIN_BLD_NS class DBloodActor; @@ -90,11 +92,8 @@ struct SPRITEHIT 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. -// Note that the indexing is very inconsistent - partially by sprite index, partially by xsprite index. -class DBloodActor +class DBloodActor : public DCoreActor { - int index; DBloodActor* base(); public: @@ -116,7 +115,11 @@ public: int cumulDamage; bool interpolated; - DBloodActor() :index(int(this - base())) {} + DBloodActor() + { + index = (int(this - base())); + } + DBloodActor& operator=(const DBloodActor& other) = default; void Clear() @@ -138,10 +141,7 @@ public: bool hasX() { return hasx; } void addX() { hasx = true; } - spritetype& s() { return sprite[index]; } 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) { @@ -237,11 +237,6 @@ public: return true; } } - - sectortype* sector() - { - return s().sector(); - } }; extern DBloodActor bloodActors[kMaxSprites]; diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 23e9da9a0..87e502f2c 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -1,4 +1,5 @@ #pragma once +#include "coreactor.h" #include "names.h" #include "packet.h" #include "d_net.h" diff --git a/source/games/exhumed/src/exhumedactor.h b/source/games/exhumed/src/exhumedactor.h index 5aa91a9b6..74607867b 100644 --- a/source/games/exhumed/src/exhumedactor.h +++ b/source/games/exhumed/src/exhumedactor.h @@ -1,5 +1,7 @@ #pragma once +#include "coreactor.h" + BEGIN_PS_NS class DExhumedActor; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 8349f8bff..5fd2df662 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -39,6 +39,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "build.h" #include "d_net.h" #include "gamefuncs.h" +#include "coreactor.h" #include "mytypes.h" #include "sounds.h" diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index 8ab4414ce..72e23484a 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -404,7 +404,7 @@ int DoBloodSpray(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: @@ -603,7 +603,7 @@ int DoPhosphorus(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: @@ -818,7 +818,7 @@ int DoChemBomb(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: @@ -1053,7 +1053,7 @@ int DoCaltrops(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 8e6dcdae5..cc7e37e5f 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -145,12 +145,6 @@ public: }; -enum EHitBitsSW -{ - kHitTypeMaskSW = 0x1C000, - kHitSky = 0x10000, // SW only -}; - inline int Collision::setNone() { @@ -186,7 +180,7 @@ inline int Collision::setSprite(DSWActor* num) return kHitSprite; } -int Collision::setSky() { setNone(); type = kHitSky; return kHitSky; } +int Collision::setSky() { setNone(); type = kHitVoid; return kHitVoid; } inline int Collision::setFromEngine(int value) { diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 539afe32f..72200d281 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -4300,7 +4300,7 @@ bool WeaponMoveHit(DSWActor* actor) default: break; - case kHitSky: + case kHitVoid: SetSuicide(actor); return true; @@ -8474,7 +8474,7 @@ int DoGrenade(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: @@ -8705,7 +8705,7 @@ int DoVulcanBoulder(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: @@ -9090,7 +9090,7 @@ int DoMine(DSWActor* actor) // check to see if you hit a sprite switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return 0; case kHitSprite: @@ -19197,7 +19197,7 @@ int DoShrapVelocity(DSWActor* actor) { switch (u->coll.type) { - case kHitSky: + case kHitVoid: KillActor(actor); return true; case kHitSprite: