Merge pull request #64 from lioncash/constexpr

CRumbleVoice: Make SAdsrData and SAdsrDelta interfaces constexpr
This commit is contained in:
Phillip Stephens 2019-09-10 23:55:12 -07:00 committed by GitHub
commit 28f8843e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 17 deletions

View File

@ -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) { s16 CRumbleManager::Rumble(CStateManager& mgr, ERumbleFxId fx, float gain, ERumblePriority priority) {
if (g_GameState->GameOptions().GetIsRumbleEnabled()) 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; return -1;
} }

View File

@ -37,9 +37,9 @@ struct SAdsrData {
u8 dummy = 0; u8 dummy = 0;
}; };
SAdsrData() = default; constexpr SAdsrData() noexcept = default;
SAdsrData(float attackGain, float autoReleaseDur, float attackDur, float decayDur, float sustainGain, constexpr SAdsrData(float attackGain, float autoReleaseDur, float attackDur, float decayDur, float sustainGain,
float releaseDur, bool hasSustain, bool autoRelease) float releaseDur, bool hasSustain, bool autoRelease) noexcept
: x0_attackGain(attackGain) : x0_attackGain(attackGain)
, x4_autoReleaseDur(autoReleaseDur) , x4_autoReleaseDur(autoReleaseDur)
, x8_attackDur(attackDur) , x8_attackDur(attackDur)
@ -59,17 +59,17 @@ struct SAdsrDelta {
float x8_decayTime = 0.f; float x8_decayTime = 0.f;
float xc_releaseTime = 0.f; float xc_releaseTime = 0.f;
float x10_autoReleaseTime = 0.f; float x10_autoReleaseTime = 0.f;
float x14_attackIntensity; float x14_attackIntensity = 0.f;
float x18_sustainIntensity; float x18_sustainIntensity = 0.f;
ERumblePriority x1c_priority; ERumblePriority x1c_priority;
EPhase x20_phase; 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) {} : 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 constexpr SAdsrDelta Stopped() noexcept { return SAdsrDelta(EPhase::Stop); }
static SAdsrDelta Start(ERumblePriority priority, bool prePulse) { static constexpr SAdsrDelta Start(ERumblePriority priority, bool prePulse) noexcept {
return SAdsrDelta(prePulse ? EPhase::PrePulse : EPhase::Attack, priority); return SAdsrDelta(prePulse ? EPhase::PrePulse : EPhase::Attack, priority);
} }
}; };

View File

@ -1,8 +1,8 @@
#include "RumbleFxTable.hpp" #include "Runtime/Input/RumbleFxTable.hpp"
namespace urde { namespace urde {
const SAdsrData RumbleFxTable[] = { const RumbleFXTable RumbleFxTable{{
/* attackGain, autoReleaseDur, attackDur, decayDur, sustainGain, releaseDur, hasSustain, autoRelease */ /* attackGain, autoReleaseDur, attackDur, decayDur, sustainGain, releaseDur, hasSustain, autoRelease */
{0.48f, 0.f, 0.3f, 0.125f, 0.1f, 0.5f, false, false}, {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}, {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}, {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.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}, {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},
}};
} }

View File

@ -1,9 +1,12 @@
#pragma once #pragma once
#include "CRumbleVoice.hpp" #include <array>
#include "Runtime/Input/CRumbleVoice.hpp"
namespace urde { namespace urde {
extern const SAdsrData RumbleFxTable[]; using RumbleFXTable = std::array<SAdsrData, 24>;
extern const RumbleFXTable RumbleFxTable;
} }

View File

@ -1429,7 +1429,7 @@ void CFrontEndUI::SOptionsFrontEndFrame::DoMenuSelectionChange(CGuiTableGroup* c
if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) { if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) {
x40_rumbleGen.HardStopAll(); 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);
} }
} }
} }

View File

@ -86,7 +86,7 @@ void COptionsScreen::OnEnumChanged(CGuiTableGroup* caller, int oldSel) {
if (opt == EGameOption::Rumble && caller->GetUserSelection() > 0) { if (opt == EGameOption::Rumble && caller->GetUserSelection() > 0) {
x1a8_rumble.HardStopAll(); 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); CPauseScreenBase::UpdateSideTable(caller);