2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:44:56 +00:00

Initial mouse events for pause screen

This commit is contained in:
Jack Andersen
2019-01-20 18:10:34 -10:00
parent 47c6b5cba8
commit f3f9924309
25 changed files with 620 additions and 176 deletions

View File

@@ -92,51 +92,15 @@ CFinalInput::CFinalInput(int cIdx, float dt, const boo::DolphinControllerState&
, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft())
, x2e_b31_PStart(DStart() && !prevInput.DStart()) {}
static float KBToAnaLeftX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('a')])
retval -= 1.0;
if (data.m_charKeys[int('d')])
retval += 1.0;
return retval;
}
static float KBToAnaLeftY(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('s')])
retval -= 1.0;
if (data.m_charKeys[int('w')])
retval += 1.0;
return retval;
}
static float KBToAnaRightX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('2')])
retval -= 1.0;
if (data.m_charKeys[int('4')])
retval += 1.0;
return retval;
}
static float KBToAnaRightY(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('3')])
retval -= 1.0;
if (data.m_charKeys[int('1')])
retval += 1.0;
return retval;
}
CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& data, const CFinalInput& prevInput)
: x0_dt(dt)
, x4_controllerIdx(cIdx)
, x8_anaLeftX(KBToAnaLeftX(data))
, xc_anaLeftY(KBToAnaLeftY(data))
, x10_anaRightX(KBToAnaRightX(data))
, x14_anaRightY(KBToAnaRightY(data))
, x18_anaLeftTrigger(data.m_charKeys[int('q')] ? 1.0 : 0.0)
, x1c_anaRightTrigger(data.m_charKeys[int('e')] ? 1.0 : 0.0)
, x8_anaLeftX(0.f)
, xc_anaLeftY(0.f)
, x10_anaRightX(0.f)
, x14_anaRightY(0.f)
, x18_anaLeftTrigger(false)
, x1c_anaRightTrigger(false)
, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
@@ -147,13 +111,13 @@ CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData&
, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
, x2c_b24_A(data.m_mouseButtons[int(boo::EMouseButton::Primary)])
, x2c_b25_B(data.m_charKeys[int(' ')])
, x2c_b26_X(data.m_charKeys[int('c')])
, x2c_b27_Y(data.m_mouseButtons[int(boo::EMouseButton::Secondary)])
, x2c_b28_Z(data.m_charKeys[int('\t')])
, x2c_b29_L(data.m_charKeys[int('q')])
, x2c_b30_R(data.m_charKeys[int('e')])
, x2c_b24_A(false)
, x2c_b25_B(false)
, x2c_b26_X(false)
, x2c_b27_Y(false)
, 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)])
@@ -172,15 +136,13 @@ CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData&
, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft())
, x2e_b31_PStart(DStart() && !prevInput.DStart())
, m_kbm(data) {
if (x8_anaLeftX || xc_anaLeftY) {
float len = std::sqrt(x8_anaLeftX * x8_anaLeftX + xc_anaLeftY * xc_anaLeftY);
x8_anaLeftX /= len;
xc_anaLeftY /= len;
}
if (x10_anaRightX || x14_anaRightY) {
float len = std::sqrt(x10_anaRightX * x10_anaRightX + x14_anaRightY * x14_anaRightY);
x10_anaRightX /= len;
x14_anaRightY /= len;
if (prevInput.m_kbm) {
for (int i = 0; i < 256; ++i)
m_PCharKeys[i] = data.m_charKeys[i] && !prevInput.m_kbm->m_charKeys[i];
for (int i = 0; i < 26; ++i)
m_PSpecialKeys[i] = data.m_specialKeys[i] && !prevInput.m_kbm->m_specialKeys[i];
for (int i = 0; i < 6; ++i)
m_PMouseButtons[i] = data.m_mouseButtons[i] && !prevInput.m_kbm->m_mouseButtons[i];
}
}
@@ -231,8 +193,15 @@ CFinalInput& CFinalInput::operator|=(const CFinalInput& other) {
x2e_b29_PDPDown |= other.x2e_b29_PDPDown;
x2e_b30_PDPLeft |= other.x2e_b30_PDPLeft;
x2e_b31_PStart |= other.x2e_b31_PStart;
if (other.m_kbm)
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];
}
return *this;
}
@@ -242,6 +211,8 @@ CFinalInput CFinalInput::ScaleAnalogueSticks(float leftDiv, float rightDiv) cons
ret.xc_anaLeftY = zeus::clamp(-1.f, xc_anaLeftY / leftDiv, 1.f);
ret.x10_anaRightX = zeus::clamp(-1.f, x10_anaRightX / rightDiv, 1.f);
ret.x14_anaRightY = zeus::clamp(-1.f, x14_anaRightY / rightDiv, 1.f);
ret.m_leftMul = 1.f / leftDiv;
ret.m_rightMul = 1.f / rightDiv;
return ret;
}
} // namespace urde

View File

@@ -61,6 +61,13 @@ struct CFinalInput {
std::experimental::optional<CKeyboardMouseControllerData> m_kbm;
bool m_PCharKeys[256] = {};
bool m_PSpecialKeys[26] = {};
bool m_PMouseButtons[6] = {};
float m_leftMul = 1.f;
float m_rightMul = 1.f;
CFinalInput();
CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput, float leftDiv,
float rightDiv);
@@ -146,6 +153,16 @@ struct CFinalInput {
CFinalInput ScaleAnalogueSticks(float leftDiv, float rightDiv) const;
bool PKey(char k) const { return m_kbm && m_PCharKeys[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[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 AKey(char k) const { return DKey(k) ? 1.f : 0.f; }
bool ASpecialKey(boo::ESpecialKey k) const { return DSpecialKey(k) ? 1.f : 0.f; }
bool AMouseButton(boo::EMouseButton k) const { return DMouseButton(k) ? 1.f : 0.f; }
const std::experimental::optional<CKeyboardMouseControllerData>& GetKBM() const { return m_kbm; }
};

View File

@@ -123,6 +123,79 @@ static FloatReturnFn skAnalogFuncs[] = {nullptr,
&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
};
#define kCommandFilterCount 67
static bool skCommandFilterFlag[kCommandFilterCount] = {true};
@@ -136,37 +209,149 @@ void ControlMapper::ResetCommandFilters() {
bool ControlMapper::GetPressInput(ECommands cmd, const CFinalInput& input) {
if (!skCommandFilterFlag[int(cmd)])
return false;
bool ret = false;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func > EFunctionList::MAX)
return false;
BoolReturnFn fn = skPressFuncs[int(func)];
if (!fn)
return false;
return (input.*fn)();
if (func < EFunctionList::MAX) {
if (BoolReturnFn fn = skPressFuncs[int(func)])
ret = (input.*fn)();
}
if (const auto& kbm = input.GetKBM()) {
EKBMFunctionList kbmfunc = skKBMMapping[int(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)];
}
}
return ret;
}
bool ControlMapper::GetDigitalInput(ECommands cmd, const CFinalInput& input) {
if (!skCommandFilterFlag[int(cmd)])
return false;
bool ret = false;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func > EFunctionList::MAX)
return false;
BoolReturnFn fn = skDigitalFuncs[int(func)];
if (!fn)
return false;
return (input.*fn)();
if (func < EFunctionList::MAX) {
if (BoolReturnFn fn = skDigitalFuncs[int(func)])
ret = (input.*fn)();
}
if (const auto& kbm = input.GetKBM()) {
EKBMFunctionList kbmfunc = skKBMMapping[int(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)];
}
}
return ret;
}
static float KBToWASDX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('a')])
retval -= 1.0;
if (data.m_charKeys[int('d')])
retval += 1.0;
return retval;
}
static float KBToWASDY(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_charKeys[int('s')])
retval -= 1.0;
if (data.m_charKeys[int('w')])
retval += 1.0;
return retval;
}
static float KBToArrowsX(const CKeyboardMouseControllerData& data) {
float retval = 0.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Left)])
retval -= 1.0;
if (data.m_specialKeys[int(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)])
retval -= 1.0;
if (data.m_specialKeys[int(boo::ESpecialKey::Up)])
retval += 1.0;
return retval;
}
float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
if (!skCommandFilterFlag[int(cmd)])
return 0.0;
return 0.f;
float ret = 0.f;
EFunctionList func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd)));
if (func > EFunctionList::MAX)
return 0.0;
FloatReturnFn fn = skAnalogFuncs[int(func)];
if (!fn)
return 0.0;
return (input.*fn)();
if (func < EFunctionList::MAX) {
if (FloatReturnFn fn = skAnalogFuncs[int(func)])
ret = (input.*fn)();
}
if (const auto& kbm = input.GetKBM()) {
switch (cmd) {
case ECommands::Forward:
case ECommands::LookDown:
case ECommands::OrbitUp:
case ECommands::MapCircleDown:
ret = std::max(ret, KBToWASDY(*kbm) * input.m_leftMul);
break;
case ECommands::Backward:
case ECommands::LookUp:
case ECommands::OrbitDown:
case ECommands::MapCircleUp:
ret = std::max(ret, -KBToWASDY(*kbm) * input.m_leftMul);
break;
case ECommands::TurnLeft:
case ECommands::StrafeLeft:
case ECommands::LookLeft:
case ECommands::OrbitLeft:
case ECommands::MapCircleLeft:
ret = std::max(ret, -KBToWASDX(*kbm) * input.m_leftMul);
break;
case ECommands::TurnRight:
case ECommands::StrafeRight:
case ECommands::LookRight:
case ECommands::OrbitRight:
case ECommands::MapCircleRight:
ret = std::max(ret, KBToWASDX(*kbm) * input.m_leftMul);
break;
case ECommands::MapMoveForward:
ret = std::max(ret, KBToArrowsY(*kbm));
break;
case ECommands::MapMoveBack:
ret = std::max(ret, -KBToArrowsY(*kbm));
break;
case ECommands::MapMoveLeft:
ret = std::max(ret, -KBToArrowsX(*kbm));
break;
case ECommands::MapMoveRight:
ret = std::max(ret, KBToArrowsX(*kbm));
break;
default: {
EKBMFunctionList kbmfunc = skKBMMapping[int(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);
}
break;
}
}
}
return ret;
}
const char* ControlMapper::GetDescriptionForCommand(ECommands cmd) {

View File

@@ -1,5 +1,7 @@
#pragma once
#include "boo/IWindow.hpp"
namespace urde {
struct CFinalInput;
@@ -100,6 +102,14 @@ public:
MAX // default case
};
enum class EKBMFunctionList {
None,
KeyPress,
SpecialKeyPress = 259,
MousePress = 285,
MAX = 291 /* Provide space for keys/buttons within base actions */
};
static void SetCommandFiltered(ECommands cmd, bool filtered);
static void ResetCommandFilters();
static bool GetPressInput(ECommands cmd, const CFinalInput& input);
@@ -109,4 +119,19 @@ public:
static const char* GetDescriptionForFunction(EFunctionList func);
};
constexpr ControlMapper::EKBMFunctionList operator+(ControlMapper::EKBMFunctionList a, char b) {
using T = std::underlying_type_t<ControlMapper::EKBMFunctionList>;
return ControlMapper::EKBMFunctionList(static_cast<T>(a) + static_cast<T>(b));
}
constexpr ControlMapper::EKBMFunctionList operator+(ControlMapper::EKBMFunctionList a, boo::ESpecialKey b) {
using T = std::underlying_type_t<ControlMapper::EKBMFunctionList>;
return ControlMapper::EKBMFunctionList(static_cast<T>(a) + static_cast<T>(b));
}
constexpr ControlMapper::EKBMFunctionList operator+(ControlMapper::EKBMFunctionList a, boo::EMouseButton b) {
using T = std::underlying_type_t<ControlMapper::EKBMFunctionList>;
return ControlMapper::EKBMFunctionList(static_cast<T>(a) + static_cast<T>(b));
}
} // namespace urde