ControlMapper: Use std::array where applicable

This commit is contained in:
Lioncash 2019-10-01 02:02:57 -04:00
parent dc565969e6
commit f0186e7ceb
1 changed files with 194 additions and 183 deletions

View File

@ -1,12 +1,16 @@
#include "../RetroTypes.hpp"
#include "ControlMapper.hpp"
#include "CFinalInput.hpp"
#include "Runtime/Input/ControlMapper.hpp"
#include <array>
#include "DataSpec/DNACommon/Tweaks/ITweakPlayerControl.hpp"
#include "../GameGlobalObjects.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/RetroTypes.hpp"
#include "Runtime/Input/CFinalInput.hpp"
namespace urde {
static const char* skCommandDescs[] = {
namespace {
constexpr std::array skCommandDescs{
"Forward", "Backward", "Turn Left",
"Turn Right", "Strafe Left", "Strafe Right",
"Look Left", "Look Right", "Look Up",
@ -32,7 +36,8 @@ static const char* skCommandDescs[] = {
"Next Pause Screen", "UNKNOWN", "None",
};
static const char* skFunctionDescs[] = {"None",
constexpr std::array skFunctionDescs{
"None",
"Left Stick Up",
"Left Stick Down",
"Left Stick Left",
@ -54,12 +59,14 @@ static const char* skFunctionDescs[] = {"None",
"Z Button",
"Left Trigger Press",
"Right Trigger Press",
"Start"};
"Start",
};
typedef bool (CFinalInput::*BoolReturnFn)() const;
typedef float (CFinalInput::*FloatReturnFn)() const;
using BoolReturnFn = bool (CFinalInput::*)() const;
using FloatReturnFn = float (CFinalInput::*)() const;
static BoolReturnFn skPressFuncs[] = {nullptr,
constexpr std::array<BoolReturnFn, 24> skPressFuncs{
nullptr,
&CFinalInput::PLAUp,
&CFinalInput::PLADown,
&CFinalInput::PLALeft,
@ -82,9 +89,11 @@ static BoolReturnFn skPressFuncs[] = {nullptr,
&CFinalInput::PL,
&CFinalInput::PR,
&CFinalInput::PStart,
nullptr};
nullptr,
};
static BoolReturnFn skDigitalFuncs[] = {nullptr,
constexpr std::array<BoolReturnFn, 24> skDigitalFuncs{
nullptr,
&CFinalInput::DLAUp,
&CFinalInput::DLADown,
&CFinalInput::DLALeft,
@ -107,9 +116,11 @@ static BoolReturnFn skDigitalFuncs[] = {nullptr,
&CFinalInput::DL,
&CFinalInput::DR,
&CFinalInput::DStart,
nullptr};
nullptr,
};
static FloatReturnFn skAnalogFuncs[] = {nullptr,
constexpr std::array<FloatReturnFn, 24> skAnalogFuncs{
nullptr,
&CFinalInput::ALAUp,
&CFinalInput::ALADown,
&CFinalInput::ALALeft,
@ -132,9 +143,10 @@ static FloatReturnFn skAnalogFuncs[] = {nullptr,
&CFinalInput::AL,
&CFinalInput::AR,
&CFinalInput::AStart,
nullptr};
nullptr,
};
static const ControlMapper::EKBMFunctionList skKBMMapping[] = {
constexpr std::array<ControlMapper::EKBMFunctionList, 70> skKBMMapping{
ControlMapper::EKBMFunctionList::KeyPress + 'w', // Forward,
ControlMapper::EKBMFunctionList::KeyPress + 's', // Backward,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // TurnLeft,
@ -204,17 +216,16 @@ static const ControlMapper::EKBMFunctionList skKBMMapping[] = {
ControlMapper::EKBMFunctionList::KeyPress + 'e', // NextPauseScreen = 0x42,
ControlMapper::EKBMFunctionList::None, // UNKNOWN,
ControlMapper::EKBMFunctionList::None, // None,
ControlMapper::EKBMFunctionList::None
ControlMapper::EKBMFunctionList::None,
};
#define kCommandFilterCount 67
static bool skCommandFilterFlag[kCommandFilterCount] = {true};
std::array<bool, 67> skCommandFilterFlag{true};
} // Anonymous namespace
void ControlMapper::SetCommandFiltered(ECommands cmd, bool filtered) { skCommandFilterFlag[size_t(cmd)] = filtered; }
void ControlMapper::ResetCommandFilters() {
for (int i = 0; i < kCommandFilterCount; ++i)
skCommandFilterFlag[i] = true;
skCommandFilterFlag.fill(true);
}
bool ControlMapper::GetPressInput(ECommands cmd, const CFinalInput& input) {