Skip to content

Commit 77fa001

Browse files
authored
Merge pull request #97 from cortex-command-community/lerp-improvements
Lerp Improvements
2 parents c0ad45b + 49ad146 commit 77fa001

File tree

18 files changed

+126
-58
lines changed

18 files changed

+126
-58
lines changed

CHANGELOG.md

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

1111
- New `MovableObject` INI and Lua property `PostEffectEnabled` (R/W), which determines whether or not the screen effect of an MO is enabled. Defaults to `true` for `MOPixels` and `MOSParticles`, `false` for everything else (to avoid backwards compatibility issues).
1212

13+
- `Lerp` can now be used on Vectors and Matrices/Rotations, not just numbers.
14+
1315
</details>
1416

1517
<details><summary><b>Changed</b></summary>
@@ -22,6 +24,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2224

2325
- Screen effects (glows) can now show on *any* `MovableObject` they're attached to; you may need to set `EffectAlwaysShows = 1` to see them on `MOSRotatings`. Try `InheritEffectRotAngle = 1` on one of them!
2426

27+
- `LERP` Lua binding has been deprecated, and renamed to `Lerp`.
28+
2529
</details>
2630

2731
<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
@@ -478,13 +478,13 @@ void ADoor::Update() {
478478
// Lose health when door is lost, spinning out of control until grinds to halt
479479
if (!m_Door && m_Status != DYING && m_Status != DEAD) {
480480
m_SpriteAnimMode = ALWAYSLOOP;
481-
m_SpriteAnimDuration = static_cast<int>(LERP(0, m_MaxHealth, 10.0F, static_cast<float>(m_InitialSpriteAnimDuration), m_Health));
481+
m_SpriteAnimDuration = static_cast<int>(Lerp(0, m_MaxHealth, 10.0F, static_cast<float>(m_InitialSpriteAnimDuration), m_Health));
482482

483483
if (m_DoorMoveSound) {
484484
if (!m_DoorMoveSound->IsBeingPlayed()) {
485485
m_DoorMoveSound->Play(m_Pos);
486486
}
487-
m_DoorMoveSound->SetPitch(LERP(10.0F, static_cast<float>(m_InitialSpriteAnimDuration), 2.0F, 1.0F, static_cast<float>(m_SpriteAnimDuration)));
487+
m_DoorMoveSound->SetPitch(Lerp(10.0F, static_cast<float>(m_InitialSpriteAnimDuration), 2.0F, 1.0F, static_cast<float>(m_SpriteAnimDuration)));
488488
}
489489

490490
m_Health -= 0.4F;
@@ -580,11 +580,8 @@ void ADoor::UpdateDoorAttachableActions() {
580580
m_DoorState = CLOSED;
581581
}
582582
} else {
583-
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()));
584-
585-
// 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.
586-
// TODO_MULTITHREAD: multithread branch has lerped rotation, so once that's done!
587-
float updatedAngle = LERP(0, m_DoorMoveTime, startAngle, endAngle, m_DoorMoveTimer.GetElapsedSimTimeMS());
583+
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()));
584+
float updatedAngle = Lerp(0, m_DoorMoveTime, Matrix(startAngle), Matrix(endAngle), m_DoorMoveTimer.GetElapsedSimTimeMS()).GetRadAngle();
588585

589586
m_Door->SetParentOffset(updatedOffset);
590587
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
@@ -1404,12 +1404,12 @@ void AHuman::UpdateCrouching() {
14041404
desiredWalkPathYOffset = m_CrouchAmountOverride * m_MaxWalkPathCrouchShift;
14051405
}
14061406

1407-
float finalWalkPathYOffset = std::clamp(LERP(0.0F, 1.0F, -m_WalkPathOffset.m_Y, desiredWalkPathYOffset, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);
1407+
float finalWalkPathYOffset = std::clamp(Lerp(0.0F, 1.0F, -m_WalkPathOffset.m_Y, desiredWalkPathYOffset, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);
14081408
m_WalkPathOffset.m_Y = -finalWalkPathYOffset;
14091409

14101410
// If crouching, move at reduced speed
14111411
const float crouchSpeedMultiplier = 0.5F;
1412-
float travelSpeedMultiplier = LERP(0.0F, m_MaxWalkPathCrouchShift, 1.0F, crouchSpeedMultiplier, -m_WalkPathOffset.m_Y);
1412+
float travelSpeedMultiplier = Lerp(0.0F, m_MaxWalkPathCrouchShift, 1.0F, crouchSpeedMultiplier, -m_WalkPathOffset.m_Y);
14131413
m_Paths[FGROUND][WALK].SetTravelSpeedMultiplier(travelSpeedMultiplier);
14141414
m_Paths[BGROUND][WALK].SetTravelSpeedMultiplier(travelSpeedMultiplier);
14151415

@@ -2413,7 +2413,7 @@ void AHuman::Update() {
24132413

24142414
// Lean forwards when crouching
24152415
float crouchAngleAdjust = m_HFlipped ? m_MaxCrouchRotation : -m_MaxCrouchRotation;
2416-
rotTarget += LERP(0.0F, m_MaxWalkPathCrouchShift, 0.0F, crouchAngleAdjust, m_WalkPathOffset.m_Y * -1.0F);
2416+
rotTarget += Lerp(0.0F, m_MaxWalkPathCrouchShift, 0.0F, crouchAngleAdjust, m_WalkPathOffset.m_Y * -1.0F);
24172417

24182418
float rotDiff = rot - rotTarget;
24192419
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,11 @@ void MOPixel::Draw(BITMAP* targetBitmap, const Vector& targetPos, DrawMode mode,
245245

246246
g_SceneMan.RegisterDrawing(targetBitmap, m_MOID, pixelPos, 1.0F);
247247
}
248+
249+
void MOPixel::SetPostScreenEffectToDraw() const {
250+
if (m_AgeTimer.GetElapsedSimTimeMS() >= m_EffectStartTime && (m_EffectStopTime == 0 || !m_AgeTimer.IsPastSimMS(m_EffectStopTime))) {
251+
if (m_EffectAlwaysShows || !g_SceneMan.ObscuredPoint(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY())) {
252+
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, Lerp(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
253+
}
254+
}
255+
}

Source/Entities/MOSParticle.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,11 @@ void MOSParticle::Draw(BITMAP* targetBitmap, const Vector& targetPos, DrawMode m
217217
g_SceneMan.RegisterDrawing(targetBitmap, m_MOID, spriteX, spriteY, spriteX + m_aSprite[m_Frame]->w, spriteY + m_aSprite[m_Frame]->h);
218218
}
219219
}
220+
221+
void MOSParticle::SetPostScreenEffectToDraw() const {
222+
if (m_AgeTimer.GetElapsedSimTimeMS() >= m_EffectStartTime && (m_EffectStopTime == 0 || !m_AgeTimer.IsPastSimMS(m_EffectStopTime))) {
223+
if (m_EffectAlwaysShows || !g_SceneMan.ObscuredPoint(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY())) {
224+
g_PostProcessMan.RegisterPostEffect(m_Pos, m_pScreenEffect, m_ScreenEffectHash, Lerp(m_EffectStartTime, m_EffectStopTime, m_EffectStartStrength, m_EffectStopStrength, m_AgeTimer.GetElapsedSimTimeMS()), m_EffectRotAngle);
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)