Merge pull request #96 from lioncash/array2

CFinalInput, ControlMapper: Use std::array where applicable
This commit is contained in:
Phillip Stephens 2019-10-01 06:43:23 -07:00 committed by GitHub
commit d2e9495686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 300 additions and 264 deletions

View File

@ -486,7 +486,7 @@ void CAutoMapper::ProcessMapRotateInput(const CFinalInput& input, const CStateMa
float dirs[4] = {};
bool mouseHeld = false;
if (const auto& kbm = input.GetKBM()) {
if (kbm->m_mouseButtons[int(boo::EMouseButton::Primary)]) {
if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) {
mouseHeld = true;
if (float(m_mouseDelta.x()) < 0.f)
dirs[3] = -m_mouseDelta.x();
@ -664,8 +664,8 @@ void CAutoMapper::ProcessMapPanInput(const CFinalInput& input, const CStateManag
bool mouseHeld = false;
if (const auto& kbm = input.GetKBM()) {
if (kbm->m_mouseButtons[int(boo::EMouseButton::Middle)] ||
kbm->m_mouseButtons[int(boo::EMouseButton::Secondary)]) {
if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Middle)] ||
kbm->m_mouseButtons[size_t(boo::EMouseButton::Secondary)]) {
mouseHeld = true;
if (float(m_mouseDelta.x()) < 0.f)
right += -m_mouseDelta.x();

View File

@ -227,7 +227,7 @@ bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDraw
hit->m_integerScroll.delta[1] -= std::trunc(hit->m_integerScroll.delta[1]);
}
}
if (!m_inMouseDown && kbm->m_mouseButtons[int(boo::EMouseButton::Primary)]) {
if (!m_inMouseDown && kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) {
m_inMouseDown = true;
m_inCancel = false;
m_mouseDownWidget = hit;
@ -235,7 +235,7 @@ bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDraw
m_mouseDownCb(hit, false);
if (hit)
return true;
} else if (m_inMouseDown && !kbm->m_mouseButtons[int(boo::EMouseButton::Primary)]) {
} else if (m_inMouseDown && !kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) {
m_inMouseDown = false;
m_inCancel = false;
if (m_mouseDownWidget == m_lastMouseOverWidget) {

View File

@ -118,10 +118,10 @@ CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData&
, x2c_b28_Z(false)
, x2c_b29_L(false)
, x2c_b30_R(false)
, x2c_b31_DPUp(data.m_specialKeys[int(boo::ESpecialKey::Up)])
, x2d_b24_DPRight(data.m_specialKeys[int(boo::ESpecialKey::Right)])
, x2d_b25_DPDown(data.m_specialKeys[int(boo::ESpecialKey::Down)])
, x2d_b26_DPLeft(data.m_specialKeys[int(boo::ESpecialKey::Left)])
, x2c_b31_DPUp(data.m_specialKeys[size_t(boo::ESpecialKey::Up)])
, x2d_b24_DPRight(data.m_specialKeys[size_t(boo::ESpecialKey::Right)])
, x2d_b25_DPDown(data.m_specialKeys[size_t(boo::ESpecialKey::Down)])
, x2d_b26_DPLeft(data.m_specialKeys[size_t(boo::ESpecialKey::Left)])
, x2d_b27_Start(false)
, x2d_b28_PA(DA() && !prevInput.DA())
, x2d_b29_PB(DB() && !prevInput.DB())
@ -137,12 +137,15 @@ CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData&
, x2e_b31_PStart(DStart() && !prevInput.DStart())
, m_kbm(data) {
if (prevInput.m_kbm) {
for (int i = 0; i < 256; ++i)
for (size_t i = 0; i < m_PCharKeys.size(); ++i) {
m_PCharKeys[i] = data.m_charKeys[i] && !prevInput.m_kbm->m_charKeys[i];
for (int i = 0; i < 26; ++i)
}
for (size_t i = 0; i < m_PSpecialKeys.size(); ++i) {
m_PSpecialKeys[i] = data.m_specialKeys[i] && !prevInput.m_kbm->m_specialKeys[i];
for (int i = 0; i < 6; ++i)
}
for (size_t i = 0; i < m_PMouseButtons.size(); ++i) {
m_PMouseButtons[i] = data.m_mouseButtons[i] && !prevInput.m_kbm->m_mouseButtons[i];
}
}
}
@ -195,12 +198,9 @@ CFinalInput& CFinalInput::operator|=(const CFinalInput& other) {
x2e_b31_PStart |= other.x2e_b31_PStart;
if (other.m_kbm) {
m_kbm = other.m_kbm;
for (int i = 0; i < 256; ++i)
m_PCharKeys[i] = other.m_PCharKeys[i];
for (int i = 0; i < 26; ++i)
m_PSpecialKeys[i] = other.m_PSpecialKeys[i];
for (int i = 0; i < 6; ++i)
m_PMouseButtons[i] = other.m_PMouseButtons[i];
m_PCharKeys = other.m_PCharKeys;
m_PSpecialKeys = other.m_PSpecialKeys;
m_PMouseButtons = other.m_PMouseButtons;
}
return *this;
}

View File

@ -1,5 +1,7 @@
#pragma once
#include <array>
#include "Runtime/RetroTypes.hpp"
#include "Runtime/Input/CKeyboardMouseController.hpp"
@ -62,9 +64,9 @@ struct CFinalInput {
std::optional<CKeyboardMouseControllerData> m_kbm;
bool m_PCharKeys[256] = {};
bool m_PSpecialKeys[26] = {};
bool m_PMouseButtons[6] = {};
std::array<bool, 256> m_PCharKeys{};
std::array<bool, 26> m_PSpecialKeys{};
std::array<bool, 6> m_PMouseButtons{};
float m_leftMul = 1.f;
float m_rightMul = 1.f;
@ -158,12 +160,12 @@ struct CFinalInput {
CFinalInput ScaleAnalogueSticks(float leftDiv, float rightDiv) const;
bool PKey(char k) const { return m_kbm && m_PCharKeys[int(k)]; }
bool PSpecialKey(boo::ESpecialKey k) const { return m_kbm && m_PSpecialKeys[int(k)]; }
bool PMouseButton(boo::EMouseButton k) const { return m_kbm && m_PMouseButtons[int(k)]; }
bool DKey(char k) const { return m_kbm && m_kbm->m_charKeys[int(k)]; }
bool DSpecialKey(boo::ESpecialKey k) const { return m_kbm && m_kbm->m_specialKeys[int(k)]; }
bool DMouseButton(boo::EMouseButton k) const { return m_kbm && m_kbm->m_mouseButtons[int(k)]; }
bool PKey(char k) const { return m_kbm && m_PCharKeys[size_t(k)]; }
bool PSpecialKey(boo::ESpecialKey k) const { return m_kbm && m_PSpecialKeys[size_t(k)]; }
bool PMouseButton(boo::EMouseButton k) const { return m_kbm && m_PMouseButtons[size_t(k)]; }
bool DKey(char k) const { return m_kbm && m_kbm->m_charKeys[size_t(k)]; }
bool DSpecialKey(boo::ESpecialKey k) const { return m_kbm && m_kbm->m_specialKeys[size_t(k)]; }
bool DMouseButton(boo::EMouseButton k) const { return m_kbm && m_kbm->m_mouseButtons[size_t(k)]; }
float AKey(char k) const { return DKey(k) ? 1.f : 0.f; }
float ASpecialKey(boo::ESpecialKey k) const { return DSpecialKey(k) ? 1.f : 0.f; }
float AMouseButton(boo::EMouseButton k) const { return DMouseButton(k) ? 1.f : 0.f; }

View File

@ -49,10 +49,10 @@ public:
* is necessary, only absolute state tracking. */
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey) {
m_data.m_mouseButtons[int(button)] = true;
m_data.m_mouseButtons[size_t(button)] = true;
}
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey) {
m_data.m_mouseButtons[int(button)] = false;
m_data.m_mouseButtons[size_t(button)] = false;
}
void mouseMove(const boo::SWindowCoord& coord) { m_data.m_mouseCoord = coord; }
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta& scroll) { m_data.m_accumScroll += scroll; }
@ -69,8 +69,8 @@ public:
return;
m_data.m_charKeys[charCode] = false;
}
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey, bool) { m_data.m_specialKeys[int(key)] = true; }
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey) { m_data.m_specialKeys[int(key)] = false; }
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey, bool) { m_data.m_specialKeys[size_t(key)] = true; }
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey) { m_data.m_specialKeys[size_t(key)] = false; }
void modKeyDown(boo::EModifierKey mod, bool) { m_data.m_modMask = m_data.m_modMask | mod; }
void modKeyUp(boo::EModifierKey mod) { m_data.m_modMask = m_data.m_modMask & ~mod; }

View File

@ -1,13 +1,14 @@
#pragma once
#include <boo/boo.hpp>
#include <array>
#include <boo/IWindow.hpp>
namespace urde {
struct CKeyboardMouseControllerData {
bool m_charKeys[256] = {};
bool m_specialKeys[26] = {};
bool m_mouseButtons[6] = {};
std::array<bool, 256> m_charKeys{};
std::array<bool, 26> m_specialKeys{};
std::array<bool, 6> m_mouseButtons{};
boo::EModifierKey m_modMask = boo::EModifierKey::None;
boo::SWindowCoord m_mouseCoord;
boo::SScrollDelta m_accumScroll;

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,232 +36,246 @@ 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;
void ControlMapper::SetCommandFiltered(ECommands cmd, bool filtered) { skCommandFilterFlag[int(cmd)] = filtered; }
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) {
if (!skCommandFilterFlag[int(cmd)])
if (!skCommandFilterFlag[size_t(cmd)]) {
return false;
}
bool ret = false;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func < EFunctionList::MAX) {
if (BoolReturnFn fn = skPressFuncs[int(func)])
if (BoolReturnFn fn = skPressFuncs[size_t(func)]) {
ret = (input.*fn)();
}
}
if (const auto& kbm = input.GetKBM()) {
EKBMFunctionList kbmfunc = skKBMMapping[int(cmd)];
const EKBMFunctionList kbmfunc = skKBMMapping[size_t(cmd)];
if (kbmfunc < EKBMFunctionList::MAX) {
if (kbmfunc >= EKBMFunctionList::MousePress)
ret |= input.m_PMouseButtons[int(kbmfunc) - int(EKBMFunctionList::MousePress)];
else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress)
ret |= input.m_PSpecialKeys[int(kbmfunc) - int(EKBMFunctionList::SpecialKeyPress)];
else if (kbmfunc >= EKBMFunctionList::KeyPress)
ret |= input.m_PCharKeys[int(kbmfunc) - int(EKBMFunctionList::KeyPress)];
if (kbmfunc >= EKBMFunctionList::MousePress) {
ret |= input.m_PMouseButtons[size_t(kbmfunc) - size_t(EKBMFunctionList::MousePress)];
} else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress) {
ret |= input.m_PSpecialKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::SpecialKeyPress)];
} else if (kbmfunc >= EKBMFunctionList::KeyPress) {
ret |= input.m_PCharKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::KeyPress)];
}
}
}
return ret;
}
bool ControlMapper::GetDigitalInput(ECommands cmd, const CFinalInput& input) {
if (!skCommandFilterFlag[int(cmd)])
if (!skCommandFilterFlag[size_t(cmd)]) {
return false;
}
bool ret = false;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func < EFunctionList::MAX) {
if (BoolReturnFn fn = skDigitalFuncs[int(func)])
if (BoolReturnFn fn = skDigitalFuncs[size_t(func)])
ret = (input.*fn)();
}
if (const auto& kbm = input.GetKBM()) {
EKBMFunctionList kbmfunc = skKBMMapping[int(cmd)];
EKBMFunctionList kbmfunc = skKBMMapping[size_t(cmd)];
if (kbmfunc < EKBMFunctionList::MAX) {
if (kbmfunc >= EKBMFunctionList::MousePress)
ret |= kbm->m_mouseButtons[int(kbmfunc) - int(EKBMFunctionList::MousePress)];
else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress)
ret |= kbm->m_specialKeys[int(kbmfunc) - int(EKBMFunctionList::SpecialKeyPress)];
else if (kbmfunc >= EKBMFunctionList::KeyPress)
ret |= kbm->m_charKeys[int(kbmfunc) - int(EKBMFunctionList::KeyPress)];
if (kbmfunc >= EKBMFunctionList::MousePress) {
ret |= kbm->m_mouseButtons[size_t(kbmfunc) - size_t(EKBMFunctionList::MousePress)];
} else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress) {
ret |= kbm->m_specialKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::SpecialKeyPress)];
} else if (kbmfunc >= EKBMFunctionList::KeyPress) {
ret |= kbm->m_charKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::KeyPress)];
}
}
}
return ret;
@ -265,52 +283,65 @@ bool ControlMapper::GetDigitalInput(ECommands cmd, const CFinalInput& input) {
static float KBToWASDX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('a')])
if (data.m_charKeys[size_t('a')]) {
retval -= 1.0;
if (data.m_charKeys[int('d')])
}
if (data.m_charKeys[size_t('d')]) {
retval += 1.0;
if (data.m_charKeys[int('w')] ^ data.m_charKeys[int('s')])
}
if (data.m_charKeys[size_t('w')] ^ data.m_charKeys[size_t('s')]) {
retval *= 0.555f;
}
return retval;
}
static float KBToWASDY(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('s')])
if (data.m_charKeys[size_t('s')]) {
retval -= 1.0;
if (data.m_charKeys[int('w')])
}
if (data.m_charKeys[size_t('w')]) {
retval += 1.0;
if (data.m_charKeys[int('a')] ^ data.m_charKeys[int('d')])
}
if (data.m_charKeys[size_t('a')] ^ data.m_charKeys[size_t('d')]) {
retval *= 0.555f;
}
return retval;
}
static float KBToArrowsX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Left)])
if (data.m_specialKeys[size_t(boo::ESpecialKey::Left)]) {
retval -= 1.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Right)])
}
if (data.m_specialKeys[size_t(boo::ESpecialKey::Right)]) {
retval += 1.0;
}
return retval;
}
static float KBToArrowsY(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Down)])
if (data.m_specialKeys[size_t(boo::ESpecialKey::Down)]) {
retval -= 1.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Up)])
}
if (data.m_specialKeys[size_t(boo::ESpecialKey::Up)]) {
retval += 1.0;
}
return retval;
}
float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
if (!skCommandFilterFlag[int(cmd)])
if (!skCommandFilterFlag[size_t(cmd)]) {
return 0.f;
}
float ret = 0.f;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func < EFunctionList::MAX) {
if (FloatReturnFn fn = skAnalogFuncs[int(func)])
if (FloatReturnFn fn = skAnalogFuncs[size_t(func)]) {
ret = (input.*fn)();
}
}
if (const auto& kbm = input.GetKBM()) {
switch (cmd) {
@ -353,14 +384,16 @@ float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
ret = std::max(ret, KBToArrowsX(*kbm));
break;
default: {
EKBMFunctionList kbmfunc = skKBMMapping[int(cmd)];
const EKBMFunctionList kbmfunc = skKBMMapping[size_t(cmd)];
if (kbmfunc < EKBMFunctionList::MAX) {
if (kbmfunc >= EKBMFunctionList::MousePress)
ret = std::max(ret, kbm->m_mouseButtons[int(kbmfunc) - int(EKBMFunctionList::MousePress)] ? 1.f : 0.f);
else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress)
ret = std::max(ret, kbm->m_specialKeys[int(kbmfunc) - int(EKBMFunctionList::SpecialKeyPress)] ? 1.f : 0.f);
else if (kbmfunc >= EKBMFunctionList::KeyPress)
ret = std::max(ret, kbm->m_charKeys[int(kbmfunc) - int(EKBMFunctionList::KeyPress)] ? 1.f : 0.f);
if (kbmfunc >= EKBMFunctionList::MousePress) {
ret = std::max(ret, kbm->m_mouseButtons[size_t(kbmfunc) - size_t(EKBMFunctionList::MousePress)] ? 1.f : 0.f);
} else if (kbmfunc >= EKBMFunctionList::SpecialKeyPress) {
ret = std::max(ret,
kbm->m_specialKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::SpecialKeyPress)] ? 1.f : 0.f);
} else if (kbmfunc >= EKBMFunctionList::KeyPress) {
ret = std::max(ret, kbm->m_charKeys[size_t(kbmfunc) - size_t(EKBMFunctionList::KeyPress)] ? 1.f : 0.f);
}
}
break;
}
@ -373,14 +406,14 @@ const char* ControlMapper::GetDescriptionForCommand(ECommands cmd) {
if (cmd >= ECommands::MAX) {
return nullptr;
}
return skCommandDescs[int(cmd)];
return skCommandDescs[size_t(cmd)];
}
const char* ControlMapper::GetDescriptionForFunction(EFunctionList func) {
if (func >= EFunctionList::MAX) {
return nullptr;
}
return skFunctionDescs[int(func)];
return skFunctionDescs[size_t(func)];
}
} // namespace urde

View File

@ -158,8 +158,8 @@ void CInventoryScreen::ProcessControllerInput(const CFinalInput& input) {
m_lastMouseCoord = mouseCoord;
mouseDelta.x() *= g_Viewport.aspect;
mouseDelta *= 100.f;
if (kbm->m_mouseButtons[int(boo::EMouseButton::Middle)] ||
kbm->m_mouseButtons[int(boo::EMouseButton::Secondary)]) {
if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Middle)] ||
kbm->m_mouseButtons[size_t(boo::EMouseButton::Secondary)]) {
if (float(mouseDelta.x()) < 0.f)
moveRight += -mouseDelta.x();
else if (float(mouseDelta.x()) > 0.f)
@ -169,7 +169,7 @@ void CInventoryScreen::ProcessControllerInput(const CFinalInput& input) {
else if (float(mouseDelta.y()) > 0.f)
moveBack += mouseDelta.y();
}
if (kbm->m_mouseButtons[int(boo::EMouseButton::Primary)]) {
if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) {
if (float(mouseDelta.x()) < 0.f)
circleRight += -mouseDelta.x();
else if (float(mouseDelta.x()) > 0.f)