diff --git a/source/build/include/build.h b/source/build/include/build.h index 7ef8062c6..45540d4cb 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -143,12 +143,8 @@ struct usermaphack_t uint8_t md4[16]{}; }; -extern spriteext_t spriteext[MAXSPRITES]; -extern spritesmooth_t spritesmooth[MAXSPRITES + MAXUNIQHUDID]; - extern TArray sector; extern TArray wall; -extern spritetype sprite[MAXSPRITES]; EXTERN int leveltimer; extern TArray sectorbackup; @@ -328,7 +324,7 @@ struct SpawnSpriteDef void insertAllSprites(SpawnSpriteDef& sprites); void allocateMapArrays(int numsprites); -void ValidateSprite(spritetype& spr); +void ValidateSprite(spritetype& spr, int index); void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int *dacursectnum, SpawnSpriteDef& sprites); void loadMapBackup(const char* filename); void G_LoadMapHack(const char* filename, const unsigned char*, SpawnSpriteDef& sprites); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index acc08674e..0434bafd7 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -41,12 +41,8 @@ #include "gl_renderer.h" #endif -spriteext_t spriteext[MAXSPRITES]; -spritesmooth_t spritesmooth[MAXSPRITES + MAXUNIQHUDID]; - TArray sector; TArray wall; -spritetype sprite[MAXSPRITES]; int32_t r_rortexture = 0; int32_t r_rortexturerange = 0; diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 8ea67bcb0..e8103d231 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -17,6 +17,11 @@ public: DCoreActor* prevStat, * nextStat; DCoreActor* prevSect, * nextSect; + spritetype spr; + spriteext_t sprext; + spritesmooth_t spsmooth; + + virtual ~DCoreActor() = default; virtual void Serialize(FSerializer& arc); @@ -25,19 +30,34 @@ public: return (unsigned)s().statnum < MAXSTATUS; } - spritetype& s() const + const spritetype& s() const { - return sprite[index]; + return spr; } - spriteext_t& sx() const + spritetype& s() { - return spriteext[index]; + return spr; } - spritesmooth_t& sm() const + const spriteext_t& sx() const { - return spritesmooth[index]; + return sprext; + } + + spriteext_t& sx() + { + return sprext; + } + + const spritesmooth_t& sm() const + { + return spsmooth; + } + + spritesmooth_t& sm() + { + return spsmooth; } int GetIndex() const diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 8899a917c..c7b8a960b 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -237,9 +237,8 @@ static void SetWallPalV5() } } -void ValidateSprite(spritetype& spr) +void ValidateSprite(spritetype& spr, int index) { - int index = int(&spr - sprite); bool bugged = false; if ((unsigned)spr.statnum >= MAXSTATUS) { @@ -297,7 +296,6 @@ static void ReadSpriteV7(FileReader& fr, spritetype& spr) spr.hitag = fr.ReadInt16(); spr.extra = fr.ReadInt16(); spr.detail = 0; - ValidateSprite(spr); } static void ReadSpriteV6(FileReader& fr, spritetype& spr) @@ -326,7 +324,6 @@ static void ReadSpriteV6(FileReader& fr, spritetype& spr) spr.extra = fr.ReadInt16(); spr.blend = 0; spr.detail = 0; - ValidateSprite(spr); } static void ReadSpriteV5(FileReader& fr, spritetype& spr) @@ -361,7 +358,6 @@ static void ReadSpriteV5(FileReader& fr, spritetype& spr) spr.xoffset = 0; spr.yoffset = 0; spr.detail = 0; - ValidateSprite(spr); } @@ -431,8 +427,6 @@ void allocateMapArrays(int numsprites) memset(sector.Data(), 0, sizeof(sectortype) * numsectors); wall.Resize(numwalls); memset(wall.Data(), 0, sizeof(walltype) * numwalls); - memset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES); - memset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES + MAXUNIQHUDID)); ClearAutomap(); } @@ -508,6 +502,8 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, case 6: ReadSpriteV6(fr, sprites.sprites[i]); break; default: ReadSpriteV7(fr, sprites.sprites[i]); break; } + ValidateSprite(sprites.sprites[i], i); + } artSetupMapArt(filename); diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index d32ce0649..151302f54 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -655,6 +655,10 @@ FSerializer &Serialize(FSerializer &arc, const char *key, walltype &c, walltype void DCoreActor::Serialize(FSerializer& arc) { // nothing here yet. + arc("sprite", spr) + ("spriteext", sprext); + + if (arc.isReading()) spsmooth = {}; } diff --git a/source/core/savegamehelp.h b/source/core/savegamehelp.h index 6ca76ade0..bce926b97 100644 --- a/source/core/savegamehelp.h +++ b/source/core/savegamehelp.h @@ -22,14 +22,6 @@ void M_Autosave(); #define SAVEGAME_EXT ".dsave" -template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, spritetype*& w, spritetype** def) -{ - int ndx = w ? int(w - sprite) : -1; - arc(keyname, ndx); - w = ndx == -1 ? nullptr : sprite + ndx; - return arc; -} - template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def) { int ndx = w ? sectnum(w) : -1; diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 2374ba8e3..61acdda94 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -555,7 +555,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect pSprite->shade = load.shade; pSprite->blend = 0; pSprite->time = i; - ValidateSprite(*pSprite); + ValidateSprite(*pSprite, i); if (pSprite->extra > 0) { diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index e9413d736..1e4c5669a 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1171,14 +1171,14 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, sectortype** tsect, binan if (!player_in_camera && pp->camera_check_time_delay > 0) { - if (pp->last_camera_sp != sp) + if (pp->last_camera_act != actor) continue; } switch (sp->clipdist) { case 1: - pp->last_camera_sp = sp; + pp->last_camera_act = actor; CircleCamera(tx, ty, tz, tsect, tang, 0); found_camera = true; break; @@ -1187,7 +1187,7 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, sectortype** tsect, binan { int xvect,yvect,zvect,zdiff; - pp->last_camera_sp = sp; + pp->last_camera_act = actor; xvect = ang.bcos(-3); yvect = ang.bsin(-3); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index cdc663a7a..ad9bf6956 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -771,7 +771,7 @@ struct PLAYERstruct int ceiling_dist,floor_dist; SECTORp hi_sectp, lo_sectp; - SPRITEp last_camera_sp; + DSWActor* last_camera_act; int circle_camera_dist; int six,siy,siz; // save player interp position for PlayerSprite int16_t siang; diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index a3516098a..381ee02b5 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -459,7 +459,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYERstruct& w, P ("lo_sectp", w.lo_sectp) ("hi_sp", w.highActor) ("lo_sp", w.lowActor) - ("last_camera_sp", w.last_camera_sp) + ("last_camera_sp", w.last_camera_act) ("circle_camera_dist", w.circle_camera_dist) ("six", w.six) ("siy", w.siy)