From 6600f5554389a454945d72479d0f7f2faecc8fc8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 4 Dec 2021 12:31:54 +0100 Subject: [PATCH] - separate map loading from actor spawning for the other games, too. It still uses the horribly messed up original spawn logic, though. --- source/build/include/build.h | 4 ++- source/core/maploader.cpp | 41 +++++++++++++++++------------ source/games/blood/src/db.cpp | 4 --- source/games/duke/src/premap.cpp | 5 +++- source/games/exhumed/src/init.cpp | 4 ++- source/games/exhumed/src/object.cpp | 2 +- source/games/sw/src/game.cpp | 4 ++- source/games/sw/src/swactor.h | 1 - 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index a9eabffa2..0024f51de 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -355,10 +355,12 @@ struct SpawnSpriteDef TArray sprext; }; +[[deprecated]] +void insertAllSprites(SpawnSpriteDef& sprites); void allocateMapArrays(int numsprites); void ValidateSprite(spritetype& spr); -void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int *dacursectnum); +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/core/maploader.cpp b/source/core/maploader.cpp index 844f01922..9f347cbfe 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -40,6 +40,7 @@ #include "printf.h" #include "inputstate.h" #include "md4.h" +#include "coreactor.h" #include "gamecontrol.h" #include "gamefuncs.h" #include "sectorgeometry.h" @@ -364,15 +365,21 @@ static void ReadSpriteV5(FileReader& fr, spritetype& spr) } -static void insertAllSprites(const char* filename, const vec3_t* pos, int* cursectnum, int16_t numsprites) +void insertAllSprites(SpawnSpriteDef& sprites) { // This function is stupid because it exploits side effects of insertsprite and should be redone by only inserting the valid sprites. - int i, realnumsprites = numsprites; + int i, realnumsprites = sprites.sprites.Size(); + int numsprites = realnumsprites; for (i = 0; i < numsprites; i++) { + auto actor = actorArray[i]; bool removeit = false; - auto& spr = sprite[i]; + auto& spr = actor->s(); + spr = sprites.sprites[i]; + if (sprites.sprext.Size()) actor->sx() = sprites.sprext[i]; + else actor->sx() = {}; + actor->sm() = {}; if (spr.statnum == MAXSTATUS) { @@ -384,7 +391,7 @@ static void insertAllSprites(const char* filename, const vec3_t* pos, int* curse if (removeit) { - sprite[i].statnum = MAXSTATUS; + spr.statnum = MAXSTATUS; realnumsprites--; } } @@ -392,12 +399,17 @@ static void insertAllSprites(const char* filename, const vec3_t* pos, int* curse if (numsprites != realnumsprites) { for (i = 0; i < numsprites; i++) - if (sprite[i].statnum == MAXSTATUS) + { + auto actor = actorArray[i]; + auto& spr = actor->s(); + + if (spr.statnum == MAXSTATUS) { // Now remove it for real! - sprite[i].statnum = 0; + spr.statnum = 0; deletesprite(i); } + } } assert(realnumsprites == Numsprites); @@ -427,9 +439,8 @@ void allocateMapArrays(int numsprites) Polymost::Polymost_prepare_loadboard(); } -void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cursectnum) +void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites) { - SpawnSpriteDef sprites; inputState.ClearAllInput(); FileReader fr = fileSystem.OpenFileReader(filename); @@ -495,19 +506,14 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, { switch (mapversion) { - case 5: ReadSpriteV5(fr, sprite[i]); break; - case 6: ReadSpriteV6(fr, sprite[i]); break; - default: ReadSpriteV7(fr, sprite[i]); break; + case 5: ReadSpriteV5(fr, sprites.sprites[i]); break; + case 6: ReadSpriteV6(fr, sprites.sprites[i]); break; + default: ReadSpriteV7(fr, sprites.sprites[i]); break; } } artSetupMapArt(filename); - insertAllSprites(filename, pos, cursectnum, numsprites); - for (int i = 0; i < numsprites; i++) - { - if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48; - } //Must be last. updatesector(pos->x, pos->y, cursectnum); guniqhudid = 0; @@ -535,6 +541,7 @@ void loadMapBackup(const char* filename) vec3_t pos; int16_t scratch; int scratch2; + SpawnSpriteDef scratch3; if (isBlood()) { @@ -542,7 +549,7 @@ void loadMapBackup(const char* filename) } else { - engineLoadBoard(filename, 0, &pos, &scratch, &scratch2); + engineLoadBoard(filename, 0, &pos, &scratch, &scratch2, scratch3); initspritelists(); } } diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index d464382a4..073d56990 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -238,10 +238,6 @@ int ChangeSpriteStat(int nSprite, int nStatus) void dbInit(void) { initspritelists(); - for (int i = 0; i < kMaxSprites; i++) - { - sprite[i].cstat = 128; - } } bool drawtile2048, encrypted; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index ae93bfc1c..bc0b9ea07 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -945,7 +945,8 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode) currentLevel = mi; int sect; - engineLoadBoard(mi->fileName, isShareware(), &p->pos, &lbang, §); + SpawnSpriteDef sprites; + engineLoadBoard(mi->fileName, isShareware(), &p->pos, &lbang, §, sprites); p->cursector = §or[sect]; SECRET_SetMapName(mi->DisplayName(), mi->name); @@ -954,6 +955,8 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode) p->angle.ang = buildang(lbang); memset(gotpic, 0, sizeof(gotpic)); + + insertAllSprites(sprites); if (isRR()) prelevel_r(gamemode); else prelevel_d(gamemode); diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index cd7609c70..ffe9ec0b1 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -118,11 +118,13 @@ uint8_t LoadLevel(MapRecord* map) vec3_t startPos; int initsect; - engineLoadBoard(currentLevel->fileName, 0, &startPos, &inita, &initsect); + SpawnSpriteDef spawned; + engineLoadBoard(currentLevel->fileName, 0, &startPos, &inita, &initsect, spawned); initx = startPos.x; inity = startPos.y; initz = startPos.z; initsectp = §or[initsect]; + insertAllSprites(spawned); int i; diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index 1c4332113..9d8650e7d 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -2565,7 +2565,7 @@ void PostProcess() } } - ExhumedLinearSpriteIterator it; + ExhumedSpriteIterator it; while (auto act = it.Next()) { auto spr = &act->s(); diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 40501a659..ded379c82 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -328,7 +328,9 @@ void InitLevel(MapRecord *maprec) int16_t ang; currentLevel = maprec; int cursect; - engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &cursect); + SpawnSpriteDef sprites; + engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &cursect, sprites); + insertAllSprites(sprites); Player[0].cursector = §or[cursect]; SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 94b650277..2c4bda63f 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -52,7 +52,6 @@ inline DSWActor* DSWActor::base() { return swActors; } using SWStatIterator = TStatIterator; using SWSectIterator = TSectIterator; using SWSpriteIterator = TSpriteIterator; -using SWLinearSpriteIterator = TLinearSpriteIterator; inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DSWActor*& w, DSWActor** def)