Skip to content

Commit

Permalink
Input: Improve setting of dpd_enable_fg (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
capitalistspz authored May 6, 2024
1 parent bd13d4b commit 7d6d417
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/input/api/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "input/InputManager.h"
#include "input/motion/MotionSample.h"
#include "input/api/ControllerState.h"

namespace pugi
{
Expand Down Expand Up @@ -118,6 +119,7 @@ class ControllerBase
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() {}
Expand Down
6 changes: 6 additions & 0 deletions src/input/api/ControllerState.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#include <glm/vec2.hpp>
#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
{
Expand Down
7 changes: 7 additions & 0 deletions src/input/api/DSU/DSUController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/input/api/DSU/DSUController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DSUController : public Controller<DSUControllerProvider>
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;

Expand Down
5 changes: 5 additions & 0 deletions src/input/api/Wiimote/NativeWiimoteController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
1 change: 1 addition & 0 deletions src/input/api/Wiimote/NativeWiimoteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NativeWiimoteController : public Controller<WiimoteControllerProvider>
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; }
Expand Down
6 changes: 6 additions & 0 deletions src/input/api/Wiimote/WiimoteControllerProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/input/api/Wiimote/WiimoteControllerProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "input/api/Wiimote/WiimoteMessages.h"

#include "input/api/ControllerProvider.h"
#include "input/api/ControllerState.h"

#include <list>
#include <variant>
Expand Down Expand Up @@ -61,6 +62,7 @@ class WiimoteControllerProvider : public ControllerProviderBase
std::array<IRDot, 4> dots{}, prev_dots{};

glm::vec2 position{}, m_prev_position{};
PositionVisibility m_positionVisibility;
glm::vec2 middle {};
float distance = 0;
std::pair<sint32, sint32> indices{ 0,1 };
Expand Down
11 changes: 11 additions & 0 deletions src/input/emulated/EmulatedController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ControllerBase> controller)
{
controller->connect();
Expand Down
1 change: 1 addition & 0 deletions src/input/emulated/EmulatedController.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class EmulatedController
bool has_position() const;
glm::vec2 get_position() const;
glm::vec2 get_prev_position() const;
PositionVisibility GetPositionVisibility() const;

void add_controller(std::shared_ptr<ControllerBase> controller);
void remove_controller(const std::shared_ptr<ControllerBase>& controller);
Expand Down
12 changes: 9 additions & 3 deletions src/input/emulated/WPADController.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <api/Controller.h>
#include "input/emulated/WPADController.h"

#include "input/emulated/ClassicController.h"
Expand Down Expand Up @@ -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();

Expand All @@ -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())
{
Expand Down

0 comments on commit 7d6d417

Please sign in to comment.