CInputGenerator: Make use of std::array where applicable

Allows removing hardcoded array sizes.
This commit is contained in:
Lioncash 2020-03-17 23:23:13 -04:00
parent 6ddbd15cfc
commit e83d5caea6
3 changed files with 32 additions and 24 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <array>
#include <atomic>
#include <mutex>
@ -82,9 +83,9 @@ public:
* report thread. This class atomically exchanges that data to the
* game thread as needed */
struct DolphinSmashAdapterCallback : boo::IDolphinSmashAdapterCallback {
std::atomic<EStatusChange> m_statusChanges[4];
bool m_connected[4] = {};
boo::DolphinControllerState m_states[4];
std::array<std::atomic<EStatusChange>, 4> m_statusChanges;
std::array<bool, 4> m_connected{};
std::array<boo::DolphinControllerState, 4> m_states;
std::mutex m_stateLock;
void controllerConnected(unsigned idx, boo::EDolphinControllerType) override {
/* Controller thread */
@ -103,7 +104,7 @@ public:
m_states[idx] = state;
}
CFinalInput m_lastUpdates[4];
std::array<CFinalInput, 4> m_lastUpdates;
const CFinalInput& getFinalInput(unsigned idx, float dt, float leftDiv, float rightDiv) {
/* Game thread */
std::unique_lock<std::mutex> lk(m_stateLock);
@ -159,9 +160,9 @@ public:
}
}
}
void ControlAllMotors(const EMotorState* states) {
void ControlAllMotors(const std::array<EMotorState, 4>& states) {
if (smashAdapter) {
for (int i = 0; i < 4; ++i) {
for (size_t i = 0; i < states.size(); ++i) {
switch (states[i]) {
case EMotorState::Stop:
smashAdapter->stopRumble(i);

View File

@ -30,8 +30,8 @@ void CRumbleGenerator::Update(float dt) {
if (!xf0_24_disabled) {
bool updated = false;
for (int i = 0; i < 4; ++i) {
float intensity = x0_voices[i].GetIntensity();
for (size_t i = 0; i < x0_voices.size(); ++i) {
const float intensity = x0_voices[i].GetIntensity();
if (!x0_voices[i].Update(dt) || intensity <= 0.f) {
xc0_periodTime[i] = 0.f;
xd0_onTime[i] = 0.f;
@ -76,31 +76,36 @@ void CRumbleGenerator::Update(float dt) {
}
}
static const EMotorState HardStopCommands[] = {EMotorState::StopHard, EMotorState::StopHard, EMotorState::StopHard,
EMotorState::StopHard};
void CRumbleGenerator::HardStopAll() {
for (int i = 0; i < 4; ++i) {
xc0_periodTime[i] = 0.f;
xd0_onTime[i] = 0.f;
xe0_commandArray[i] = EMotorState::Stop;
x0_voices[i].HardReset();
static constexpr std::array HardStopCommands{
EMotorState::StopHard,
EMotorState::StopHard,
EMotorState::StopHard,
EMotorState::StopHard,
};
xc0_periodTime.fill(0.0f);
xd0_onTime.fill(0.0f);
xe0_commandArray.fill(EMotorState::Stop);
for (auto& voice : x0_voices) {
voice.HardReset();
}
g_InputGenerator->ControlAllMotors(HardStopCommands);
}
s16 CRumbleGenerator::Rumble(const SAdsrData& adsr, float gain, ERumblePriority prio, EIOPort port) {
CRumbleVoice& vox = x0_voices[int(port)];
s16 freeChan = vox.GetFreeChannel();
CRumbleVoice& vox = x0_voices[size_t(port)];
const s16 freeChan = vox.GetFreeChannel();
if (prio >= vox.GetPriority(freeChan)) {
xc0_periodTime[int(port)] = 0.f;
xc0_periodTime[size_t(port)] = 0.f;
return vox.Activate(adsr, freeChan, gain, prio);
}
return -1;
}
void CRumbleGenerator::Stop(s16 id, EIOPort port) {
CRumbleVoice& vox = x0_voices[int(port)];
CRumbleVoice& vox = x0_voices[size_t(port)];
vox.Deactivate(id, false);
}

View File

@ -1,15 +1,17 @@
#pragma once
#include <array>
#include "Runtime/GCNTypes.hpp"
#include "Runtime/Input/CInputGenerator.hpp"
#include "Runtime/Input/CRumbleVoice.hpp"
namespace urde {
class CRumbleGenerator {
CRumbleVoice x0_voices[4];
float xc0_periodTime[4];
float xd0_onTime[4];
EMotorState xe0_commandArray[4];
std::array<CRumbleVoice, 4> x0_voices;
std::array<float, 4> xc0_periodTime;
std::array<float, 4> xd0_onTime;
std::array<EMotorState, 4> xe0_commandArray;
bool xf0_24_disabled : 1;
public: