From 6ca5143b15421173c51bd9f5b83c6877272c2d9f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Sep 2019 19:00:47 -0400 Subject: [PATCH 1/3] CRumbleVoice: Make SAdsrData constructors constexpr Technically all file-scope instances have runtime-static constructors otherwise. This allows the compiler to completely elide them from a language point of view. --- Runtime/Input/CRumbleVoice.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Runtime/Input/CRumbleVoice.hpp b/Runtime/Input/CRumbleVoice.hpp index 5b3042756..146249073 100644 --- a/Runtime/Input/CRumbleVoice.hpp +++ b/Runtime/Input/CRumbleVoice.hpp @@ -37,9 +37,9 @@ struct SAdsrData { u8 dummy = 0; }; - SAdsrData() = default; - SAdsrData(float attackGain, float autoReleaseDur, float attackDur, float decayDur, float sustainGain, - float releaseDur, bool hasSustain, bool autoRelease) + constexpr SAdsrData() noexcept = default; + constexpr SAdsrData(float attackGain, float autoReleaseDur, float attackDur, float decayDur, float sustainGain, + float releaseDur, bool hasSustain, bool autoRelease) noexcept : x0_attackGain(attackGain) , x4_autoReleaseDur(autoReleaseDur) , x8_attackDur(attackDur) From d7493d5920380980961a30546649a83aff487d24 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Sep 2019 19:11:07 -0400 Subject: [PATCH 2/3] CRumbleVoice: Make SAdsrDelta interface constexpr Makes the API consistent between SAdsrData and SAdsrDelta. --- Runtime/Input/CRumbleVoice.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Runtime/Input/CRumbleVoice.hpp b/Runtime/Input/CRumbleVoice.hpp index 146249073..21f66e5ed 100644 --- a/Runtime/Input/CRumbleVoice.hpp +++ b/Runtime/Input/CRumbleVoice.hpp @@ -59,17 +59,17 @@ struct SAdsrDelta { float x8_decayTime = 0.f; float xc_releaseTime = 0.f; float x10_autoReleaseTime = 0.f; - float x14_attackIntensity; - float x18_sustainIntensity; + float x14_attackIntensity = 0.f; + float x18_sustainIntensity = 0.f; ERumblePriority x1c_priority; EPhase x20_phase; - SAdsrDelta(EPhase phase, ERumblePriority priority) + constexpr SAdsrDelta(EPhase phase, ERumblePriority priority) noexcept : x0_curIntensity(phase == EPhase::PrePulse ? 2.f : 0.f), x1c_priority(priority), x20_phase(phase) {} - SAdsrDelta(EPhase phase) : x1c_priority(ERumblePriority::None), x20_phase(phase) {} + constexpr SAdsrDelta(EPhase phase) noexcept : x1c_priority(ERumblePriority::None), x20_phase(phase) {} - static SAdsrDelta Stopped() { return SAdsrDelta(EPhase::Stop); } - static SAdsrDelta Start(ERumblePriority priority, bool prePulse) { + static constexpr SAdsrDelta Stopped() noexcept { return SAdsrDelta(EPhase::Stop); } + static constexpr SAdsrDelta Start(ERumblePriority priority, bool prePulse) noexcept { return SAdsrDelta(prePulse ? EPhase::PrePulse : EPhase::Attack, priority); } }; From 9983366a537a74d1638c490b4d9a55c9261d2fe3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Sep 2019 19:06:26 -0400 Subject: [PATCH 3/3] RumbleFxTable: Use std::array for the lookup table Strongly enforces the type of the array and also allows size querying, etc, directly from the type. --- Runtime/Input/CRumbleManager.cpp | 2 +- Runtime/Input/RumbleFxTable.cpp | 7 ++++--- Runtime/Input/RumbleFxTable.hpp | 7 +++++-- Runtime/MP1/CFrontEndUI.cpp | 2 +- Runtime/MP1/COptionsScreen.cpp | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Runtime/Input/CRumbleManager.cpp b/Runtime/Input/CRumbleManager.cpp index 601dc688e..d79c99c3f 100644 --- a/Runtime/Input/CRumbleManager.cpp +++ b/Runtime/Input/CRumbleManager.cpp @@ -19,7 +19,7 @@ s16 CRumbleManager::Rumble(CStateManager& mgr, const zeus::CVector3f& pos, ERumb s16 CRumbleManager::Rumble(CStateManager& mgr, ERumbleFxId fx, float gain, ERumblePriority priority) { if (g_GameState->GameOptions().GetIsRumbleEnabled()) - return x0_rumbleGenerator.Rumble(RumbleFxTable[int(fx)], gain, priority, EIOPort::Zero); + return x0_rumbleGenerator.Rumble(RumbleFxTable[size_t(fx)], gain, priority, EIOPort::Zero); return -1; } diff --git a/Runtime/Input/RumbleFxTable.cpp b/Runtime/Input/RumbleFxTable.cpp index a887e0497..c7c67f28c 100644 --- a/Runtime/Input/RumbleFxTable.cpp +++ b/Runtime/Input/RumbleFxTable.cpp @@ -1,8 +1,8 @@ -#include "RumbleFxTable.hpp" +#include "Runtime/Input/RumbleFxTable.hpp" namespace urde { -const SAdsrData RumbleFxTable[] = { +const RumbleFXTable RumbleFxTable{{ /* attackGain, autoReleaseDur, attackDur, decayDur, sustainGain, releaseDur, hasSustain, autoRelease */ {0.48f, 0.f, 0.3f, 0.125f, 0.1f, 0.5f, false, false}, {0.66f, 0.f, 0.11f, 0.175f, 0.42f, 0.375f, false, false}, @@ -27,6 +27,7 @@ const SAdsrData RumbleFxTable[] = { {1.2f, 0.f, 0.01f, 0.621f, 0.f, 0.f, false, false}, {0.5268f, 0.f, 0.114f, 1.008f, 0.f, 0.325f, false, false}, {0.6828f, 0.f, 0.f, 0.821f, 0.f, 0.f, false, false}, - {1.8f, 0.f, 0.5f, 0.425f, 0.35f, 0.5f, false, false}}; + {1.8f, 0.f, 0.5f, 0.425f, 0.35f, 0.5f, false, false}, +}}; } diff --git a/Runtime/Input/RumbleFxTable.hpp b/Runtime/Input/RumbleFxTable.hpp index 3c63da69c..9d649537c 100644 --- a/Runtime/Input/RumbleFxTable.hpp +++ b/Runtime/Input/RumbleFxTable.hpp @@ -1,9 +1,12 @@ #pragma once -#include "CRumbleVoice.hpp" +#include +#include "Runtime/Input/CRumbleVoice.hpp" namespace urde { -extern const SAdsrData RumbleFxTable[]; +using RumbleFXTable = std::array; + +extern const RumbleFXTable RumbleFxTable; } diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 869a2bc19..b477335ba 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -1429,7 +1429,7 @@ void CFrontEndUI::SOptionsFrontEndFrame::DoMenuSelectionChange(CGuiTableGroup* c if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) { x40_rumbleGen.HardStopAll(); - x40_rumbleGen.Rumble(RumbleFxTable[int(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Zero); + x40_rumbleGen.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Zero); } } } diff --git a/Runtime/MP1/COptionsScreen.cpp b/Runtime/MP1/COptionsScreen.cpp index 451e4960c..8d2419cf1 100644 --- a/Runtime/MP1/COptionsScreen.cpp +++ b/Runtime/MP1/COptionsScreen.cpp @@ -86,7 +86,7 @@ void COptionsScreen::OnEnumChanged(CGuiTableGroup* caller, int oldSel) { if (opt == EGameOption::Rumble && caller->GetUserSelection() > 0) { x1a8_rumble.HardStopAll(); - x1a8_rumble.Rumble(RumbleFxTable[int(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Zero); + x1a8_rumble.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Zero); } CPauseScreenBase::UpdateSideTable(caller);