Skip to content

Commit

Permalink
Fixed ViewPos not properly backing up when predicting
Browse files Browse the repository at this point in the history
Also now forcibly creates the object on players when they spawn so their pointer won't get lost when predicting.
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Apr 29, 2024
1 parent 2643a4a commit 48eb848
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/playsim/p_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ static TArray<msecnode_t *> PredictionPortalSectors_sprev_Backup;
static TArray<FLinePortal *> PredictionPortalLinesBackup;
static TArray<portnode_t *> PredictionPortalLines_sprev_Backup;

struct
{
DVector3 Pos = {};
int Flags = 0;
} static PredictionViewPosBackup;

// [GRB] Custom player classes
TArray<FPlayerClass> PlayerClasses;

Expand Down Expand Up @@ -1443,6 +1449,14 @@ void P_PredictPlayer (player_t *player)
PredictionActorBackupArray.Resize(act->GetClass()->Size);
memcpy(PredictionActorBackupArray.Data(), &act->snext, act->GetClass()->Size - ((uint8_t *)&act->snext - (uint8_t *)act));

// Since this is a DObject it needs to have its fields backed up manually for restore, otherwise any changes
// to it will be permanent while predicting. This is now auto-created on pawns to prevent creation spam.
if (act->ViewPos != nullptr)
{
PredictionViewPosBackup.Pos = act->ViewPos->Offset;
PredictionViewPosBackup.Flags = act->ViewPos->Flags;
}

act->flags &= ~MF_PICKUP;
act->flags2 &= ~MF2_PUSHWALL;
player->cheats |= CF_PREDICTING;
Expand Down Expand Up @@ -1580,6 +1594,12 @@ void P_UnPredictPlayer ()
act->UnlinkFromWorld(&ctx);
memcpy(&act->snext, PredictionActorBackupArray.Data(), PredictionActorBackupArray.Size() - ((uint8_t *)&act->snext - (uint8_t *)act));

if (act->ViewPos != nullptr)
{
act->ViewPos->Offset = PredictionViewPosBackup.Pos;
act->ViewPos->Flags = PredictionViewPosBackup.Flags;
}

// The blockmap ordering needs to remain unchanged, too.
// Restore sector links and refrences.
// [ED850] This is somewhat of a duplicate of LinkToWorld(), but we need to keep every thing the same,
Expand Down
3 changes: 3 additions & 0 deletions wadsrc/static/zscript/actors/player/player.zs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class PlayerPawn : Actor

override void BeginPlay()
{
// Force create this since players can predict.
SetViewPos((0.0, 0.0, 0.0));

Super.BeginPlay ();
ChangeStatNum (STAT_PLAYER);
FullHeight = Height;
Expand Down

0 comments on commit 48eb848

Please sign in to comment.