Skip to content

Commit

Permalink
Revert "- Simplify PlayerHorizon::settarget() by adding a dedicated…
Browse files Browse the repository at this point in the history
… angle setter that resets interpolated value as well."

This reverts commit 0416834.

Revert "- Simplify `PlayerAngle::settarget()` by adding a dedicated angle setter that resets interpolated value as well."

This reverts commit 5a55061.

Revert "- Add bool `lock` to `PlayerHorizon::settarget()` when setting target from the ticker without having to call setters and resetters."

This reverts commit 18541d1.

Revert "- Add bool `lock` to `PlayerAngle::settarget()` when setting target from the ticker without having to call setters and resetters."

This reverts commit 1ac58dc.

* We need to ensure only the ticker can unlock the player's input if it's telling us to lock the input.
  • Loading branch information
mjr4077au committed Jun 6, 2022
1 parent 0359d49 commit 71fb919
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
24 changes: 10 additions & 14 deletions source/core/gameinput.h
Expand Up @@ -55,14 +55,13 @@ struct PlayerHorizon
fixedhoriz sum() { return horiz + horizoff; }
fixedhoriz interpolatedsum(double const smoothratio) { return interpolatedhorizon(osum(), sum(), smoothratio); }

// Setter to force horizon and its interpolation companion.
void setvalue(fixedhoriz const value) { ohoriz = horiz = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax())); }

// Ticrate playsim adjustment helpers.
void resetadjustment() { adjustment = 0; }
bool targetset() { return target.asq16(); }

// Input locking helpers.
void lockinput() { inputdisabled = true; }
void unlockinput() { inputdisabled = false; }
bool movementlocked() { return targetset() || inputdisabled; }

// Draw code helpers.
Expand Down Expand Up @@ -96,19 +95,19 @@ struct PlayerHorizon
}
}

void settarget(fixedhoriz value, bool const lock = false)
void settarget(fixedhoriz value, bool const backup = false)
{
// Clamp incoming variable because sometimes the caller can exceed bounds.
value = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));

if (!SyncInput())
if (!SyncInput() && !backup)
{
inputdisabled = lock;
target = value.asq16() ? value : q16horiz(1);
}
else
{
horiz = value;
if (backup) ohoriz = horiz;
}
}

Expand All @@ -126,7 +125,6 @@ struct PlayerHorizon
{
horiz = target;
target = q16horiz(0);
inputdisabled = false;
}
}
else if (adjustment)
Expand Down Expand Up @@ -172,14 +170,13 @@ struct PlayerAngle
binangle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
binangle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); }

// Setter to force angle and its interpolation companion.
void setvalue(binangle const value) { oang = ang = value; }

// Ticrate playsim adjustment helpers.
void resetadjustment() { adjustment = 0; }
bool targetset() { return target.asbam(); }

// Input locking helpers.
void lockinput() { inputdisabled = true; }
void unlockinput() { inputdisabled = false; }
bool movementlocked() { return targetset() || inputdisabled; }

// Draw code helpers.
Expand Down Expand Up @@ -214,16 +211,16 @@ struct PlayerAngle
}
}

void settarget(binangle const value, bool const lock = false)
void settarget(binangle const value, bool const backup = false)
{
if (!SyncInput())
if (!SyncInput() && !backup)
{
inputdisabled = lock;
target = value.asbam() ? value : bamang(1);
}
else
{
ang = value;
if (backup) oang = ang;
}
}

Expand All @@ -241,7 +238,6 @@ struct PlayerAngle
{
ang = target;
target = bamang(0);
inputdisabled = false;
}
}
else if (adjustment)
Expand Down
12 changes: 8 additions & 4 deletions source/games/blood/src/nnexts.cpp
Expand Up @@ -2234,7 +2234,8 @@ void trPlayerCtrlSetLookAngle(int value, PLAYER* pPlayer)
adjustment = 0;
}

pPlayer->horizon.settarget(buildfhoriz(100. * tan(adjustment * pi::pi() / 1024.)), true);
pPlayer->horizon.settarget(buildfhoriz(100. * tan(adjustment * pi::pi() * (1. / 1024.))));
pPlayer->horizon.lockinput();
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3119,7 +3120,8 @@ void useTeleportTarget(DBloodActor* sourceactor, DBloodActor* actor)
{
if (pPlayer)
{
pPlayer->angle.settarget(buildang(sourceactor->spr.ang), true);
pPlayer->angle.settarget(buildang(sourceactor->spr.ang));
pPlayer->angle.lockinput();
}
else if (isDude) sourceactor->xspr.goalAng = actor->spr.ang = sourceactor->spr.ang;
else actor->spr.ang = sourceactor->spr.ang;
Expand Down Expand Up @@ -5840,11 +5842,13 @@ bool modernTypeOperateSprite(DBloodActor* actor, EVENT& event)
if (actor->xspr.data4 != 0) break;
else if (actor->spr.flags & kModernTypeFlag1)
{
pPlayer->angle.settarget(buildang(actor->spr.ang), true);
pPlayer->angle.settarget(buildang(actor->spr.ang));
pPlayer->angle.lockinput();
}
else if (valueIsBetween(actor->xspr.data2, -kAng360, kAng360))
{
pPlayer->angle.settarget(buildang(actor->xspr.data2), true);
pPlayer->angle.settarget(buildang(actor->xspr.data2));
pPlayer->angle.lockinput();
}
break;
case 10: // 74 (de)activate powerup
Expand Down
3 changes: 3 additions & 0 deletions source/games/blood/src/player.cpp
Expand Up @@ -1781,6 +1781,9 @@ void ProcessInput(PLAYER* pPlayer)
doslopetilting(pPlayer);
}

pPlayer->angle.unlockinput();
pPlayer->horizon.unlockinput();

pPlayer->slope = -pPlayer->horizon.horiz.asq16() >> 9;
if (pInput->actions & SB_INVPREV)
{
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/triggers.cpp
Expand Up @@ -1543,7 +1543,7 @@ void OperateTeleport(sectortype* pSector)
{
playerResetInertia(pPlayer);
pPlayer->zViewVel = pPlayer->zWeaponVel = 0;
pPlayer->angle.setvalue(buildang(actor->spr.ang));
pPlayer->angle.settarget(buildang(actor->spr.ang), true);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/games/exhumed/src/player.cpp
Expand Up @@ -935,10 +935,10 @@ void AIPlayer::Tick(RunListEvent* ev)
if (nTotalPlayers <= 1)
{
auto ang = GetAngleToSprite(pPlayerActor, pSpiritSprite) & kAngleMask;
PlayerList[nPlayer].angle.setvalue(buildang(ang));
PlayerList[nPlayer].angle.settarget(buildang(ang), true);
pPlayerActor->spr.ang = ang;

PlayerList[nPlayer].horizon.setvalue(buildhoriz(0));
PlayerList[nPlayer].horizon.settarget(buildhoriz(0), true);

lPlayerXVel = 0;
lPlayerYVel = 0;
Expand Down

0 comments on commit 71fb919

Please sign in to comment.