- SW: Swap out the internals of the player's pos methods and get the game going again.

* Leave `PLAYER::PlayerOldPosition` for now.
This commit is contained in:
Mitchell Richters 2022-11-23 18:08:35 +11:00 committed by Christoph Oelckers
parent c14d1587f0
commit 6d736aea19
9 changed files with 51 additions and 53 deletions

View file

@ -1240,7 +1240,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly)
} }
// Get initial player position, interpolating if required. // Get initial player position, interpolating if required.
DVector3 tpos = interpolatedvalue(camerapp->posprevGet(), camerapp->posGet(), interpfrac); DVector3 tpos = camerapp->actor->getRenderPos(interpfrac);
if (SyncInput() || pp != Player+myconnectindex) if (SyncInput() || pp != Player+myconnectindex)
{ {
tang = camerapp->angle.interpolatedsum(interpfrac); tang = camerapp->angle.interpolatedsum(interpfrac);

View file

@ -408,7 +408,6 @@ void InitLevel(MapRecord *maprec)
SpawnSpriteDef sprites; SpawnSpriteDef sprites;
DVector3 ppos; DVector3 ppos;
loadMap(maprec->fileName, SW_SHAREWARE ? 1 : 0, &ppos, &ang, &cursect, sprites); loadMap(maprec->fileName, SW_SHAREWARE ? 1 : 0, &ppos, &ang, &cursect, sprites);
Player[0].posSet(ppos);
spawnactors(sprites); spawnactors(sprites);
Player[0].cursector = cursect; Player[0].cursector = cursect;
@ -434,8 +433,8 @@ void InitLevel(MapRecord *maprec)
QueueReset(); QueueReset();
PreMapCombineFloors(); PreMapCombineFloors();
InitMultiPlayerInfo(); InitMultiPlayerInfo(ppos);
InitAllPlayerSprites(); InitAllPlayerSprites(ppos);
// //
// Do setup for sprite, track, panel, sector, etc // Do setup for sprite, track, panel, sector, etc

View file

@ -1708,9 +1708,7 @@ BEGIN_SW_NS
struct PLAYER struct PLAYER
{ {
// variable that fit in the sprite or user structure DVector3 PlayerOldPosition;
DVector3 PlayerNowPosition, PlayerPrevPosition, PlayerOldPosition;
DSWActor* actor; // this may not be a TObjPtr! DSWActor* actor; // this may not be a TObjPtr!
TObjPtr<DSWActor*> lowActor, highActor; TObjPtr<DSWActor*> lowActor, highActor;
@ -1889,52 +1887,52 @@ struct PLAYER
DVector2& posXY() DVector2& posXY()
{ {
return PlayerNowPosition.XY(); return actor->spr.pos.XY();
} }
void posZset(const double val) void posZset(const double val)
{ {
PlayerNowPosition.Z = val; actor->spr.pos.Z = val - actor->viewzoffset;
} }
void posZadd(const double val) void posZadd(const double val)
{ {
PlayerNowPosition.Z += val; actor->spr.pos.Z += val;
} }
double posZget() double posZget()
{ {
return PlayerNowPosition.Z; return actor->spr.pos.Z + actor->viewzoffset;
} }
void posSet(const DVector3& val) void posSet(const DVector3& val)
{ {
PlayerNowPosition = val; actor->spr.pos = val.plusZ(-actor->viewzoffset);
} }
void posAdd(const DVector2& val) void posAdd(const DVector2& val)
{ {
PlayerNowPosition += val; actor->spr.pos += val;
} }
DVector3 posGet() DVector3 posGet()
{ {
return PlayerNowPosition; return actor->spr.pos.plusZ(actor->viewzoffset);
} }
DVector2& posprevXY() DVector2& posprevXY()
{ {
return PlayerPrevPosition.XY(); return actor->opos.XY();
} }
void posprevZset(const double val) void posprevZset(const double val)
{ {
PlayerPrevPosition.Z = val; actor->opos.Z = val - actor->viewzoffset;
} }
void posprevSet(const DVector3& val) void posprevSet(const DVector3& val)
{ {
PlayerPrevPosition = val; actor->opos = val.plusZ(-actor->viewzoffset);
} }
DVector3 posprevGet() DVector3 posprevGet()
{ {
return PlayerPrevPosition; return actor->opos.plusZ(actor->viewzoffset);
} }
DVector2& posoldXY() DVector2& posoldXY()

View file

@ -71,8 +71,8 @@ int DoActorSectorDamage(DSWActor* actor);
int DoScaleSprite(DSWActor* actor); int DoScaleSprite(DSWActor* actor);
int DoActorStopFall(DSWActor* actor); int DoActorStopFall(DSWActor* actor);
void InitPlayerSprite(PLAYER* pp); void InitPlayerSprite(PLAYER* pp, const DVector3& spawnpos);
void InitAllPlayerSprites(void); void InitAllPlayerSprites(const DVector3& spawnpos);
void PlayerPanelSetup(void); void PlayerPanelSetup(void);
void PlayerDeathReset(PLAYER* pp); void PlayerDeathReset(PLAYER* pp);
void SpawnPlayerUnderSprite(PLAYER* pp); void SpawnPlayerUnderSprite(PLAYER* pp);

View file

@ -2166,13 +2166,13 @@ int DoNinjaCeiling(DSWActor* actor)
// too convienent to put it here. // too convienent to put it here.
// //
void InitAllPlayerSprites(void) void InitAllPlayerSprites(const DVector3& spawnpos)
{ {
short i; short i;
TRAVERSE_CONNECT(i) TRAVERSE_CONNECT(i)
{ {
InitPlayerSprite(Player + i); InitPlayerSprite(Player + i, spawnpos);
} }
} }
@ -2385,14 +2385,24 @@ extern ACTOR_ACTION_SET PlayerNinjaActionSet;
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void InitPlayerSprite(PLAYER* pp) void InitPlayerSprite(PLAYER* pp, const DVector3& spawnpos)
{ {
int pnum = int(pp - Player); int pnum = int(pp - Player);
double fz,cz;
extern bool NewGame; extern bool NewGame;
COVER_SetReverb(0); // Turn off any echoing that may have been going before COVER_SetReverb(0); // Turn off any echoing that may have been going before
pp->Reverb = 0; pp->Reverb = 0;
auto actor = SpawnActor(STAT_PLAYER0 + pnum, NINJA_RUN_R0, nullptr, pp->cursector, pp->posGet(), pp->angle.ang); auto actor = SpawnActor(STAT_PLAYER0 + pnum, NINJA_RUN_R0, nullptr, pp->cursector, spawnpos.plusZ(PLAYER_HEIGHTF), pp->angle.ang);
actor->viewzoffset = -PLAYER_HEIGHTF;
// if too close to the floor - stand up
calcSlope(pp->cursector, actor->getPosWithOffsetZ(), &cz, &fz);
if (actor->spr.pos.Z > fz)
{
actor->spr.pos.Z = fz;
}
actor->backuppos();
pp->actor = actor; pp->actor = actor;
pp->pnum = pnum; pp->pnum = pnum;

View file

@ -1859,10 +1859,6 @@ void UpdatePlayerSprite(PLAYER* pp)
DSWActor* actor = pp->actor; DSWActor* actor = pp->actor;
if (!actor) return; if (!actor) return;
// Update sprite representation of player
actor->spr.pos.XY() = pp->posXY();
// there are multiple death functions // there are multiple death functions
if (pp->Flags & (PF_DEAD)) if (pp->Flags & (PF_DEAD))
{ {
@ -6137,14 +6133,10 @@ void DoPlayerDeathCheckKeys(PLAYER* pp)
InitBloodSpray(plActor,true,-1); InitBloodSpray(plActor,true,-1);
} }
PlayerSpawnPosition(pp);
NewStateGroup(plActor, plActor->user.ActorActionSet->Stand); NewStateGroup(plActor, plActor->user.ActorActionSet->Stand);
plActor->spr.picnum = plActor->user.State->Pic; plActor->spr.picnum = plActor->user.State->Pic;
plActor->spr.picnum = plActor->user.State->Pic; plActor->spr.picnum = plActor->user.State->Pic;
plActor->spr.scale = DVector2(PLAYER_NINJA_XREPEAT, PLAYER_NINJA_XREPEAT);
plActor->spr.cstat &= ~(CSTAT_SPRITE_YCENTER); plActor->spr.cstat &= ~(CSTAT_SPRITE_YCENTER);
plActor->spr.pos = pp->posGet().plusZ(PLAYER_HEIGHTF);
plActor->spr.angle = pp->angle.ang; plActor->spr.angle = pp->angle.ang;
DoSpawnTeleporterEffect(plActor); DoSpawnTeleporterEffect(plActor);
@ -6165,7 +6157,6 @@ void DoPlayerDeathCheckKeys(PLAYER* pp)
plActor->spr.scale = DVector2(PLAYER_NINJA_XREPEAT, PLAYER_NINJA_YREPEAT); plActor->spr.scale = DVector2(PLAYER_NINJA_XREPEAT, PLAYER_NINJA_YREPEAT);
pp->horizon.horiz = nullAngle; pp->horizon.horiz = nullAngle;
DoPlayerResetMovement(pp);
plActor->user.ID = NINJA_RUN_R0; plActor->user.ID = NINJA_RUN_R0;
PlayerDeathReset(pp); PlayerDeathReset(pp);
@ -7186,8 +7177,6 @@ void InitAllPlayers(void)
// Initialize all [MAX_SW_PLAYERS] arrays here! // Initialize all [MAX_SW_PLAYERS] arrays here!
for (pp = Player; pp < &Player[MAX_SW_PLAYERS]; pp++) for (pp = Player; pp < &Player[MAX_SW_PLAYERS]; pp++)
{ {
pp->posSet(pfirst->posGet());
pp->posprevSet(pfirst->posGet());
pp->angle.ang = pp->angle.oang = pfirst->angle.ang; pp->angle.ang = pp->angle.oang = pfirst->angle.ang;
pp->horizon.horiz = pp->horizon.ohoriz = pfirst->horizon.horiz; pp->horizon.horiz = pp->horizon.ohoriz = pfirst->horizon.horiz;
pp->cursector = pfirst->cursector; pp->cursector = pfirst->cursector;
@ -7196,7 +7185,6 @@ void InitAllPlayers(void)
//pp->MaxHealth = 100; //pp->MaxHealth = 100;
pp->posoldXY().Zero();
pp->climb_ndx = 10; pp->climb_ndx = 10;
pp->KillerActor = nullptr; pp->KillerActor = nullptr;
pp->Kills = 0; pp->Kills = 0;
@ -7287,7 +7275,6 @@ void PlayerSpawnPosition(PLAYER* pp)
{ {
short pnum = short(pp - Player); short pnum = short(pp - Player);
short pos_num = pnum; short pos_num = pnum;
double fz,cz;
int i; int i;
DSWActor* spawn_sprite = nullptr; DSWActor* spawn_sprite = nullptr;
@ -7346,17 +7333,14 @@ void PlayerSpawnPosition(PLAYER* pp)
ASSERT(spawn_sprite != nullptr); ASSERT(spawn_sprite != nullptr);
pp->posSet(spawn_sprite->spr.pos);
pp->posprevSet(pp->posGet());
pp->angle.ang = pp->angle.oang = spawn_sprite->spr.angle; pp->angle.ang = pp->angle.oang = spawn_sprite->spr.angle;
pp->setcursector(spawn_sprite->sector()); pp->setcursector(spawn_sprite->sector());
calcSlope(pp->cursector, pp->posGet(), &cz, &fz); if (pp->actor)
// if too close to the floor - stand up
if (pp->posZget() > fz - PLAYER_HEIGHTF)
{ {
pp->posZset(fz - PLAYER_HEIGHTF); pp->actor->spr.pos = spawn_sprite->spr.pos;
pp->posprevZset(pp->posZget()); pp->actor->viewzoffset = spawn_sprite->viewzoffset;
pp->actor->backuppos();
} }
} }
@ -7366,12 +7350,13 @@ void PlayerSpawnPosition(PLAYER* pp)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void InitMultiPlayerInfo(void) void InitMultiPlayerInfo(const DVector3& spawnpos)
{ {
PLAYER* pp; PLAYER* pp;
short pnum; short pnum;
unsigned stat; unsigned stat;
int tag; int tag;
double fz,cz;
static short MultiStatList[] = static short MultiStatList[] =
{ {
STAT_MULTI_START, STAT_MULTI_START,
@ -7411,7 +7396,16 @@ void InitMultiPlayerInfo(void)
continue; continue;
} }
auto start0 = SpawnActor(MultiStatList[stat], ST1, nullptr, pp->cursector, pp->posGet(), pp->angle.ang); auto start0 = SpawnActor(MultiStatList[stat], ST1, nullptr, pp->cursector, spawnpos.plusZ(PLAYER_HEIGHTF), pp->angle.ang);
start0->viewzoffset = -PLAYER_HEIGHTF;
// if too close to the floor - stand up
calcSlope(pp->cursector, start0->getPosWithOffsetZ(), &cz, &fz);
if (start0->spr.pos.Z > fz)
{
start0->spr.pos.Z = fz;
}
start0->backuppos();
start0->clearUser(); start0->clearUser();
start0->spr.picnum = ST1; start0->spr.picnum = ST1;
} }

View file

@ -126,7 +126,7 @@ void HeadBobStateControl(void);
void DoPlayer(void); void DoPlayer(void);
void domovethings(void); void domovethings(void);
void InitAllPlayers(void); void InitAllPlayers(void);
void InitMultiPlayerInfo(void); void InitMultiPlayerInfo(const DVector3& spawnpos);
void MoveScrollMode2D(PLAYER* pp, ControlInfo* const hidInput); void MoveScrollMode2D(PLAYER* pp, ControlInfo* const hidInput);
void DoPlayerDivePalette(PLAYER* pp); void DoPlayerDivePalette(PLAYER* pp);
void DoPlayerNightVisionPalette(PLAYER* pp); void DoPlayerNightVisionPalette(PLAYER* pp);

View file

@ -435,10 +435,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER*
{ {
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))
{ {
arc("x", w.PlayerNowPosition.X) arc("lv_sectnum", w.lv_sector)
("y", w.PlayerNowPosition.Y)
("z", w.PlayerNowPosition.Z)
("lv_sectnum", w.lv_sector)
("lv_x", w.lv.X) ("lv_x", w.lv.X)
("lv_y", w.lv.Y) ("lv_y", w.lv.Y)
("lv_z", w.lv.Z) ("lv_z", w.lv.Z)

View file

@ -513,7 +513,7 @@ void SWSoundEngine::CalcPosVel(int type, const void* source, const float pt[3],
if (pos != nullptr) if (pos != nullptr)
{ {
PLAYER* pp = Player + screenpeek; PLAYER* pp = Player + screenpeek;
FVector3 campos = GetSoundPos(pp->posGet()); FVector3 campos = GetSoundPos(pp->actor ? pp->posGet() : DVector3());
DVector3 vPos = {}; DVector3 vPos = {};
bool pancheck = false; bool pancheck = false;
@ -605,7 +605,7 @@ void GameInterface::UpdateSounds(void)
listener.angle = float(-tang.Radians()); listener.angle = float(-tang.Radians());
listener.velocity.Zero(); listener.velocity.Zero();
listener.position = GetSoundPos(pp->posGet()); listener.position = GetSoundPos(pp->actor ? pp->posGet() : DVector3());
listener.underwater = false; listener.underwater = false;
// This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D.
// listenactor->waterlevel == 3; // listenactor->waterlevel == 3;