- pass map start as DVector3

This commit is contained in:
Christoph Oelckers 2022-08-23 23:36:23 +02:00
parent 40312d64c8
commit d573ba4cad
18 changed files with 64 additions and 92 deletions

View file

@ -432,14 +432,14 @@ void fixSectors()
}
}
void validateStartSector(const char* filename, const vec3_t& pos, int* cursectnum, unsigned numsectors, bool noabort)
void validateStartSector(const char* filename, const DVector3& pos, int* cursectnum, unsigned numsectors, bool noabort)
{
if ((unsigned)(*cursectnum) >= numsectors)
{
sectortype* sect = nullptr;
updatesectorz(pos.X, pos.Y, pos.Z, &sect);
if (!sect) updatesector(pos.X, pos.Y, &sect);
updatesectorz(pos, &sect);
if (!sect) updatesector(pos, &sect);
if (sect || noabort)
{
Printf(PRINT_HIGH, "Error in map %s: Start sector %d out of range. Max. sector is %d\n", filename, *cursectnum, numsectors);
@ -454,7 +454,7 @@ void validateStartSector(const char* filename, const vec3_t& pos, int* cursectnu
}
void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites)
void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites)
{
inputState.ClearAllInput();
@ -466,9 +466,9 @@ void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cu
I_Error("%s: Invalid map format, expected 5-9, got %d", filename, mapversion);
}
pos->X = fr.ReadInt32();
pos->Y = fr.ReadInt32();
pos->Z = fr.ReadInt32();
pos->X = fr.ReadInt32() * maptoworld;
pos->Y = fr.ReadInt32() * maptoworld;
pos->Z = fr.ReadInt32() * zmaptoworld;
*ang = fr.ReadInt16() & 2047;
*cursectnum = fr.ReadUInt16();
@ -533,7 +533,7 @@ void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cu
//Must be last.
fixSectors();
updatesector(pos->X, pos->Y, cursectnum);
updatesector(*pos, cursectnum);
guniqhudid = 0;
fr.Seek(0, FileReader::SeekSet);
auto buffer = fr.Read();
@ -717,24 +717,24 @@ TArray<walltype> loadMapWalls(const char* filename)
}
void qloadboard(const char* filename, uint8_t flags, vec3_t* dapos, int16_t* daang);
void qloadboard(const char* filename, uint8_t flags, DVector3* dapos, int16_t* daang);
// loads a map into the backup buffer.
void loadMapBackup(const char* filename)
{
vec3_t pos;
DVector3 fpos;
int16_t scratch;
int scratch2;
SpawnSpriteDef scratch3;
if (isBlood())
{
qloadboard(filename, 0, &pos, &scratch);
qloadboard(filename, 0, &fpos, &scratch);
}
else
{
loadMap(filename, 0, &pos, &scratch, &scratch2, scratch3);
loadMap(filename, 0, &fpos, &scratch, &scratch2, scratch3);
}
}

View file

@ -753,8 +753,8 @@ struct SpawnSpriteDef;
void allocateMapArrays(int numwall, int numsector, int numsprites);
void validateSprite(spritetype& spr, int secno, int index);
void fixSectors();
void loadMap(const char *filename, int flags, vec3_t *pos, int16_t *ang, int *cursectnum, SpawnSpriteDef& sprites);
void loadMap(const char *filename, int flags, DVector3 *pos, int16_t *ang, int *cursectnum, SpawnSpriteDef& sprites);
TArray<walltype> loadMapWalls(const char* filename);
void loadMapBackup(const char* filename);
void loadMapHack(const char* filename, const uint8_t*, SpawnSpriteDef& sprites);
void validateStartSector(const char* filename, const vec3_t& pos, int* cursectnum, unsigned numsectors, bool noabort = false);
void validateStartSector(const char* filename, const DVector3& pos, int* cursectnum, unsigned numsectors, bool noabort = false);

View file

@ -117,6 +117,12 @@ inline void updatesector(const DVector3& pos, sectortype** const sectp)
*sectp = sectno == -1 ? nullptr : &sector[sectno];
}
// This is still needed for map startup.
inline void updatesector(const DVector3& pos, int* sectno)
{
updatesector(int(pos.X * worldtoint), int(pos.Y * worldtoint), sectno);
}
inline void updatesectorz(int x, int y, int z, sectortype** const sectp)
{
int sectno = *sectp ? sector.IndexOf(*sectp) : -1;

View file

@ -250,9 +250,8 @@ void StartLevel(MapRecord* level, bool newgame)
//drawLoadingScreen();
BloodSpawnSpriteDef sprites;
int startsectno;
vec3_t startposi;
dbLoadMap(currentLevel->fileName, (int*)&startposi.X, (int*)&startposi.Y, (int*)&startposi.Z, &startang, &startsectno, nullptr, sprites);
DVector3 startpos(startposi.X * maptoworld, startposi.Y * maptoworld, startposi.Z * maptoworld);
DVector3 startpos;
dbLoadMap(currentLevel->fileName, startpos, &startang, &startsectno, nullptr, sprites);
startsector = &sector[startsectno];
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
STAT_NewLevel(currentLevel->fileName);

View file

@ -130,7 +130,7 @@ unsigned int dbReadMapCRC(const char* pPath)
//
//---------------------------------------------------------------------------
void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int* cursectnum, unsigned int* pCRC, BloodSpawnSpriteDef& sprites)
void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* cursectnum, unsigned int* pCRC, BloodSpawnSpriteDef& sprites)
{
const int nXSectorSize = 60;
const int nXSpriteSize = 56;
@ -199,9 +199,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int*
mapHeader.numwalls = LittleShort(mapHeader.numwalls);
mapHeader.numsprites = LittleShort(mapHeader.numsprites);
*pX = mapHeader.x;
*pY = mapHeader.y;
*pZ = mapHeader.z;
pos = { mapHeader.x * maptoworld, mapHeader.y * maptoworld, mapHeader.z * zmaptoworld };
*pAngle = mapHeader.ang;
gVisibility = g_visibility = mapHeader.visibility;
gMattId = mapHeader.mattid;
@ -666,7 +664,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int*
sectionGeometry.SetSize(sections.Size());
wallbackup = wall;
sectorbackup = sector;
validateStartSector(mapname.GetChars(), { *pX, *pY, *pZ }, cursectnum, mapHeader.numsectors, true);
validateStartSector(mapname.GetChars(), pos, cursectnum, mapHeader.numsectors, true);
}
@ -678,9 +676,9 @@ END_BLD_NS
//
//---------------------------------------------------------------------------
void qloadboard(const char* filename, uint8_t flags, vec3_t* dapos, int16_t* daang)
void qloadboard(const char* filename, uint8_t flags, DVector3* dapos, int16_t* daang)
{
Blood::BloodSpawnSpriteDef sprites;
int sp;
Blood::dbLoadMap(filename, &dapos->X, &dapos->Y, &dapos->Z, daang, &sp, nullptr, sprites);
Blood::dbLoadMap(filename, *dapos, daang, &sp, nullptr, sprites);
}

View file

@ -101,7 +101,7 @@ DBloodActor* InsertSprite(sectortype* pSector, int nStat);
int DeleteSprite(DBloodActor* actor);
unsigned int dbReadMapCRC(const char* pPath);
void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int* pSector, unsigned int* pCRC, BloodSpawnSpriteDef& sprites);
void dbLoadMap(const char* pPath, DVector3& pos, short* pAngle, int* pSector, unsigned int* pCRC, BloodSpawnSpriteDef& sprites);
END_BLD_NS

View file

@ -1003,9 +1003,9 @@ static int LoadTheMap(MapRecord *mi, player_struct*p, int gamemode)
currentLevel = mi;
int sect;
SpawnSpriteDef sprites;
vec3_t pos;
DVector3 pos;
loadMap(mi->fileName, isShareware(), &pos, &lbang, &sect, sprites);
p->pos = { pos.X * inttoworld, pos.Y * inttoworld, pos.Z * zinttoworld };
p->pos = pos;
p->cursector = &sector[sect];
SECRET_SetMapName(mi->DisplayName(), mi->name);

View file

@ -52,9 +52,7 @@ enum {
kSectLava = 0x4000,
};
extern int initx;
extern int inity;
extern int initz;
extern DVector3 initpos;
extern int16_t inita;
extern sectortype* initsectp;

View file

@ -39,7 +39,7 @@ enum
kTagRamses = 61,
};
int initx, inity, initz;
DVector3 initpos;
int16_t inita;
sectortype* initsectp;
@ -140,13 +140,9 @@ uint8_t LoadLevel(MapRecord* map)
nStopSound = 66;
}
vec3_t startPos;
int initsect;
SpawnSpriteDef spawned;
loadMap(currentLevel->fileName, 0, &startPos, &inita, &initsect, spawned);
initx = startPos.X;
inity = startPos.Y;
initz = startPos.Z;
loadMap(currentLevel->fileName, 0, &initpos, &inita, &initsect, spawned);
initsectp = &sector[initsect];
auto actors = spawnactors(spawned);
@ -175,7 +171,7 @@ void InitLevel(MapRecord* map)
for (int i = 0; i < nTotalPlayers; i++)
{
SetSavePoint(i, initx, inity, initz, initsectp, inita);
SetSavePoint(i, initpos, initsectp, inita);
RestartPlayer(i);
InitPlayerKeys(i);
}
@ -750,7 +746,7 @@ void ExamineSprites(TArray<DExhumedActor*>& actors)
{
auto pActor = insertActor(initsectp, 0);
pActor->set_int_pos({ initx, inity, initz });
pActor->spr.pos = initpos;
pActor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
nNetStartSprite[nNetStartSprites] = pActor;
nNetStartSprites++;
@ -813,18 +809,14 @@ void LoadObjects(TArray<DExhumedActor*>& actors)
runlist_ReadyChannel(nChannel);
}
nCamerax = initx;
nCameray = inity;
nCameraz = initz;
nCamera = initpos;
}
void SerializeInit(FSerializer& arc)
{
if (arc.BeginObject("init"))
{
arc("initx", initx)
("inity", inity)
("initz", initz)
arc("init", initpos)
("inita", inita)
("initsect", initsectp)
("curchunk", nCurChunkNum)

View file

@ -1055,9 +1055,7 @@ void MoveSector(sectortype* pSector, int nAngle, int *nXVel, int *nYVel)
TODO: Might need to be done elsewhere too?
*/
auto pActor = PlayerList[nLocalPlayer].pActor;
initx = pActor->int_pos().X;
inity = pActor->int_pos().Y;
initz = pActor->int_pos().Z;
initpos = pActor->spr.pos;
inita = pActor->int_ang();
initsectp = pActor->sector();
}

View file

@ -71,7 +71,6 @@ static int osdcmd_spawn(CCmdFuncPtr parm)
if (parm->numparms != 1) return CCMD_SHOWHELP;
auto c = parm->parms[0];
auto sectp = initsectp;
DVector3 initpos = { initx * inttoworld, inity * inttoworld, sectp->floorz };
if (!stricmp(c, "anubis")) BuildAnubis(nullptr, initpos, sectp, inita, false);
else if (!stricmp(c, "spider")) BuildSpider(nullptr, initpos, sectp, inita);
else if (!stricmp(c, "mummy")) BuildMummy(nullptr, initpos, sectp, inita);

View file

@ -101,11 +101,9 @@ size_t MarkPlayers()
return 5 * kMaxPlayers;
}
void SetSavePoint(int nPlayer, int x, int y, int z, sectortype* pSector, int nAngle)
void SetSavePoint(int nPlayer, const DVector3& pos, sectortype* pSector, int nAngle)
{
PlayerList[nPlayer].sPlayerSave.x = x;
PlayerList[nPlayer].sPlayerSave.y = y;
PlayerList[nPlayer].sPlayerSave.z = z;
PlayerList[nPlayer].sPlayerSave.pos = pos;
PlayerList[nPlayer].sPlayerSave.pSector = pSector;
PlayerList[nPlayer].sPlayerSave.nAngle = nAngle;
}
@ -278,7 +276,8 @@ void RestartPlayer(int nPlayer)
}
else
{
pActor->set_int_pos({ plr->sPlayerSave.x, plr->sPlayerSave.y, plr->sPlayerSave.pSector->int_floorz() });
pActor->spr.pos.XY() = plr->sPlayerSave.pos.XY();
pActor->spr.pos.Z = plr->sPlayerSave.pSector->floorz;
plr->angle.ang = DAngle::fromBuild(plr->sPlayerSave.nAngle&kAngleMask);
pActor->spr.angle = plr->angle.ang;
@ -2172,7 +2171,7 @@ sectdone:
ChangeActorStat(pActorB, 899);
}
SetSavePoint(nPlayer, pPlayerActor->int_pos().X, pPlayerActor->int_pos().Y, pPlayerActor->int_pos().Z, pPlayerActor->sector(), pPlayerActor->int_ang());
SetSavePoint(nPlayer, pPlayerActor->spr.pos, pPlayerActor->sector(), pPlayerActor->int_ang());
break;
}
@ -2516,9 +2515,7 @@ sectdone:
// loc_1C3B4:
if (nPlayer == nLocalPlayer)
{
initx = pPlayerActor->int_pos().X;
inity = pPlayerActor->int_pos().Y;
initz = pPlayerActor->int_pos().Z;
initpos = pPlayerActor->spr.pos;
initsectp = pPlayerActor->sector();
inita = pPlayerActor->int_ang();
}
@ -2643,9 +2640,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerSave& w, Pla
{
if (arc.BeginObject(keyname))
{
arc("x", w.x)
("y", w.y)
("z", w.z)
arc("pos", w.pos)
("sector", w.pSector)
("angle", w.nAngle)
.EndObject();

View file

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
void SetSavePoint(int nPlayer, int x, int y, int z, sectortype* pSector, int nAngle);
void SetSavePoint(int nPlayer, const DVector3& pos, sectortype* pSector, int nAngle);
void InitPlayer();
void InitPlayerKeys(int nPlayer);
int GrabPlayer();
@ -46,9 +46,7 @@ extern int lPlayerYVel;
struct PlayerSave
{
sectortype* pSector;
int x;
int y;
int z;
DVector3 pos;
int16_t nAngle;
};

View file

@ -479,7 +479,7 @@ int seq_GetSeqPicnum(int16_t nSeq, int16_t edx, int16_t ebx)
int seq_PlotArrowSequence(int nSprite, int16_t nSeq, int nVal)
{
tspritetype* pTSprite = mytspriteArray->get(nSprite);
int nAngle = getangle(nCamerax - pTSprite->int_pos().X, nCameray - pTSprite->int_pos().Y);
int nAngle = getangle(nCamera.XY() - pTSprite->pos.XY());
int nSeqOffset = ((((pTSprite->int_ang() + 512) - nAngle) + 128) & kAngleMask) >> 8;
@ -527,7 +527,7 @@ int seq_PlotArrowSequence(int nSprite, int16_t nSeq, int nVal)
int seq_PlotSequence(int nSprite, int16_t edx, int16_t nFrame, int16_t ecx)
{
tspritetype* pTSprite = mytspriteArray->get(nSprite);
int nAngle = getangle(nCamerax - pTSprite->int_pos().X, nCameray - pTSprite->int_pos().Y);
int nAngle = getangle(nCamera.XY() - pTSprite->pos.XY());
int val;
@ -619,7 +619,7 @@ int seq_PlotSequence(int nSprite, int16_t edx, int16_t nFrame, int16_t ecx)
auto pSector =pTSprite->sectp;
int nFloorZ = pSector->int_floorz();
if (nFloorZ <= PlayerList[nLocalPlayer].eyelevel + initz) {
if (nFloorZ <= PlayerList[nLocalPlayer].eyelevel + int(initpos.Z * worldtoint)) {
pTSprite->ownerActor = nullptr;
}
else

View file

@ -425,15 +425,15 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3],
{
if (pos != nullptr)
{
vec3_t campos;
DVector3 campos;
if (nSnakeCam > -1)
{
Snake* pSnake = &SnakeList[nSnakeCam];
campos = pSnake->pSprites[0]->int_pos();
campos = pSnake->pSprites[0]->spr.pos;
}
else
{
campos = { initx, inity, initz };
campos = initpos;
}
auto fcampos = GetSoundPos(campos);
@ -477,7 +477,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3],
assert(actor != nullptr);
if (actor != nullptr)
{
*pos = GetSoundPos(actor->int_pos());
*pos = GetSoundPos(actor->spr.pos);
}
}
if ((chanflags & CHANF_LISTENERZ) && type != SOURCE_None)
@ -498,20 +498,19 @@ void GameInterface::UpdateSounds()
if (nFreeze)
return;
vec3_t pos;
DVector3 pos;
int ang;
if (nSnakeCam > -1)
{
Snake *pSnake = &SnakeList[nSnakeCam];
pos = pSnake->pSprites[0]->int_pos();
pos = pSnake->pSprites[0]->spr.pos;
ang = pSnake->pSprites[0]->int_ang();
}
else
{
pos = { initx, inity, initz };
pos = initpos;
ang = inita;
}
auto fv = GetSoundPos(pos);
SoundListener listener;
listener.angle = float(-ang * BAngRadian); // Build uses a period of 2048.
listener.velocity.Zero();

View file

@ -39,11 +39,7 @@ bool bSubTitles = true;
int zbob;
int16_t dVertPan[kMaxPlayers];
int nCamerax;
int nCameray;
int nCameraz;
DVector3 nCamera;
bool bTouchFloor;
int16_t nQuake[kMaxPlayers] = { 0 };
@ -291,9 +287,7 @@ void DrawView(double smoothRatio, bool sceneonly)
}
}
}
nCamerax = playerX;
nCameray = playerY;
nCameraz = playerZ;
nCamera = DVector3(playerX * inttoworld, playerY * inttoworld, playerZ * zinttoworld);
if (pSector != nullptr)
{
@ -346,7 +340,7 @@ void DrawView(double smoothRatio, bool sceneonly)
if (!nFreeze && !sceneonly)
DrawWeapons(smoothRatio);
render_drawrooms(nullptr, { nCamerax, nCameray, viewz }, sectnum(pSector), nCameraa, nCamerapan, rotscrnang, smoothRatio);
render_drawrooms(nullptr, { int(nCamera.X * worldtoint), int(nCamera.Y * worldtoint), viewz }, sectnum(pSector), nCameraa, nCamerapan, rotscrnang, smoothRatio);
if (HavePLURemap())
{
@ -460,9 +454,7 @@ void SerializeView(FSerializer& arc)
{
if (arc.BeginObject("view"))
{
arc("camerax", nCamerax)
("cameray", nCameray)
("cameraz", nCameraz)
arc("camera", nCamera)
("touchfloor", bTouchFloor)
("chunktotal", nChunkTotal)
("cameraa", nCameraa)

View file

@ -33,9 +33,7 @@ void Clip();
extern int16_t dVertPan[];
extern int16_t nQuake[];
extern int nCamerax;
extern int nCameray;
extern int nCameraz;
extern DVector3 nCamera;
extern bool bTouchFloor;
extern int nChunkTotal;
extern int gFov;

View file

@ -403,9 +403,9 @@ void InitLevel(MapRecord *maprec)
currentLevel = maprec;
int cursect;
SpawnSpriteDef sprites;
vec3_t ppos;
DVector3 ppos;
loadMap(maprec->fileName, SW_SHAREWARE ? 1 : 0, &ppos, &ang, &cursect, sprites);
Player[0].set_int_ppos(ppos);
Player[0].pos = ppos;
spawnactors(sprites);
Player[0].cursector = &sector[cursect];