Skip to content

Commit 8b7bdc0

Browse files
committed
Esposed ReloadTimer, and made ReloadProgress (and the Timer Real/SimTimeLimitProgress properties) writable
1 parent d5d72a4 commit 8b7bdc0

File tree

9 files changed

+50
-31
lines changed

9 files changed

+50
-31
lines changed

CHANGELOG.md

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

139139
- New option to mute audio when the game window loses focus.
140140

141+
- `ReloadTimer` on `HDFirearm` is now exposed to Lua.
142+
143+
- `ReloadProgress` on `HDFirearm` is now a writable property in Lua, and not only readable.
144+
145+
- `RealTimeLimitProgress` and `SimTimeLimitProgress` on `Timer` are now both writable properties in Lua, and not only readable.
146+
141147
</details>
142148

143149
<details><summary><b>Changed</b></summary>

Source/Entities/Actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,8 @@ void Actor::DrawHUD(BITMAP* pTargetBitmap, const Vector& targetPos, int whichScr
13871387
}
13881388

13891389
// Draw the alarm exclamation mark if we are alarmed!
1390-
if (m_AlarmTimer.SimTimeLimitProgress() < 0.25) {
1391-
draw_sprite(pTargetBitmap, m_apAlarmExclamation[m_AgeTimer.AlternateSim(100)], cpuPos.m_X - 3, EaseOut(drawPos.m_Y + m_HUDStack - 10, drawPos.m_Y + m_HUDStack - 25, m_AlarmTimer.SimTimeLimitProgress() / 0.25f));
1390+
if (m_AlarmTimer.GetSimTimeLimitProgress() < 0.25) {
1391+
draw_sprite(pTargetBitmap, m_apAlarmExclamation[m_AgeTimer.AlternateSim(100)], cpuPos.m_X - 3, EaseOut(drawPos.m_Y + m_HUDStack - 10, drawPos.m_Y + m_HUDStack - 25, m_AlarmTimer.GetSimTimeLimitProgress() / 0.25f));
13921392
}
13931393

13941394
if (pSmallFont && pSymbolFont) {

Source/Entities/HDFirearm.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,29 @@ namespace RTE {
365365

366366
/// Gets this HDFirearm's reload progress as a scalar from 0 to 1.
367367
/// @return The reload progress as a scalar from 0 to 1.
368-
float GetReloadProgress() const { return IsReloading() && m_BaseReloadTime > 0 ? static_cast<float>(m_ReloadTmr.SimTimeLimitProgress()) : 1.0F; }
368+
float GetReloadProgress() const { return IsReloading() && m_BaseReloadTime > 0 ? static_cast<float>(m_ReloadTmr.GetSimTimeLimitProgress()) : 1.0F; }
369+
370+
/// Sets this HDFirearm's reload progress as a scalar from 0 to 1.
371+
/// @param progress The reload progress as a scalar from 0 to 1.
372+
void SetReloadProgress(float progress) { m_ReloadTmr.SetSimTimeLimitProgress(progress); }
373+
374+
/// Gets this HDFirearm's underlying reload timer.
375+
/// @return This firearm's reload timer.
376+
Timer& GetReloadTimer() { return m_ReloadTmr; }
369377

370378
/// Does the calculations necessary to detect whether this HDFirearm is at rest or not. IsAtRest() retrieves the answer.
371379
void RestDetection() override;
372380

373-
/// Activates one of this HDFirearm's features. Analogous to 'pulling
374-
/// the trigger'.
381+
/// Activates one of this HDFirearm's features. Analogous to 'pulling the trigger'.
375382
void Activate() override;
376383

377-
/// Deactivates one of this HDFirearm's features. Analogous to 'releasing
378-
/// the trigger'.
384+
/// Deactivates one of this HDFirearm's features. Analogous to 'releasing the trigger'.
379385
void Deactivate() override;
380386

381-
/// Aborts playing of active sound no matter what. Used to silence spinning
382-
/// weapons when weapons swapped
387+
/// Aborts playing of active sound no matter what. Used to silence spinning weapons when weapons swapped
383388
void StopActivationSound();
384389

385-
/// Throws out the currently used Magazine, if any, and puts in a new one
386-
/// after the reload delay is up.
390+
/// Throws out the currently used Magazine, if any, and puts in a new one after the reload delay is up.
387391
void Reload() override;
388392

389393
/// Tells whether the device is curtrently being reloaded.
@@ -398,11 +402,12 @@ namespace RTE {
398402
/// @return Whetehr in need of reloading (ie not full).
399403
bool NeedsReloading() const override;
400404

401-
/// Tells whether the device is curtrently full and reloading won't have
402-
/// any effect.
403-
/// @return Whetehr magazine is full or not.
405+
/// Tells whether the device is currently full and reloading won't have any effect.
406+
/// @return Whether magazine is full or not.
404407
bool IsFull() const override;
405408

409+
/// Tells whether the device is currently empty and attempting to fire won't have any effect.
410+
/// @return Whether magazine is empty or not.
406411
bool IsEmpty() const override;
407412

408413
/// Tells whether the device is fully automatic or not.
@@ -427,8 +432,7 @@ namespace RTE {
427432
/// Updates this MovableObject. Supposed to be done every frame.
428433
void Update() override;
429434

430-
/// Draws this HDFirearm's current graphical representation to a
431-
/// BITMAP of choice.
435+
/// Draws this HDFirearm's current graphical representation to a BITMAP of choice.
432436
/// @param pTargetBitmap A pointer to a BITMAP to draw on.
433437
/// @param targetPos The absolute position of the target bitmap's upper left corner in the Scene. (default: Vector())
434438
/// @param mode In which mode to draw in. See the DrawMode enumeration for the modes. (default: g_DrawColor)
@@ -439,8 +443,7 @@ namespace RTE {
439443
/// Draws an aiming aid in front of this HeldDevice.
440444
/// @param pTargetBitmap A pointer to a BITMAP to draw on.
441445
/// @param targetPos The absolute position of the target bitmap's upper left corner in the Scene. (default: Vector())
442-
/// @param whichScreen Which player's screen this is being drawn to. May affect what HUD elements (default: 0)
443-
/// get drawn etc.
446+
/// @param whichScreen Which player's screen this is being drawn to. May affect what HUD elements get drawn etc. (default: 0)
444447
void DrawHUD(BITMAP* pTargetBitmap, const Vector& targetPos = Vector(), int whichScreen = 0, bool playerControlled = false) override;
445448

446449
/// Estimates what material strength one round in the magazine can destroy.
@@ -475,7 +478,6 @@ namespace RTE {
475478
/// @param newValue Manual animation flag value.
476479
void SetAnimatedManually(bool newValue) { m_IsAnimatedManually = newValue; }
477480

478-
/// Protected member variable and method declarations
479481
protected:
480482
/// Sets this Attachable's parent MOSRotating, and also sets its Team based on its parent and, if the Attachable is set to collide, adds/removes Atoms to its new/old parent.
481483
/// Additionally, sets this HDFirearm as not firing or reloading, and resets its reload timer.

Source/GUI/GUILabel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ void GUILabel::Draw(GUIBitmap* Bitmap, bool overwiteFontColorAndKerning) {
174174
m_OverflowScrollState = OverflowScrollState::WaitAtEnd;
175175
break;
176176
}
177-
xPos -= modifyXPos ? static_cast<int>(static_cast<double>(textFullWidth - m_Width) * m_OverflowScrollTimer.RealTimeLimitProgress()) : 0;
178-
yPos -= modifyYPos ? static_cast<int>(static_cast<double>(textFullHeight - m_Height) * m_OverflowScrollTimer.RealTimeLimitProgress()) : 0;
177+
xPos -= modifyXPos ? static_cast<int>(static_cast<double>(textFullWidth - m_Width) * m_OverflowScrollTimer.GetRealTimeLimitProgress()) : 0;
178+
yPos -= modifyYPos ? static_cast<int>(static_cast<double>(textFullHeight - m_Height) * m_OverflowScrollTimer.GetRealTimeLimitProgress()) : 0;
179179
break;
180180
case OverflowScrollState::WaitAtEnd:
181181
if (m_OverflowScrollTimer.GetRealTimeLimitMS() == -1) {

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, HDFirearm) {
654654
.property("DeactivationDelay", &HDFirearm::GetDeactivationDelay, &HDFirearm::SetDeactivationDelay)
655655
.property("BaseReloadTime", &HDFirearm::GetBaseReloadTime, &HDFirearm::SetBaseReloadTime)
656656
.property("ReloadTime", &HDFirearm::GetReloadTime)
657-
.property("ReloadProgress", &HDFirearm::GetReloadProgress)
657+
.property("ReloadTimer", &HDFirearm::GetReloadTimer)
658+
.property("ReloadProgress", &HDFirearm::GetReloadProgress, &HDFirearm::SetReloadProgress)
658659
.property("ShakeRange", &HDFirearm::GetShakeRange, &HDFirearm::SetShakeRange)
659660
.property("SharpShakeRange", &HDFirearm::GetSharpShakeRange, &HDFirearm::SetSharpShakeRange)
660661
.property("NoSupportFactor", &HDFirearm::GetNoSupportFactor, &HDFirearm::SetNoSupportFactor)

Source/Lua/LuaBindingsSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ LuaBindingRegisterFunctionDefinitionForType(SystemLuaBindings, Timer) {
146146
.property("StartSimTimeMS", &Timer::GetStartSimTimeMS, &Timer::SetStartSimTimeMS)
147147
.property("ElapsedSimTimeS", &Timer::GetElapsedSimTimeS, &Timer::SetElapsedSimTimeS)
148148
.property("ElapsedSimTimeMS", &Timer::GetElapsedSimTimeMS, &Timer::SetElapsedSimTimeMS)
149-
.property("RealTimeLimitProgress", &Timer::RealTimeLimitProgress)
150-
.property("SimTimeLimitProgress", &Timer::SimTimeLimitProgress)
149+
.property("RealTimeLimitProgress", &Timer::GetRealTimeLimitProgress, &Timer::SetRealTimeLimitProgress)
150+
.property("SimTimeLimitProgress", &Timer::GetSimTimeLimitProgress, &Timer::SetSimTimeLimitProgress)
151151

152152
.def("Reset", &Timer::Reset)
153153
.def("SetRealTimeLimitMS", &Timer::SetRealTimeLimitMS)

Source/Menus/InventoryMenuGUI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void InventoryMenuGUI::UpdateCarouselMode() {
469469
void InventoryMenuGUI::UpdateCarouselItemBoxSizesAndPositions() {
470470
float halfMassFontHeight = static_cast<float>(m_SmallFont->GetFontHeight() / 2);
471471
int carouselIndex = 0;
472-
float carouselAnimationProgress = static_cast<float>(m_CarouselAnimationTimer.RealTimeLimitProgress());
472+
float carouselAnimationProgress = static_cast<float>(m_CarouselAnimationTimer.GetRealTimeLimitProgress());
473473
float directionalAnimationProgress = carouselAnimationProgress * static_cast<float>(m_CarouselAnimationDirection);
474474
float currentBoxHorizontalOffset = (directionalAnimationProgress <= 0 ? directionalAnimationProgress : -(1.0F - directionalAnimationProgress)) * m_CarouselExitingItemBox->FullSize.GetX();
475475

@@ -1316,7 +1316,7 @@ void InventoryMenuGUI::DrawCarouselMode(BITMAP* targetBitmap, const Vector& draw
13161316
clear_to_color(m_CarouselBitmap.get(), g_MaskColor);
13171317
clear_to_color(m_CarouselBGBitmap.get(), g_MaskColor);
13181318
AllegroBitmap carouselAllegroBitmap(m_CarouselBitmap.get());
1319-
float enableDisableProgress = static_cast<float>(m_EnableDisableAnimationTimer.RealTimeLimitProgress());
1319+
float enableDisableProgress = static_cast<float>(m_EnableDisableAnimationTimer.GetRealTimeLimitProgress());
13201320

13211321
for (const std::unique_ptr<CarouselItemBox>& carouselItemBox: m_CarouselItemBoxes) {
13221322
if ((carouselItemBox->Item && carouselItemBox->Item->GetUniqueID() != 0) || (carouselItemBox->IsForEquippedItems && !m_InventoryActorEquippedItems.empty())) {
@@ -1428,7 +1428,7 @@ void InventoryMenuGUI::DrawFullMode(BITMAP* targetBitmap, const Vector& drawPos)
14281428
m_GUITopLevelBox->SetPositionAbs(drawPos.GetFloorIntX(), drawPos.GetFloorIntY());
14291429

14301430
if (IsEnablingOrDisabling()) {
1431-
float enableDisableProgress = static_cast<float>(m_EnableDisableAnimationTimer.RealTimeLimitProgress());
1431+
float enableDisableProgress = static_cast<float>(m_EnableDisableAnimationTimer.GetRealTimeLimitProgress());
14321432
if (m_EnabledState == EnabledState::Disabling) {
14331433
enableDisableProgress = 1.0F - enableDisableProgress;
14341434
}

Source/Menus/MetagameGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5535,7 +5535,7 @@ void MetagameGUI::UpdatePlayerBars() {
55355535
if (!m_apFundsChangeTimer[metaPlayer].IsPastRealTimeLimit()) {
55365536
// Animate downward if value is negative, upward if positive
55375537
int animDir = m_apFundsChangeLabel[metaPlayer]->GetText()[2] == '-' ? 1 : -1;
5538-
int heightChange = EaseOut(0, 25, m_apFundsChangeTimer[metaPlayer].RealTimeLimitProgress());
5538+
int heightChange = EaseOut(0, 25, m_apFundsChangeTimer[metaPlayer].GetRealTimeLimitProgress());
55395539
// Use the height of the label to keep track of the animation progress over several frames
55405540
m_apFundsChangeLabel[metaPlayer]->SetPositionAbs(m_apFundsChangeLabel[metaPlayer]->GetXPos(), m_apFundsChangeLabel[metaPlayer]->GetYPos() + animDir * (heightChange - m_apFundsChangeLabel[metaPlayer]->GetHeight() + 16));
55415541
m_apFundsChangeLabel[metaPlayer]->Resize(m_apFundsChangeLabel[metaPlayer]->GetWidth(), 16 + heightChange);
@@ -5551,7 +5551,7 @@ void MetagameGUI::UpdatePlayerBars() {
55515551
if (!m_apBrainsChangeTimer[metaPlayer].IsPastRealTimeLimit()) {
55525552
// Animate downward if value is negative, upward if positive
55535553
int animDir = m_apBrainChangeLabel[metaPlayer]->GetText()[1] == '-' ? 1 : -1;
5554-
int heightChange = EaseOut(0, 25, m_apBrainsChangeTimer[metaPlayer].RealTimeLimitProgress());
5554+
int heightChange = EaseOut(0, 25, m_apBrainsChangeTimer[metaPlayer].GetRealTimeLimitProgress());
55555555
// Use the height of the label to keep track of the animation progress over several frames
55565556
m_apBrainChangeLabel[metaPlayer]->SetPositionAbs(m_apBrainChangeLabel[metaPlayer]->GetXPos(), m_apBrainChangeLabel[metaPlayer]->GetYPos() + animDir * (heightChange - m_apBrainChangeLabel[metaPlayer]->GetHeight() + 16));
55575557
m_apBrainChangeLabel[metaPlayer]->Resize(m_apBrainChangeLabel[metaPlayer]->GetWidth(), 16 + heightChange);

Source/System/Timer.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ namespace RTE {
137137
/// Returns how much progress has been made toward the set time limit previously set by SetRealTimeLimitMS.
138138
/// 0 means no progress, 1.0 means the timer has reached, or is beyond the limit.
139139
/// @return A normalized scalar between 0.0 - 1.0 showing the progress toward the limit.
140-
double RealTimeLimitProgress() const { return (m_RealTimeLimit == 0) ? 1.0 : (std::min(1.0, GetElapsedRealTimeMS() / (m_RealTimeLimit / m_TicksPerMS))); }
140+
double GetRealTimeLimitProgress() const { return (m_RealTimeLimit == 0) ? 1.0 : (std::min(1.0, GetElapsedRealTimeMS() / (m_RealTimeLimit / m_TicksPerMS))); }
141+
142+
/// Sets how much progress has been made toward the set time limit previously set by SetRealTimeLimitMS.
143+
/// 0 means no progress, 1.0 means the timer is at the limit, greater is beyond the limit.
144+
/// @param progress A normalized scalar between 0.0 - 1.0 of the progress toward the limit.
145+
void SetRealTimeLimitProgress(double progress) { m_StartRealTime = g_TimerMan.GetSimTickCount() - static_cast<long long>(round(m_RealTimeLimit * progress)); }
141146

142147
/// Returns true or false, depending on whether the elapsed time falls in one of two repeating intervals which divide it.
143148
/// This is useful for blink animations etc.
@@ -226,7 +231,12 @@ namespace RTE {
226231
/// Returns how much progress has been made toward the set time limit previously set by SetSimTimeLimitMS.
227232
/// 0 means no progress, 1.0 means the timer has reached, or is beyond the limit.
228233
/// @return A normalized scalar between 0.0 - 1.0 showing the progress toward the limit.
229-
double SimTimeLimitProgress() const { return (m_SimTimeLimit == 0) ? 1.0 : (std::min(1.0, GetElapsedSimTimeMS() / (m_SimTimeLimit / m_TicksPerMS))); }
234+
double GetSimTimeLimitProgress() const { return (m_SimTimeLimit == 0) ? 1.0 : (std::min(1.0, GetElapsedSimTimeMS() / (m_SimTimeLimit / m_TicksPerMS))); }
235+
236+
/// Sets how much progress has been made toward the set time limit previously set by SetSimTimeLimitMS.
237+
/// 0 means no progress, 1.0 means the timer is at the limit, greater is beyond the limit.
238+
/// @param progress A normalized scalar between 0.0 - 1.0 of the progress toward the limit.
239+
void SetSimTimeLimitProgress(double progress) { m_StartSimTime = g_TimerMan.GetSimTickCount() - static_cast <long long>(round(m_SimTimeLimit * progress)); }
230240

231241
/// Returns true or false, depending on whether the elapsed time falls in one of two repeating intervals which divide it.
232242
/// This is useful for blink animations etc.

0 commit comments

Comments
 (0)