mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-22 03:31:26 +00:00
- Implement new method for applying scaled angle changes.
* This method works more accurately to how an angle change would occur under interpolated circumstances.
This commit is contained in:
parent
5a8612110d
commit
6c0493868e
7 changed files with 24 additions and 43 deletions
|
@ -354,7 +354,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P
|
||||||
if (arc.isReading())
|
if (arc.isReading())
|
||||||
{
|
{
|
||||||
w.backupViewAngles();
|
w.backupViewAngles();
|
||||||
w.resetAdjustments();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arc;
|
return arc;
|
||||||
|
|
|
@ -25,7 +25,6 @@ struct PlayerAngles
|
||||||
void doViewYaw(const ESyncBits actions);
|
void doViewYaw(const ESyncBits actions);
|
||||||
|
|
||||||
// General methods.
|
// General methods.
|
||||||
void resetAdjustments() { Adjustments = {}; }
|
|
||||||
void backupViewAngles() { PrevViewAngles = ViewAngles; }
|
void backupViewAngles() { PrevViewAngles = ViewAngles; }
|
||||||
void setActor(DCoreActor* const actor) { pActor = actor; }
|
void setActor(DCoreActor* const actor) { pActor = actor; }
|
||||||
|
|
||||||
|
@ -65,23 +64,23 @@ struct PlayerAngles
|
||||||
// Pitch methods.
|
// Pitch methods.
|
||||||
void lockPitch() { AngleLocks.Set(PITCH); }
|
void lockPitch() { AngleLocks.Set(PITCH); }
|
||||||
void unlockPitch() { AngleLocks.Clear(PITCH); }
|
void unlockPitch() { AngleLocks.Clear(PITCH); }
|
||||||
bool lockedPitch() { return Targets.Pitch.Sgn() || AngleLocks[PITCH]; }
|
bool lockedPitch() { return AngleLocks[PITCH]; }
|
||||||
void addPitch(const DAngle value) { addAngle(PITCH, value); }
|
void addPitch(const DAngle value) { updateAngle(PITCH, ClampViewPitch(pActor->spr.Angles.Pitch + value)); }
|
||||||
void setPitch(const DAngle value, const bool backup = false) { setAngle(PITCH, ClampViewPitch(value), backup); }
|
void setPitch(const DAngle value, const bool backup = false) { updateAngle(PITCH, ClampViewPitch(value), backup); }
|
||||||
|
|
||||||
// Yaw methods.
|
// Yaw methods.
|
||||||
void lockYaw() { AngleLocks.Set(YAW); }
|
void lockYaw() { AngleLocks.Set(YAW); }
|
||||||
void unlockYaw() { AngleLocks.Clear(YAW); }
|
void unlockYaw() { AngleLocks.Clear(YAW); }
|
||||||
bool lockedYaw() { return Targets.Yaw.Sgn() || AngleLocks[YAW]; }
|
bool lockedYaw() { return AngleLocks[YAW]; }
|
||||||
void addYaw(const DAngle value) { addAngle(YAW, value); }
|
void addYaw(const DAngle value) { updateAngle(YAW, pActor->spr.Angles.Yaw + value); }
|
||||||
void setYaw(const DAngle value, const bool backup = false) { setAngle(YAW, value, backup); }
|
void setYaw(const DAngle value, const bool backup = false) { updateAngle(YAW, value, backup); }
|
||||||
|
|
||||||
// Roll methods.
|
// Roll methods.
|
||||||
void lockRoll() { AngleLocks.Set(ROLL); }
|
void lockRoll() { AngleLocks.Set(ROLL); }
|
||||||
void unlockRoll() { AngleLocks.Clear(ROLL); }
|
void unlockRoll() { AngleLocks.Clear(ROLL); }
|
||||||
bool lockedRoll() { return Targets.Roll.Sgn() || AngleLocks[ROLL]; }
|
bool lockedRoll() { return AngleLocks[ROLL]; }
|
||||||
void addRoll(const DAngle value) { addAngle(ROLL, value); }
|
void addRoll(const DAngle value) { updateAngle(ROLL, pActor->spr.Angles.Roll + value); }
|
||||||
void setRoll(const DAngle value, const bool backup = false) { setAngle(ROLL, value, backup); }
|
void setRoll(const DAngle value, const bool backup = false) { updateAngle(ROLL, value, backup); }
|
||||||
|
|
||||||
// Applicator of pending angle changes.
|
// Applicator of pending angle changes.
|
||||||
void applyScaledAdjustments(const double scaleAdjust)
|
void applyScaledAdjustments(const double scaleAdjust)
|
||||||
|
@ -90,21 +89,19 @@ struct PlayerAngles
|
||||||
{
|
{
|
||||||
if (Targets[i].Sgn())
|
if (Targets[i].Sgn())
|
||||||
{
|
{
|
||||||
const auto delta = deltaangle(pActor->spr.Angles[i], Targets[i]);
|
// Calculate scaled amount of target and add to the accumlation buffer.
|
||||||
|
DAngle addition = Targets[i] * scaleAdjust;
|
||||||
|
AppliedAmounts[i] += addition;
|
||||||
|
|
||||||
if (abs(delta.Degrees()) > BAngToDegree)
|
// Test whether we're now reached/exceeded our target.
|
||||||
|
if (abs(AppliedAmounts[i]) >= abs(Targets[i]))
|
||||||
{
|
{
|
||||||
pActor->spr.Angles[i] += delta * scaleAdjust;
|
addition -= AppliedAmounts[i] - Targets[i];
|
||||||
|
Targets[i] = AppliedAmounts[i] = nullAngle;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// Apply the scaled addition to the angle.
|
||||||
pActor->spr.Angles[i] = Targets[i];
|
pActor->spr.Angles[i] += addition;
|
||||||
Targets[i] = nullAngle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Adjustments[i].Sgn())
|
|
||||||
{
|
|
||||||
pActor->spr.Angles[i] += Adjustments[i] * scaleAdjust;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,27 +117,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Private data which should never be accessed publically.
|
// Private data which should never be accessed publically.
|
||||||
DRotator Targets, Adjustments;
|
DRotator Targets, AppliedAmounts;
|
||||||
FixedBitArray<MAXANGLES> AngleLocks;
|
FixedBitArray<MAXANGLES> AngleLocks;
|
||||||
DCoreActor* pActor;
|
DCoreActor* pActor;
|
||||||
|
|
||||||
void addAngle(const unsigned angIndex, const DAngle value)
|
// Internal angle updater to reduce boilerplate from the public setters.
|
||||||
{
|
void updateAngle(const unsigned angIndex, const DAngle value, const bool backup = false)
|
||||||
if (!SyncInput())
|
|
||||||
{
|
|
||||||
Adjustments[angIndex] += value.Normalized180();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pActor->spr.Angles[angIndex] += value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAngle(const unsigned angIndex, const DAngle value, const bool backup)
|
|
||||||
{
|
{
|
||||||
if (!SyncInput() && !backup)
|
if (!SyncInput() && !backup)
|
||||||
{
|
{
|
||||||
Targets[angIndex] = value.Sgn() ? value : minAngle;
|
Targets[angIndex] = deltaangle(pActor->spr.Angles[angIndex], value);
|
||||||
|
AppliedAmounts[angIndex] = nullAngle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1522,7 +1522,6 @@ void ProcessInput(PLAYER* pPlayer)
|
||||||
Item_JumpBoots = 3
|
Item_JumpBoots = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
pPlayer->Angles.resetAdjustments();
|
|
||||||
pPlayer->Angles.backupViewAngles();
|
pPlayer->Angles.backupViewAngles();
|
||||||
|
|
||||||
DBloodActor* actor = pPlayer->actor;
|
DBloodActor* actor = pPlayer->actor;
|
||||||
|
|
|
@ -2725,7 +2725,6 @@ void processinput_d(int snum)
|
||||||
p = &ps[snum];
|
p = &ps[snum];
|
||||||
auto pact = p->GetActor();
|
auto pact = p->GetActor();
|
||||||
|
|
||||||
p->Angles.resetAdjustments();
|
|
||||||
p->Angles.backupViewAngles();
|
p->Angles.backupViewAngles();
|
||||||
|
|
||||||
ESyncBits& actions = p->sync.actions;
|
ESyncBits& actions = p->sync.actions;
|
||||||
|
|
|
@ -3272,7 +3272,6 @@ void processinput_r(int snum)
|
||||||
auto p = &ps[snum];
|
auto p = &ps[snum];
|
||||||
auto pact = p->GetActor();
|
auto pact = p->GetActor();
|
||||||
|
|
||||||
p->Angles.resetAdjustments();
|
|
||||||
p->Angles.backupViewAngles();
|
p->Angles.backupViewAngles();
|
||||||
|
|
||||||
ESyncBits& actions = p->sync.actions;
|
ESyncBits& actions = p->sync.actions;
|
||||||
|
|
|
@ -904,7 +904,6 @@ void AIPlayer::Tick(RunListEvent* ev)
|
||||||
int nAction = PlayerList[nPlayer].nAction;
|
int nAction = PlayerList[nPlayer].nAction;
|
||||||
int nActionB = PlayerList[nPlayer].nAction;
|
int nActionB = PlayerList[nPlayer].nAction;
|
||||||
|
|
||||||
PlayerList[nPlayer].Angles.resetAdjustments();
|
|
||||||
PlayerList[nPlayer].Angles.backupViewAngles();
|
PlayerList[nPlayer].Angles.backupViewAngles();
|
||||||
|
|
||||||
pPlayerActor->vel.XY() = sPlayerInput[nPlayer].vel;
|
pPlayerActor->vel.XY() = sPlayerInput[nPlayer].vel;
|
||||||
|
|
|
@ -6991,7 +6991,6 @@ void domovethings(void)
|
||||||
|
|
||||||
// Reset flags used while tying input to framerate
|
// Reset flags used while tying input to framerate
|
||||||
pp->Flags2 &= ~(PF2_INPUT_CAN_AIM|PF2_INPUT_CAN_TURN_GENERAL|PF2_INPUT_CAN_TURN_VEHICLE|PF2_INPUT_CAN_TURN_TURRET);
|
pp->Flags2 &= ~(PF2_INPUT_CAN_AIM|PF2_INPUT_CAN_TURN_GENERAL|PF2_INPUT_CAN_TURN_VEHICLE|PF2_INPUT_CAN_TURN_TURRET);
|
||||||
pp->Angles.resetAdjustments();
|
|
||||||
pp->Angles.backupViewAngles();
|
pp->Angles.backupViewAngles();
|
||||||
|
|
||||||
// disable synchronised input if set by game.
|
// disable synchronised input if set by game.
|
||||||
|
|
Loading…
Reference in a new issue