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,189 +36,196 @@ static const char* skCommandDescs[] = {
"Next Pause Screen", "UNKNOWN", "None",
};
static const char* skFunctionDescs[] = {"None",
"Left Stick Up",
"Left Stick Down",
"Left Stick Left",
"Left Stick Right",
"Right Stick Up",
"Right Stick Down",
"Right Stick Left",
"Right Stick Right",
"Left Trigger",
"Right Trigger",
"D-Pad Up ",
"D-Pad Down ",
"D-Pad Left ",
"D-Pad Right",
"A Button",
"B Button",
"X Button",
"Y Button",
"Z Button",
"Left Trigger Press",
"Right Trigger Press",
"Start"};
typedef bool (CFinalInput::*BoolReturnFn)() const;
typedef float (CFinalInput::*FloatReturnFn)() const;
static BoolReturnFn skPressFuncs[] = {nullptr,
&CFinalInput::PLAUp,
&CFinalInput::PLADown,
&CFinalInput::PLALeft,
&CFinalInput::PLARight,
&CFinalInput::PRAUp,
&CFinalInput::PRADown,
&CFinalInput::PRALeft,
&CFinalInput::PRARight,
&CFinalInput::PLTrigger,
&CFinalInput::PRTrigger,
&CFinalInput::PDPUp,
&CFinalInput::PDPDown,
&CFinalInput::PDPLeft,
&CFinalInput::PDPRight,
&CFinalInput::PA,
&CFinalInput::PB,
&CFinalInput::PX,
&CFinalInput::PY,
&CFinalInput::PZ,
&CFinalInput::PL,
&CFinalInput::PR,
&CFinalInput::PStart,
nullptr};
static BoolReturnFn skDigitalFuncs[] = {nullptr,
&CFinalInput::DLAUp,
&CFinalInput::DLADown,
&CFinalInput::DLALeft,
&CFinalInput::DLARight,
&CFinalInput::DRAUp,
&CFinalInput::DRADown,
&CFinalInput::DRALeft,
&CFinalInput::DRARight,
&CFinalInput::DLTrigger,
&CFinalInput::DRTrigger,
&CFinalInput::DDPUp,
&CFinalInput::DDPDown,
&CFinalInput::DDPLeft,
&CFinalInput::DDPRight,
&CFinalInput::DA,
&CFinalInput::DB,
&CFinalInput::DX,
&CFinalInput::DY,
&CFinalInput::DZ,
&CFinalInput::DL,
&CFinalInput::DR,
&CFinalInput::DStart,
nullptr};
static FloatReturnFn skAnalogFuncs[] = {nullptr,
&CFinalInput::ALAUp,
&CFinalInput::ALADown,
&CFinalInput::ALALeft,
&CFinalInput::ALARight,
&CFinalInput::ARAUp,
&CFinalInput::ARADown,
&CFinalInput::ARALeft,
&CFinalInput::ARARight,
&CFinalInput::ALTrigger,
&CFinalInput::ARTrigger,
&CFinalInput::ADPUp,
&CFinalInput::ADPDown,
&CFinalInput::ADPLeft,
&CFinalInput::ADPRight,
&CFinalInput::AA,
&CFinalInput::AB,
&CFinalInput::AX,
&CFinalInput::AY,
&CFinalInput::AZ,
&CFinalInput::AL,
&CFinalInput::AR,
&CFinalInput::AStart,
nullptr};
static const ControlMapper::EKBMFunctionList skKBMMapping[] = {
ControlMapper::EKBMFunctionList::KeyPress + 'w', // Forward,
ControlMapper::EKBMFunctionList::KeyPress + 's', // Backward,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // TurnLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // TurnRight,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // StrafeLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // StrafeRight,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // LookLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // LookRight,
ControlMapper::EKBMFunctionList::KeyPress + 's', // LookUp,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // LookDown,
ControlMapper::EKBMFunctionList::KeyPress + ' ', // JumpOrBoost = 10,
ControlMapper::EKBMFunctionList::MousePress + boo::EMouseButton::Primary, // FireOrBomb = 11,
ControlMapper::EKBMFunctionList::MousePress + boo::EMouseButton::Secondary, // MissileOrPowerBomb = 12,
ControlMapper::EKBMFunctionList::KeyPress + 'c', // Morph,
ControlMapper::EKBMFunctionList::None, // AimUp,
ControlMapper::EKBMFunctionList::None, // AimDown,
ControlMapper::EKBMFunctionList::None, // CycleBeamUp,
ControlMapper::EKBMFunctionList::None, // CycleBeamDown,
ControlMapper::EKBMFunctionList::None, // CycleItem,
ControlMapper::EKBMFunctionList::KeyPress + '1', // PowerBeam,
ControlMapper::EKBMFunctionList::KeyPress + '3', // IceBeam,
ControlMapper::EKBMFunctionList::KeyPress + '2', // WaveBeam,
ControlMapper::EKBMFunctionList::KeyPress + '4', // PlasmaBeam,
ControlMapper::EKBMFunctionList::None, // ToggleHolster = 23,
ControlMapper::EKBMFunctionList::None, // OrbitClose,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // OrbitFar,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // OrbitObject,
ControlMapper::EKBMFunctionList::None, // OrbitSelect,
ControlMapper::EKBMFunctionList::None, // OrbitConfirm,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // OrbitLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // OrbitRight,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // OrbitUp,
ControlMapper::EKBMFunctionList::KeyPress + 's', // OrbitDown,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // LookHold1,
ControlMapper::EKBMFunctionList::None, // LookHold2,
ControlMapper::EKBMFunctionList::None, // LookZoomIn,
ControlMapper::EKBMFunctionList::None, // LookZoomOut,
ControlMapper::EKBMFunctionList::None, // AimHold,
ControlMapper::EKBMFunctionList::KeyPress + 's', // MapCircleUp,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // MapCircleDown,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // MapCircleLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // MapCircleRight,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Up, // MapMoveForward,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Down, // MapMoveBack,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Left, // MapMoveLeft,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Right, // MapMoveRight,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // MapZoomIn,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // MapZoomOut,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // SpiderBall,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // ChaseCamera,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Right, // XrayVisor = 50,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Down, // ThermoVisor = 51,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Left, // InviroVisor = 52,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Up, // NoVisor = 53,
ControlMapper::EKBMFunctionList::None, // VisorMenu,
ControlMapper::EKBMFunctionList::None, // VisorUp,
ControlMapper::EKBMFunctionList::None, // VisorDown,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // ShowCrosshairs,
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UseSheild = 0x3B,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // ScanItem = 0x3C,
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::KeyPress + 'q', // PreviousPauseScreen = 0x41,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // NextPauseScreen = 0x42,
ControlMapper::EKBMFunctionList::None, // UNKNOWN,
ControlMapper::EKBMFunctionList::None, // None,
ControlMapper::EKBMFunctionList::None
constexpr std::array skFunctionDescs{
"None",
"Left Stick Up",
"Left Stick Down",
"Left Stick Left",
"Left Stick Right",
"Right Stick Up",
"Right Stick Down",
"Right Stick Left",
"Right Stick Right",
"Left Trigger",
"Right Trigger",
"D-Pad Up ",
"D-Pad Down ",
"D-Pad Left ",
"D-Pad Right",
"A Button",
"B Button",
"X Button",
"Y Button",
"Z Button",
"Left Trigger Press",
"Right Trigger Press",
"Start",
};
#define kCommandFilterCount 67
static bool skCommandFilterFlag[kCommandFilterCount] = {true};
using BoolReturnFn = bool (CFinalInput::*)() const;
using FloatReturnFn = float (CFinalInput::*)() const;
constexpr std::array<BoolReturnFn, 24> skPressFuncs{
nullptr,
&CFinalInput::PLAUp,
&CFinalInput::PLADown,
&CFinalInput::PLALeft,
&CFinalInput::PLARight,
&CFinalInput::PRAUp,
&CFinalInput::PRADown,
&CFinalInput::PRALeft,
&CFinalInput::PRARight,
&CFinalInput::PLTrigger,
&CFinalInput::PRTrigger,
&CFinalInput::PDPUp,
&CFinalInput::PDPDown,
&CFinalInput::PDPLeft,
&CFinalInput::PDPRight,
&CFinalInput::PA,
&CFinalInput::PB,
&CFinalInput::PX,
&CFinalInput::PY,
&CFinalInput::PZ,
&CFinalInput::PL,
&CFinalInput::PR,
&CFinalInput::PStart,
nullptr,
};
constexpr std::array<BoolReturnFn, 24> skDigitalFuncs{
nullptr,
&CFinalInput::DLAUp,
&CFinalInput::DLADown,
&CFinalInput::DLALeft,
&CFinalInput::DLARight,
&CFinalInput::DRAUp,
&CFinalInput::DRADown,
&CFinalInput::DRALeft,
&CFinalInput::DRARight,
&CFinalInput::DLTrigger,
&CFinalInput::DRTrigger,
&CFinalInput::DDPUp,
&CFinalInput::DDPDown,
&CFinalInput::DDPLeft,
&CFinalInput::DDPRight,
&CFinalInput::DA,
&CFinalInput::DB,
&CFinalInput::DX,
&CFinalInput::DY,
&CFinalInput::DZ,
&CFinalInput::DL,
&CFinalInput::DR,
&CFinalInput::DStart,
nullptr,
};
constexpr std::array<FloatReturnFn, 24> skAnalogFuncs{
nullptr,
&CFinalInput::ALAUp,
&CFinalInput::ALADown,
&CFinalInput::ALALeft,
&CFinalInput::ALARight,
&CFinalInput::ARAUp,
&CFinalInput::ARADown,
&CFinalInput::ARALeft,
&CFinalInput::ARARight,
&CFinalInput::ALTrigger,
&CFinalInput::ARTrigger,
&CFinalInput::ADPUp,
&CFinalInput::ADPDown,
&CFinalInput::ADPLeft,
&CFinalInput::ADPRight,
&CFinalInput::AA,
&CFinalInput::AB,
&CFinalInput::AX,
&CFinalInput::AY,
&CFinalInput::AZ,
&CFinalInput::AL,
&CFinalInput::AR,
&CFinalInput::AStart,
nullptr,
};
constexpr std::array<ControlMapper::EKBMFunctionList, 70> skKBMMapping{
ControlMapper::EKBMFunctionList::KeyPress + 'w', // Forward,
ControlMapper::EKBMFunctionList::KeyPress + 's', // Backward,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // TurnLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // TurnRight,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // StrafeLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // StrafeRight,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // LookLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // LookRight,
ControlMapper::EKBMFunctionList::KeyPress + 's', // LookUp,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // LookDown,
ControlMapper::EKBMFunctionList::KeyPress + ' ', // JumpOrBoost = 10,
ControlMapper::EKBMFunctionList::MousePress + boo::EMouseButton::Primary, // FireOrBomb = 11,
ControlMapper::EKBMFunctionList::MousePress + boo::EMouseButton::Secondary, // MissileOrPowerBomb = 12,
ControlMapper::EKBMFunctionList::KeyPress + 'c', // Morph,
ControlMapper::EKBMFunctionList::None, // AimUp,
ControlMapper::EKBMFunctionList::None, // AimDown,
ControlMapper::EKBMFunctionList::None, // CycleBeamUp,
ControlMapper::EKBMFunctionList::None, // CycleBeamDown,
ControlMapper::EKBMFunctionList::None, // CycleItem,
ControlMapper::EKBMFunctionList::KeyPress + '1', // PowerBeam,
ControlMapper::EKBMFunctionList::KeyPress + '3', // IceBeam,
ControlMapper::EKBMFunctionList::KeyPress + '2', // WaveBeam,
ControlMapper::EKBMFunctionList::KeyPress + '4', // PlasmaBeam,
ControlMapper::EKBMFunctionList::None, // ToggleHolster = 23,
ControlMapper::EKBMFunctionList::None, // OrbitClose,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // OrbitFar,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // OrbitObject,
ControlMapper::EKBMFunctionList::None, // OrbitSelect,
ControlMapper::EKBMFunctionList::None, // OrbitConfirm,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // OrbitLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // OrbitRight,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // OrbitUp,
ControlMapper::EKBMFunctionList::KeyPress + 's', // OrbitDown,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // LookHold1,
ControlMapper::EKBMFunctionList::None, // LookHold2,
ControlMapper::EKBMFunctionList::None, // LookZoomIn,
ControlMapper::EKBMFunctionList::None, // LookZoomOut,
ControlMapper::EKBMFunctionList::None, // AimHold,
ControlMapper::EKBMFunctionList::KeyPress + 's', // MapCircleUp,
ControlMapper::EKBMFunctionList::KeyPress + 'w', // MapCircleDown,
ControlMapper::EKBMFunctionList::KeyPress + 'a', // MapCircleLeft,
ControlMapper::EKBMFunctionList::KeyPress + 'd', // MapCircleRight,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Up, // MapMoveForward,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Down, // MapMoveBack,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Left, // MapMoveLeft,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Right, // MapMoveRight,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // MapZoomIn,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // MapZoomOut,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // SpiderBall,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // ChaseCamera,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Right, // XrayVisor = 50,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Down, // ThermoVisor = 51,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Left, // InviroVisor = 52,
ControlMapper::EKBMFunctionList::SpecialKeyPress + boo::ESpecialKey::Up, // NoVisor = 53,
ControlMapper::EKBMFunctionList::None, // VisorMenu,
ControlMapper::EKBMFunctionList::None, // VisorUp,
ControlMapper::EKBMFunctionList::None, // VisorDown,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // ShowCrosshairs,
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UseSheild = 0x3B,
ControlMapper::EKBMFunctionList::KeyPress + 'q', // ScanItem = 0x3C,
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::None, // UNKNOWN
ControlMapper::EKBMFunctionList::KeyPress + 'q', // PreviousPauseScreen = 0x41,
ControlMapper::EKBMFunctionList::KeyPress + 'e', // NextPauseScreen = 0x42,
ControlMapper::EKBMFunctionList::None, // UNKNOWN,
ControlMapper::EKBMFunctionList::None, // None,
ControlMapper::EKBMFunctionList::None,
};
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) {