mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-15 04:06:09 +00:00
SDL controller input
This commit is contained in:
@@ -6,16 +6,61 @@ namespace metaforce {
|
||||
|
||||
CFinalInput::CFinalInput() = default;
|
||||
|
||||
CFinalInput::CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput,
|
||||
//CFinalInput::CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput,
|
||||
// float leftDiv, float rightDiv)
|
||||
//: x0_dt(dt)
|
||||
//, x4_controllerIdx(cIdx)
|
||||
//, x8_anaLeftX(zeus::clamp(-1.0f, data.m_leftStick[0] / 72.0f / leftDiv, 1.0f))
|
||||
//, xc_anaLeftY(zeus::clamp(-1.0f, data.m_leftStick[1] / 72.0f / leftDiv, 1.0f))
|
||||
//, x10_anaRightX(zeus::clamp(-1.0f, data.m_rightStick[0] / 59.0f / rightDiv, 1.0f))
|
||||
//, x14_anaRightY(zeus::clamp(-1.0f, data.m_rightStick[1] / 59.0f / rightDiv, 1.0f))
|
||||
//, x18_anaLeftTrigger(data.m_analogTriggers[0] * 0.007f)
|
||||
//, x1c_anaRightTrigger(data.m_analogTriggers[1] * 0.007f)
|
||||
//, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
|
||||
//, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
|
||||
//, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
|
||||
//, x21_enableAnaLeftNegYP(DLADown() && !prevInput.DLADown())
|
||||
//, x22_enableAnaRightXP(DRARight() && !prevInput.DRARight())
|
||||
//, x22_enableAnaRightNegXP(DRALeft() && !prevInput.DRALeft())
|
||||
//, x23_enableAnaRightYP(DRAUp() && !prevInput.DRAUp())
|
||||
//, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
|
||||
//, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
|
||||
//, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
|
||||
//, x2c_b24_A(data.m_btns & uint16_t(boo::EDolphinControllerButtons::A))
|
||||
//, x2c_b25_B(data.m_btns & uint16_t(boo::EDolphinControllerButtons::B))
|
||||
//, x2c_b26_X(data.m_btns & uint16_t(boo::EDolphinControllerButtons::X))
|
||||
//, x2c_b27_Y(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Y))
|
||||
//, x2c_b28_Z(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Z))
|
||||
//, x2c_b29_L(data.m_btns & uint16_t(boo::EDolphinControllerButtons::L))
|
||||
//, x2c_b30_R(data.m_btns & uint16_t(boo::EDolphinControllerButtons::R))
|
||||
//, x2c_b31_DPUp(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Up))
|
||||
//, x2d_b24_DPRight(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Right))
|
||||
//, x2d_b25_DPDown(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Down))
|
||||
//, x2d_b26_DPLeft(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Left))
|
||||
//, x2d_b27_Start(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Start))
|
||||
//, x2d_b28_PA(DA() && !prevInput.DA())
|
||||
//, x2d_b29_PB(DB() && !prevInput.DB())
|
||||
//, x2d_b30_PX(DX() && !prevInput.DX())
|
||||
//, x2d_b31_PY(DY() && !prevInput.DY())
|
||||
//, x2e_b24_PZ(DZ() && !prevInput.DZ())
|
||||
//, x2e_b25_PL(DL() && !prevInput.DL())
|
||||
//, x2e_b26_PR(DR() && !prevInput.DR())
|
||||
//, x2e_b27_PDPUp(DDPUp() && !prevInput.DDPUp())
|
||||
//, x2e_b28_PDPRight(DDPRight() && !prevInput.DDPRight())
|
||||
//, x2e_b29_PDPDown(DDPDown() && !prevInput.DDPDown())
|
||||
//, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft())
|
||||
//, x2e_b31_PStart(DStart() && !prevInput.DStart()) {}
|
||||
|
||||
CFinalInput::CFinalInput(int cIdx, float dt, const SAuroraControllerState& data, const CFinalInput& prevInput,
|
||||
float leftDiv, float rightDiv)
|
||||
: x0_dt(dt)
|
||||
, x4_controllerIdx(cIdx)
|
||||
, x8_anaLeftX(zeus::clamp(-1.0f, data.m_leftStick[0] / 72.0f / leftDiv, 1.0f))
|
||||
, xc_anaLeftY(zeus::clamp(-1.0f, data.m_leftStick[1] / 72.0f / leftDiv, 1.0f))
|
||||
, x10_anaRightX(zeus::clamp(-1.0f, data.m_rightStick[0] / 59.0f / rightDiv, 1.0f))
|
||||
, x14_anaRightY(zeus::clamp(-1.0f, data.m_rightStick[1] / 59.0f / rightDiv, 1.0f))
|
||||
, x18_anaLeftTrigger(data.m_analogTriggers[0] * 0.007f)
|
||||
, x1c_anaRightTrigger(data.m_analogTriggers[1] * 0.007f)
|
||||
, x8_anaLeftX(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::LeftX)] / 72.0f / leftDiv, 1.0f))
|
||||
, xc_anaLeftY(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::LeftY)] / 72.0f / leftDiv, 1.0f))
|
||||
, x10_anaRightX(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::RightX)] / 59.0f / rightDiv, 1.0f))
|
||||
, x14_anaRightY(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::RightY)] / 59.0f / rightDiv, 1.0f))
|
||||
, x18_anaLeftTrigger(data.m_axes[size_t(aurora::ControllerAxis::TriggerLeft)] * 0.007f)
|
||||
, x1c_anaRightTrigger(data.m_axes[size_t(aurora::ControllerAxis::TriggerRight)] * 0.007f)
|
||||
, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
|
||||
, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
|
||||
, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
|
||||
@@ -26,18 +71,18 @@ CFinalInput::CFinalInput(int cIdx, float dt, const boo::DolphinControllerState&
|
||||
, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
|
||||
, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
|
||||
, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
|
||||
, x2c_b24_A(data.m_btns & uint16_t(boo::EDolphinControllerButtons::A))
|
||||
, x2c_b25_B(data.m_btns & uint16_t(boo::EDolphinControllerButtons::B))
|
||||
, x2c_b26_X(data.m_btns & uint16_t(boo::EDolphinControllerButtons::X))
|
||||
, x2c_b27_Y(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Y))
|
||||
, x2c_b28_Z(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Z))
|
||||
, x2c_b29_L(data.m_btns & uint16_t(boo::EDolphinControllerButtons::L))
|
||||
, x2c_b30_R(data.m_btns & uint16_t(boo::EDolphinControllerButtons::R))
|
||||
, x2c_b31_DPUp(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Up))
|
||||
, x2d_b24_DPRight(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Right))
|
||||
, x2d_b25_DPDown(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Down))
|
||||
, x2d_b26_DPLeft(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Left))
|
||||
, x2d_b27_Start(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Start))
|
||||
, x2c_b24_A(data.m_btns[size_t(aurora::ControllerButton::A)])
|
||||
, x2c_b25_B(data.m_btns[size_t(aurora::ControllerButton::B)])
|
||||
, x2c_b26_X(data.m_btns[size_t(aurora::ControllerButton::X)])
|
||||
, x2c_b27_Y(data.m_btns[size_t(aurora::ControllerButton::Y)])
|
||||
, x2c_b28_Z(data.m_btns[size_t(aurora::ControllerButton::RightShoulder)])
|
||||
, x2c_b29_L(data.m_axes[size_t(aurora::ControllerAxis::TriggerLeft)] > 29490)
|
||||
, x2c_b30_R(data.m_axes[size_t(aurora::ControllerAxis::TriggerRight)] > 29490)
|
||||
, x2c_b31_DPUp(data.m_btns[size_t(aurora::ControllerButton::DPadUp)])
|
||||
, x2d_b24_DPRight(data.m_btns[size_t(aurora::ControllerButton::DPadRight)])
|
||||
, x2d_b25_DPDown(data.m_btns[size_t(aurora::ControllerButton::DPadDown)])
|
||||
, x2d_b26_DPLeft(data.m_btns[size_t(aurora::ControllerButton::DPadLeft)])
|
||||
, x2d_b27_Start(data.m_btns[size_t(aurora::ControllerButton::Start)])
|
||||
, x2d_b28_PA(DA() && !prevInput.DA())
|
||||
, x2d_b29_PB(DB() && !prevInput.DB())
|
||||
, x2d_b30_PX(DX() && !prevInput.DX())
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "Runtime/RetroTypes.hpp"
|
||||
#include "Runtime/Input/CKeyboardMouseController.hpp"
|
||||
#include "Runtime/RetroTypes.hpp"
|
||||
|
||||
#include <boo/inputdev/DolphinSmashAdapter.hpp>
|
||||
#include "aurora.h"
|
||||
|
||||
//#include <boo/inputdev/DolphinSmashAdapter.hpp>
|
||||
|
||||
namespace metaforce {
|
||||
|
||||
struct SAuroraControllerState {
|
||||
std::array<int16_t, size_t(aurora::ControllerAxis::MAX)> m_axes{};
|
||||
std::bitset<size_t(aurora::ControllerButton::MAX)> m_btns{};
|
||||
};
|
||||
|
||||
struct CFinalInput {
|
||||
float x0_dt = 0.0f;
|
||||
u32 x4_controllerIdx = 0;
|
||||
@@ -72,7 +79,9 @@ struct CFinalInput {
|
||||
float m_rightMul = 1.f;
|
||||
|
||||
CFinalInput();
|
||||
CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput, float leftDiv,
|
||||
// CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput, float leftDiv,
|
||||
// float rightDiv);
|
||||
CFinalInput(int cIdx, float dt, const SAuroraControllerState& data, const CFinalInput& prevInput, float leftDiv,
|
||||
float rightDiv);
|
||||
CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& data, const CFinalInput& prevInput);
|
||||
|
||||
|
||||
@@ -11,33 +11,31 @@ void CInputGenerator::Update(float dt, CArchitectureQueue& queue) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Keyboard/Mouse first */
|
||||
CFinalInput kbInput = getFinalInput(0, dt);
|
||||
bool kbUsed = false;
|
||||
const CFinalInput& kbInput = getFinalInput(0, dt);
|
||||
queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, kbInput));
|
||||
|
||||
/* Dolphin controllers next */
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
bool connected;
|
||||
EStatusChange change = m_dolphinCb.getStatusChange(i, connected);
|
||||
if (change != EStatusChange::NoChange)
|
||||
queue.Push(MakeMsg::CreateControllerStatus(EArchMsgTarget::Game, i, connected));
|
||||
if (connected) {
|
||||
CFinalInput input = m_dolphinCb.getFinalInput(i, dt, m_leftDiv, m_rightDiv);
|
||||
if (i == 0) /* Merge KB input with first controller */
|
||||
{
|
||||
input |= kbInput;
|
||||
kbUsed = true;
|
||||
}
|
||||
m_lastUpdate = input;
|
||||
queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, input));
|
||||
}
|
||||
}
|
||||
// for (int i = 0; i < 4; ++i) {
|
||||
// bool connected;
|
||||
// EStatusChange change = m_dolphinCb.getStatusChange(i, connected);
|
||||
// if (change != EStatusChange::NoChange)
|
||||
// queue.Push(MakeMsg::CreateControllerStatus(EArchMsgTarget::Game, i, connected));
|
||||
// if (connected) {
|
||||
// CFinalInput input = m_dolphinCb.getFinalInput(i, dt, m_leftDiv, m_rightDiv);
|
||||
// if (i == 0) /* Merge KB input with first controller */
|
||||
// {
|
||||
// input |= kbInput;
|
||||
// kbUsed = true;
|
||||
// }
|
||||
// m_lastUpdate = input;
|
||||
// queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, input));
|
||||
// }
|
||||
// }
|
||||
|
||||
/* Send straight keyboard input if no first controller present */
|
||||
if (!kbUsed) {
|
||||
m_lastUpdate = kbInput;
|
||||
queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, kbInput));
|
||||
}
|
||||
// /* Send straight keyboard input if no first controller present */
|
||||
// if (!kbUsed) {
|
||||
// m_lastUpdate = kbInput;
|
||||
// }
|
||||
}
|
||||
|
||||
} // namespace metaforce
|
||||
|
||||
@@ -16,7 +16,7 @@ enum class EIOPort { Zero, One, Two, Three };
|
||||
|
||||
enum class EMotorState { Stop, Rumble, StopHard };
|
||||
|
||||
class CInputGenerator : public boo::DeviceFinder {
|
||||
class CInputGenerator /*: public boo::DeviceFinder*/ {
|
||||
enum class EStatusChange { NoChange = 0, Connected = 1, Disconnected = 2 };
|
||||
|
||||
/* When the sticks are used as logical (digital) input,
|
||||
@@ -25,10 +25,14 @@ class CInputGenerator : public boo::DeviceFinder {
|
||||
float m_leftDiv;
|
||||
float m_rightDiv;
|
||||
CKeyboardMouseControllerData m_data;
|
||||
SAuroraControllerState m_state;
|
||||
|
||||
CFinalInput m_lastUpdate;
|
||||
const CFinalInput& getFinalInput(unsigned idx, float dt) {
|
||||
m_lastUpdate = CFinalInput(idx, dt, m_data, m_lastUpdate);
|
||||
auto input = CFinalInput(idx, dt, m_data, m_lastUpdate);
|
||||
// Merge controller input with kb/m input
|
||||
input |= CFinalInput(idx, dt, m_state, m_lastUpdate, m_leftDiv, m_rightDiv);
|
||||
m_lastUpdate = input;
|
||||
return m_lastUpdate;
|
||||
}
|
||||
|
||||
@@ -36,13 +40,22 @@ class CInputGenerator : public boo::DeviceFinder {
|
||||
|
||||
public:
|
||||
CInputGenerator(float leftDiv, float rightDiv)
|
||||
: boo::DeviceFinder({dev_typeid(DolphinSmashAdapter)}), m_leftDiv(leftDiv), m_rightDiv(rightDiv) {}
|
||||
: /*boo::DeviceFinder({dev_typeid(DolphinSmashAdapter)}),*/ m_leftDiv(leftDiv), m_rightDiv(rightDiv) {}
|
||||
|
||||
~CInputGenerator() override {
|
||||
if (smashAdapter) {
|
||||
smashAdapter->setCallback(nullptr);
|
||||
smashAdapter->closeDevice();
|
||||
}
|
||||
// ~CInputGenerator() override {
|
||||
// if (smashAdapter) {
|
||||
// smashAdapter->setCallback(nullptr);
|
||||
// smashAdapter->closeDevice();
|
||||
// }
|
||||
// }
|
||||
|
||||
void controllerButton(uint32_t idx, aurora::ControllerButton button, bool pressed) noexcept {
|
||||
// TODO check idx
|
||||
m_state.m_btns.set(size_t(button), pressed);
|
||||
}
|
||||
void controllerAxis(uint32_t idx, aurora::ControllerAxis axis, int16_t value) noexcept {
|
||||
// TODO check idx
|
||||
m_state.m_axes[size_t(axis)] = value;
|
||||
}
|
||||
|
||||
/* Keyboard and mouse events are delivered on the main game
|
||||
@@ -79,103 +92,77 @@ public:
|
||||
|
||||
void reset() { m_data.m_accumScroll.zeroOut(); }
|
||||
|
||||
/* Input via the smash adapter is received asynchronously on a USB
|
||||
* report thread. This class atomically exchanges that data to the
|
||||
* game thread as needed */
|
||||
struct DolphinSmashAdapterCallback : boo::IDolphinSmashAdapterCallback {
|
||||
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 */
|
||||
m_statusChanges[idx].store(EStatusChange::Connected);
|
||||
}
|
||||
void controllerDisconnected(unsigned idx) override {
|
||||
/* Controller thread */
|
||||
std::unique_lock lk{m_stateLock};
|
||||
m_statusChanges[idx].store(EStatusChange::Disconnected);
|
||||
m_states[idx].reset();
|
||||
}
|
||||
void controllerUpdate(unsigned idx, boo::EDolphinControllerType,
|
||||
const boo::DolphinControllerState& state) override {
|
||||
/* Controller thread */
|
||||
std::unique_lock lk{m_stateLock};
|
||||
m_states[idx] = state;
|
||||
}
|
||||
// /* Input via the smash adapter is received asynchronously on a USB
|
||||
// * report thread. This class atomically exchanges that data to the
|
||||
// * game thread as needed */
|
||||
// struct DolphinSmashAdapterCallback : boo::IDolphinSmashAdapterCallback {
|
||||
// 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 */
|
||||
// m_statusChanges[idx].store(EStatusChange::Connected);
|
||||
// }
|
||||
// void controllerDisconnected(unsigned idx) override {
|
||||
// /* Controller thread */
|
||||
// std::unique_lock lk{m_stateLock};
|
||||
// m_statusChanges[idx].store(EStatusChange::Disconnected);
|
||||
// m_states[idx].reset();
|
||||
// }
|
||||
// void controllerUpdate(unsigned idx, boo::EDolphinControllerType,
|
||||
// const boo::DolphinControllerState& state) override {
|
||||
// /* Controller thread */
|
||||
// std::unique_lock lk{m_stateLock};
|
||||
// m_states[idx] = state;
|
||||
// }
|
||||
//
|
||||
// std::array<CFinalInput, 4> m_lastUpdates;
|
||||
// const CFinalInput& getFinalInput(unsigned idx, float dt, float leftDiv, float rightDiv) {
|
||||
// /* Game thread */
|
||||
// std::unique_lock lk{m_stateLock};
|
||||
// boo::DolphinControllerState state = m_states[idx];
|
||||
// lk.unlock();
|
||||
// state.clamp(); /* PADClamp equivalent */
|
||||
// m_lastUpdates[idx] = CFinalInput(idx, dt, state, m_lastUpdates[idx], leftDiv, rightDiv);
|
||||
// return m_lastUpdates[idx];
|
||||
// }
|
||||
// EStatusChange getStatusChange(unsigned idx, bool& connected) {
|
||||
// /* Game thread */
|
||||
// EStatusChange ch = m_statusChanges[idx].exchange(EStatusChange::NoChange);
|
||||
// if (ch == EStatusChange::Connected)
|
||||
// m_connected[idx] = true;
|
||||
// else if (ch == EStatusChange::Disconnected)
|
||||
// m_connected[idx] = false;
|
||||
// connected = m_connected[idx];
|
||||
// return ch;
|
||||
// }
|
||||
// } m_dolphinCb;
|
||||
|
||||
std::array<CFinalInput, 4> m_lastUpdates;
|
||||
const CFinalInput& getFinalInput(unsigned idx, float dt, float leftDiv, float rightDiv) {
|
||||
/* Game thread */
|
||||
std::unique_lock lk{m_stateLock};
|
||||
boo::DolphinControllerState state = m_states[idx];
|
||||
lk.unlock();
|
||||
state.clamp(); /* PADClamp equivalent */
|
||||
m_lastUpdates[idx] = CFinalInput(idx, dt, state, m_lastUpdates[idx], leftDiv, rightDiv);
|
||||
return m_lastUpdates[idx];
|
||||
}
|
||||
EStatusChange getStatusChange(unsigned idx, bool& connected) {
|
||||
/* Game thread */
|
||||
EStatusChange ch = m_statusChanges[idx].exchange(EStatusChange::NoChange);
|
||||
if (ch == EStatusChange::Connected)
|
||||
m_connected[idx] = true;
|
||||
else if (ch == EStatusChange::Disconnected)
|
||||
m_connected[idx] = false;
|
||||
connected = m_connected[idx];
|
||||
return ch;
|
||||
}
|
||||
} m_dolphinCb;
|
||||
|
||||
/* Device connection/disconnection events are handled on a separate thread
|
||||
* using the relevant OS API. This thread blocks in a loop until an event is
|
||||
* received. Device pointers should only be manipulated by this thread using
|
||||
* the deviceConnected() and deviceDisconnected() callbacks. */
|
||||
std::shared_ptr<boo::DolphinSmashAdapter> smashAdapter;
|
||||
void deviceConnected(boo::DeviceToken& tok) override {
|
||||
/* Device listener thread */
|
||||
if (!smashAdapter) {
|
||||
auto dev = tok.openAndGetDevice();
|
||||
if (dev && dev->getTypeHash() == dev_typeid(DolphinSmashAdapter)) {
|
||||
smashAdapter = std::static_pointer_cast<boo::DolphinSmashAdapter>(tok.openAndGetDevice());
|
||||
smashAdapter->setCallback(&m_dolphinCb);
|
||||
}
|
||||
}
|
||||
}
|
||||
void deviceDisconnected(boo::DeviceToken&, boo::DeviceBase* device) override {
|
||||
if (smashAdapter.get() == device)
|
||||
smashAdapter.reset();
|
||||
}
|
||||
// /* Device connection/disconnection events are handled on a separate thread
|
||||
// * using the relevant OS API. This thread blocks in a loop until an event is
|
||||
// * received. Device pointers should only be manipulated by this thread using
|
||||
// * the deviceConnected() and deviceDisconnected() callbacks. */
|
||||
// std::shared_ptr<boo::DolphinSmashAdapter> smashAdapter;
|
||||
// void deviceConnected(boo::DeviceToken& tok) override {
|
||||
// /* Device listener thread */
|
||||
// if (!smashAdapter) {
|
||||
// auto dev = tok.openAndGetDevice();
|
||||
// if (dev && dev->getTypeHash() == dev_typeid(DolphinSmashAdapter)) {
|
||||
// smashAdapter = std::static_pointer_cast<boo::DolphinSmashAdapter>(tok.openAndGetDevice());
|
||||
// smashAdapter->setCallback(&m_dolphinCb);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// void deviceDisconnected(boo::DeviceToken&, boo::DeviceBase* device) override {
|
||||
// if (smashAdapter.get() == device)
|
||||
// smashAdapter.reset();
|
||||
// }
|
||||
void SetMotorState(EIOPort port, EMotorState state) {
|
||||
if (smashAdapter) {
|
||||
switch (state) {
|
||||
case EMotorState::Stop:
|
||||
smashAdapter->stopRumble(unsigned(port));
|
||||
break;
|
||||
case EMotorState::Rumble:
|
||||
smashAdapter->startRumble(unsigned(port));
|
||||
break;
|
||||
case EMotorState::StopHard:
|
||||
smashAdapter->stopRumble(unsigned(port), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO aurora
|
||||
}
|
||||
void ControlAllMotors(const std::array<EMotorState, 4>& states) {
|
||||
if (smashAdapter) {
|
||||
for (size_t i = 0; i < states.size(); ++i) {
|
||||
switch (states[i]) {
|
||||
case EMotorState::Stop:
|
||||
smashAdapter->stopRumble(i);
|
||||
break;
|
||||
case EMotorState::Rumble:
|
||||
smashAdapter->startRumble(i);
|
||||
break;
|
||||
case EMotorState::StopHard:
|
||||
smashAdapter->stopRumble(i, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO aurora
|
||||
}
|
||||
|
||||
/* This is where the game thread enters */
|
||||
|
||||
Reference in New Issue
Block a user