- separate map loading from actor spawning for the other games, too.

It still uses the horribly messed up original spawn logic, though.
This commit is contained in:
Christoph Oelckers 2021-12-04 12:31:54 +01:00
parent a3493048e7
commit 6600f55543
8 changed files with 38 additions and 27 deletions

View file

@ -355,10 +355,12 @@ struct SpawnSpriteDef
TArray<spriteext_t> 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);

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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, &sect);
SpawnSpriteDef sprites;
engineLoadBoard(mi->fileName, isShareware(), &p->pos, &lbang, &sect, sprites);
p->cursector = &sector[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);

View file

@ -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 = &sector[initsect];
insertAllSprites(spawned);
int i;

View file

@ -2565,7 +2565,7 @@ void PostProcess()
}
}
ExhumedLinearSpriteIterator it;
ExhumedSpriteIterator it;
while (auto act = it.Next())
{
auto spr = &act->s();

View file

@ -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 = &sector[cursect];
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);

View file

@ -52,7 +52,6 @@ inline DSWActor* DSWActor::base() { return swActors; }
using SWStatIterator = TStatIterator<DSWActor>;
using SWSectIterator = TSectIterator<DSWActor>;
using SWSpriteIterator = TSpriteIterator<DSWActor>;
using SWLinearSpriteIterator = TLinearSpriteIterator<DSWActor>;
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DSWActor*& w, DSWActor** def)