diff --git a/src/input/api/Controller.h b/src/input/api/Controller.h index 8b1c8e62..e2475191 100644 --- a/src/input/api/Controller.h +++ b/src/input/api/Controller.h @@ -2,6 +2,7 @@ #include "input/InputManager.h" #include "input/motion/MotionSample.h" +#include "input/api/ControllerState.h" namespace pugi { @@ -118,6 +119,7 @@ public: virtual bool has_position() { return false; } virtual glm::vec2 get_position() { return {}; } virtual glm::vec2 get_prev_position() { return {}; } + virtual PositionVisibility GetPositionVisibility() {return PositionVisibility::NONE;}; virtual bool has_rumble() { return false; } virtual void start_rumble() {} diff --git a/src/input/api/ControllerState.h b/src/input/api/ControllerState.h index ce79a1e0..65bfec9f 100644 --- a/src/input/api/ControllerState.h +++ b/src/input/api/ControllerState.h @@ -3,6 +3,12 @@ #include #include "util/helpers/fspinlock.h" +enum class PositionVisibility { + NONE = 0, + FULL = 1, + PARTIAL = 2 +}; + // helper class for storing and managing button press states in a thread-safe manner struct ControllerButtonState { diff --git a/src/input/api/DSU/DSUController.cpp b/src/input/api/DSU/DSUController.cpp index f134440c..082f7e39 100644 --- a/src/input/api/DSU/DSUController.cpp +++ b/src/input/api/DSU/DSUController.cpp @@ -93,6 +93,13 @@ glm::vec2 DSUController::get_prev_position() return {}; } +PositionVisibility DSUController::GetPositionVisibility() +{ + const auto state = m_provider->get_prev_state(m_index); + + return (state.data.tpad1.active || state.data.tpad2.active) ? PositionVisibility::FULL : PositionVisibility::NONE; +} + std::string DSUController::get_button_name(uint64 button) const { switch (button) diff --git a/src/input/api/DSU/DSUController.h b/src/input/api/DSU/DSUController.h index 801f609c..e6e2936d 100644 --- a/src/input/api/DSU/DSUController.h +++ b/src/input/api/DSU/DSUController.h @@ -32,6 +32,7 @@ public: bool has_position() override; glm::vec2 get_position() override; glm::vec2 get_prev_position() override; + PositionVisibility GetPositionVisibility() override; std::string get_button_name(uint64 button) const override; diff --git a/src/input/api/Wiimote/NativeWiimoteController.cpp b/src/input/api/Wiimote/NativeWiimoteController.cpp index 3f9e82a5..9aa56d9c 100644 --- a/src/input/api/Wiimote/NativeWiimoteController.cpp +++ b/src/input/api/Wiimote/NativeWiimoteController.cpp @@ -98,6 +98,11 @@ glm::vec2 NativeWiimoteController::get_prev_position() const auto state = m_provider->get_state(m_index); return state.ir_camera.m_prev_position; } +PositionVisibility NativeWiimoteController::GetPositionVisibility() +{ + const auto state = m_provider->get_state(m_index); + return state.ir_camera.m_positionVisibility; +} bool NativeWiimoteController::has_low_battery() { diff --git a/src/input/api/Wiimote/NativeWiimoteController.h b/src/input/api/Wiimote/NativeWiimoteController.h index ed3caa08..8e9c0774 100644 --- a/src/input/api/Wiimote/NativeWiimoteController.h +++ b/src/input/api/Wiimote/NativeWiimoteController.h @@ -40,6 +40,7 @@ public: bool has_position() override; glm::vec2 get_position() override; glm::vec2 get_prev_position() override; + PositionVisibility GetPositionVisibility() override; bool has_motion() override { return true; } bool has_rumble() override { return true; } diff --git a/src/input/api/Wiimote/WiimoteControllerProvider.cpp b/src/input/api/Wiimote/WiimoteControllerProvider.cpp index 5aac3fe4..c80f3fbe 100644 --- a/src/input/api/Wiimote/WiimoteControllerProvider.cpp +++ b/src/input/api/Wiimote/WiimoteControllerProvider.cpp @@ -766,14 +766,20 @@ void WiimoteControllerProvider::calculate_ir_position(WiimoteState& wiimote_stat ir.middle = ir.position; ir.distance = glm::length(ir.dots[indices.first].pos - ir.dots[indices.second].pos); ir.indices = indices; + ir.m_positionVisibility = PositionVisibility::FULL; } else if (ir.dots[indices.first].visible) { ir.position = ir.middle + (ir.dots[indices.first].pos - ir.prev_dots[indices.first].pos); + ir.m_positionVisibility = PositionVisibility::PARTIAL; } else if (ir.dots[indices.second].visible) { ir.position = ir.middle + (ir.dots[indices.second].pos - ir.prev_dots[indices.second].pos); + ir.m_positionVisibility = PositionVisibility::PARTIAL; + } + else { + ir.m_positionVisibility = PositionVisibility::NONE; } } diff --git a/src/input/api/Wiimote/WiimoteControllerProvider.h b/src/input/api/Wiimote/WiimoteControllerProvider.h index 40fe878a..7629b641 100644 --- a/src/input/api/Wiimote/WiimoteControllerProvider.h +++ b/src/input/api/Wiimote/WiimoteControllerProvider.h @@ -5,6 +5,7 @@ #include "input/api/Wiimote/WiimoteMessages.h" #include "input/api/ControllerProvider.h" +#include "input/api/ControllerState.h" #include #include @@ -61,6 +62,7 @@ public: std::array dots{}, prev_dots{}; glm::vec2 position{}, m_prev_position{}; + PositionVisibility m_positionVisibility; glm::vec2 middle {}; float distance = 0; std::pair indices{ 0,1 }; diff --git a/src/input/emulated/EmulatedController.cpp b/src/input/emulated/EmulatedController.cpp index e254db34..ad9b6ac1 100644 --- a/src/input/emulated/EmulatedController.cpp +++ b/src/input/emulated/EmulatedController.cpp @@ -207,6 +207,17 @@ glm::vec2 EmulatedController::get_prev_position() const return {}; } +PositionVisibility EmulatedController::GetPositionVisibility() const +{ + std::shared_lock lock(m_mutex); + for (const auto& controller : m_controllers) + { + if (controller->has_position()) + return controller->GetPositionVisibility(); + } + return PositionVisibility::NONE; +} + void EmulatedController::add_controller(std::shared_ptr controller) { controller->connect(); diff --git a/src/input/emulated/EmulatedController.h b/src/input/emulated/EmulatedController.h index b7bd8c6d..907be07e 100644 --- a/src/input/emulated/EmulatedController.h +++ b/src/input/emulated/EmulatedController.h @@ -67,6 +67,7 @@ public: bool has_position() const; glm::vec2 get_position() const; glm::vec2 get_prev_position() const; + PositionVisibility GetPositionVisibility() const; void add_controller(std::shared_ptr controller); void remove_controller(const std::shared_ptr& controller); diff --git a/src/input/emulated/WPADController.cpp b/src/input/emulated/WPADController.cpp index 819596ab..2eae0f86 100644 --- a/src/input/emulated/WPADController.cpp +++ b/src/input/emulated/WPADController.cpp @@ -1,3 +1,4 @@ +#include #include "input/emulated/WPADController.h" #include "input/emulated/ClassicController.h" @@ -308,10 +309,13 @@ void WPADController::KPADRead(KPADStatus_t& status, const BtnRepeat& repeat) status.mpls.dir.Z.z = attitude[8]; } } - - if (has_position()) + auto visibility = GetPositionVisibility(); + if (has_position() && visibility != PositionVisibility::NONE) { - status.dpd_valid_fg = 1; + if (visibility == PositionVisibility::FULL) + status.dpd_valid_fg = 2; + else + status.dpd_valid_fg = -1; const auto position = get_position(); @@ -324,6 +328,8 @@ void WPADController::KPADRead(KPADStatus_t& status, const BtnRepeat& repeat) status.vec.y = delta.y; status.speed = glm::length(delta); } + else + status.dpd_valid_fg = 0; switch (type()) {