Skip to content

Commit 8f65524

Browse files
committed
Renamed LERP to Lerp
Added Lerp overloads for Matrix/Rotation and Vector Updated Door (and Metagame?) to lerp rotation properly
1 parent baaa850 commit 8f65524

File tree

18 files changed

+117
-62
lines changed

18 files changed

+117
-62
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
<details><summary><b>Added</b></summary>
10+
11+
- `Lerp` can now be used on Vectors and Matrices/Rotations, not just numbers.
12+
13+
</details>
14+
915
<details><summary><b>Changed</b></summary>
1016

1117
- Massacre now displays the remaining kill count to each player's screen instead of just the first one.
@@ -14,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1420

1521
- Improvements to AI navigation in automovers, so they get stuck less often.
1622

23+
- `LERP` Lua binding has been deprecated, and renamed to `Lerp`.
24+
1725
</details>
1826

1927
<details><summary><b>Fixed</b></summary>

Data/Missions.rte/Activities/DecisionDay.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,8 @@ function DecisionDay:UpdateMainBunkerExternalPopoutTurrets()
20452045
if not boxData.movementTimer:IsPastSimTimeLimit() and boxData.actor then
20462046
local startPos = self.popoutTurretsData[bunkerId].turretsActivated and box.Center or box.Center + Vector(25, 25);
20472047
local endPos = self.popoutTurretsData[bunkerId].turretsActivated and box.Center + Vector(25, 25) or box.Center;
2048-
boxData.actor.Pos.X = LERP(0, 1, startPos.X, endPos.X, boxData.movementTimer.SimTimeLimitProgress);
2049-
boxData.actor.Pos.Y = LERP(0, 1, startPos.Y, endPos.Y, boxData.movementTimer.SimTimeLimitProgress);
2048+
boxData.actor.Pos.X = Lerp(0, 1, startPos.X, endPos.X, boxData.movementTimer.SimTimeLimitProgress);
2049+
boxData.actor.Pos.Y = Lerp(0, 1, startPos.Y, endPos.Y, boxData.movementTimer.SimTimeLimitProgress);
20502050
if boxData.movementSound:IsBeingPlayed() then
20512051
boxData.movementSound.Pos = boxData.actor.Pos;
20522052
else

Source/Entities/ADoor.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,13 @@ void ADoor::Update() {
452452
// Lose health when door is lost, spinning out of control until grinds to halt
453453
if (!m_Door && m_Status != DYING && m_Status != DEAD) {
454454
m_SpriteAnimMode = ALWAYSLOOP;
455-
m_SpriteAnimDuration = static_cast<int>(LERP(0, m_MaxHealth, 10.0F, static_cast<float>(m_InitialSpriteAnimDuration), m_Health));
455+
m_SpriteAnimDuration = static_cast<int>(Lerp(0, m_MaxHealth, 10.0F, static_cast<float>(m_InitialSpriteAnimDuration), m_Health));
456456

457457
if (m_DoorMoveSound) {
458458
if (!m_DoorMoveSound->IsBeingPlayed()) {
459459
m_DoorMoveSound->Play(m_Pos);
460460
}
461-
m_DoorMoveSound->SetPitch(LERP(10.0F, static_cast<float>(m_InitialSpriteAnimDuration), 2.0F, 1.0F, static_cast<float>(m_SpriteAnimDuration)));
461+
m_DoorMoveSound->SetPitch(Lerp(10.0F, static_cast<float>(m_InitialSpriteAnimDuration), 2.0F, 1.0F, static_cast<float>(m_SpriteAnimDuration)));
462462
}
463463

464464
m_Health -= 0.4F;
@@ -551,11 +551,8 @@ void ADoor::UpdateDoorAttachableActions() {
551551
m_DoorState = CLOSED;
552552
}
553553
} else {
554-
Vector updatedOffset(LERP(0, m_DoorMoveTime, startOffset.m_X, endOffset.m_X, m_DoorMoveTimer.GetElapsedSimTimeMS()), LERP(0, m_DoorMoveTime, startOffset.m_Y, endOffset.m_Y, m_DoorMoveTimer.GetElapsedSimTimeMS()));
555-
556-
// TODO: Make this work across rotation 0. Probably the best solution would be to setup an angle LERP that properly handles the 2PI border and +- angles.
557-
// TODO_MULTITHREAD: multithread branch has lerped rotation, so once that's done!
558-
float updatedAngle = LERP(0, m_DoorMoveTime, startAngle, endAngle, m_DoorMoveTimer.GetElapsedSimTimeMS());
554+
Vector updatedOffset(Lerp(0, m_DoorMoveTime, startOffset.m_X, endOffset.m_X, m_DoorMoveTimer.GetElapsedSimTimeMS()), Lerp(0, m_DoorMoveTime, startOffset.m_Y, endOffset.m_Y, m_DoorMoveTimer.GetElapsedSimTimeMS()));
555+
float updatedAngle = Lerp(0, m_DoorMoveTime, Matrix(startAngle), Matrix(endAngle), m_DoorMoveTimer.GetElapsedSimTimeMS()).GetRadAngle();
559556

560557
m_Door->SetParentOffset(updatedOffset);
561558
m_Door->SetRotAngle(m_Rotation.GetRadAngle() + (updatedAngle * GetFlipFactor()));

Source/Entities/ADoor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace RTE {
153153
protected:
154154
static Entity::ClassInfo m_sClass; //!< ClassInfo for this class.
155155

156-
int m_InitialSpriteAnimDuration; //!< This stores the original SpriteAnimDuration value so we can drive the death spin-up animation using LERP. For internal use only.
156+
int m_InitialSpriteAnimDuration; //!< This stores the original SpriteAnimDuration value so we can drive the death spin-up animation using Lerp. For internal use only.
157157

158158
std::list<ADSensor> m_Sensors; //!< All the sensors for detecting Actors approaching the door.
159159
Timer m_SensorTimer; //!< Times the exit interval.

Source/Entities/AEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ int AEmitter::GetTotalBurstSize() const {
314314
}
315315

316316
float AEmitter::GetScaledThrottle(float throttle, float multiplier) const {
317-
float throttleFactor = LERP(-1.0f, 1.0f, m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, throttle);
318-
return LERP(m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, -1.0f, 1.0f, throttleFactor * multiplier);
317+
float throttleFactor = Lerp(-1.0f, 1.0f, m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, throttle);
318+
return Lerp(m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, -1.0f, 1.0f, throttleFactor * multiplier);
319319
}
320320

321321
void AEmitter::SetFlash(Attachable* newFlash) {

Source/Entities/AEmitter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ namespace RTE {
140140

141141
/// Gets the adjusted throttle multiplier that is factored into the emission rate of this AEmitter.
142142
/// @return The throttle strength as a multiplier.
143-
float GetThrottleFactor() const { return LERP(-1.0f, 1.0f, m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, m_Throttle); }
143+
float GetThrottleFactor() const { return Lerp(-1.0f, 1.0f, m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, m_Throttle); }
144144

145145
/// Gets the throttle value that will achieve a given throttle factor that is factored into the emission rate of this AEmitter.
146146
/// @return The throttle value that will achieve the given throttle factor.
147-
float GetThrottleForThrottleFactor(float throttleFactor) const { return LERP(m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, -1.0f, 1.0f, throttleFactor); }
147+
float GetThrottleForThrottleFactor(float throttleFactor) const { return Lerp(m_NegativeThrottleMultiplier, m_PositiveThrottleMultiplier, -1.0f, 1.0f, throttleFactor); }
148148

149149
/// Returns a scaled throttle value that represents a linear increase of force.
150150
/// Because of (bad) reasons, throttle is in the range -1.0F to 1.0F, where -1.0F is "minimum force" and 1.0F is "maximum force".

Source/Entities/AHuman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,12 +1457,12 @@ void AHuman::UpdateCrouching() {
14571457
desiredWalkPathYOffset = m_CrouchAmountOverride * m_MaxWalkPathCrouchShift;
14581458
}
14591459

1460-
float finalWalkPathYOffset = std::clamp(LERP(0.0F, 1.0F, -m_WalkPathOffset.m_Y, desiredWalkPathYOffset, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);
1460+
float finalWalkPathYOffset = std::clamp(Lerp(0.0F, 1.0F, -m_WalkPathOffset.m_Y, desiredWalkPathYOffset, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);
14611461
m_WalkPathOffset.m_Y = -finalWalkPathYOffset;
14621462

14631463
// If crouching, move at reduced speed
14641464
const float crouchSpeedMultiplier = 0.5F;
1465-
float travelSpeedMultiplier = LERP(0.0F, m_MaxWalkPathCrouchShift, 1.0F, crouchSpeedMultiplier, -m_WalkPathOffset.m_Y);
1465+
float travelSpeedMultiplier = Lerp(0.0F, m_MaxWalkPathCrouchShift, 1.0F, crouchSpeedMultiplier, -m_WalkPathOffset.m_Y);
14661466
m_Paths[FGROUND][WALK].SetTravelSpeedMultiplier(travelSpeedMultiplier);
14671467
m_Paths[BGROUND][WALK].SetTravelSpeedMultiplier(travelSpeedMultiplier);
14681468

@@ -2466,7 +2466,7 @@ void AHuman::Update() {
24662466

24672467
// Lean forwards when crouching
24682468
float crouchAngleAdjust = m_HFlipped ? m_MaxCrouchRotation : -m_MaxCrouchRotation;
2469-
rotTarget += LERP(0.0F, m_MaxWalkPathCrouchShift, 0.0F, crouchAngleAdjust, m_WalkPathOffset.m_Y * -1.0F);
2469+
rotTarget += Lerp(0.0F, m_MaxWalkPathCrouchShift, 0.0F, crouchAngleAdjust, m_WalkPathOffset.m_Y * -1.0F);
24702470

24712471
float rotDiff = rot - rotTarget;
24722472
m_AngularVel = m_AngularVel * (0.98F - 0.06F * (m_Health / m_MaxHealth)) - (rotDiff * 0.5F);

Source/Entities/HDFirearm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,16 +959,16 @@ void HDFirearm::Update() {
959959
int animDuration = m_SpriteAnimDuration;
960960
// Spin up - can only spin up if mag is inserted
961961
if (m_Activated && !m_Reloading && m_ActivationTimer.GetElapsedSimTimeMS() < m_ActivationDelay) {
962-
animDuration = (int)LERP(0, m_ActivationDelay, (float)(m_SpriteAnimDuration * 10), (float)m_SpriteAnimDuration, m_ActivationTimer.GetElapsedSimTimeMS());
962+
animDuration = (int)Lerp(0, m_ActivationDelay, (float)(m_SpriteAnimDuration * 10), (float)m_SpriteAnimDuration, m_ActivationTimer.GetElapsedSimTimeMS());
963963
if (m_ActiveSound) {
964-
m_ActiveSound->SetPitch(LERP(0, m_ActivationDelay, 0, 1.0, m_ActivationTimer.GetElapsedSimTimeMS()));
964+
m_ActiveSound->SetPitch(Lerp(0, m_ActivationDelay, 0, 1.0, m_ActivationTimer.GetElapsedSimTimeMS()));
965965
}
966966
}
967967
// Spin down
968968
if ((!m_Activated || m_Reloading) && m_LastFireTmr.GetElapsedSimTimeMS() < m_DeactivationDelay) {
969-
animDuration = (int)LERP(0, m_DeactivationDelay, (float)m_SpriteAnimDuration, (float)(m_SpriteAnimDuration * 10), m_LastFireTmr.GetElapsedSimTimeMS());
969+
animDuration = (int)Lerp(0, m_DeactivationDelay, (float)m_SpriteAnimDuration, (float)(m_SpriteAnimDuration * 10), m_LastFireTmr.GetElapsedSimTimeMS());
970970
if (m_ActiveSound) {
971-
m_ActiveSound->SetPitch(LERP(0, m_DeactivationDelay, 1.0, 0, m_LastFireTmr.GetElapsedSimTimeMS()));
971+
m_ActiveSound->SetPitch(Lerp(0, m_DeactivationDelay, 1.0, 0, m_LastFireTmr.GetElapsedSimTimeMS()));
972972
}
973973
}
974974

Source/Entities/MOPixel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void MOPixel::Draw(BITMAP* targetBitmap, const Vector& targetPos, DrawMode mode,
264264
void MOPixel::SetPostScreenEffectToDraw() const {
265265
if (m_AgeTimer.GetElapsedSimTimeMS() >= m_EffectStartTime && (m_EffectStopTime == 0 || !m_AgeTimer.IsPastSimMS(m_EffectStopTime))) {
266266
if (m_EffectAlwaysShows || !g_SceneMan.ObscuredPoint(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY())) {
267-
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, LERP(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
267+
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, Lerp(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
268268
}
269269
}
270270
}

Source/Entities/MOSParticle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void MOSParticle::Draw(BITMAP* targetBitmap, const Vector& targetPos, DrawMode m
228228
void MOSParticle::SetPostScreenEffectToDraw() const {
229229
if (m_AgeTimer.GetElapsedSimTimeMS() >= m_EffectStartTime && (m_EffectStopTime == 0 || !m_AgeTimer.IsPastSimMS(m_EffectStopTime))) {
230230
if (m_EffectAlwaysShows || !g_SceneMan.ObscuredPoint(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY())) {
231-
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, LERP(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
231+
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, Lerp(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
232232
}
233233
}
234234
}

0 commit comments

Comments
 (0)