Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Source/Core/DolphinLibretro/Common/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,20 @@ static struct retro_core_option_v2_definition option_defs[] = {
},
"disabled"
},
{
Libretro::Options::wiimote::IR_PASSTHROUGH,
"Wiimote IR > Wiimote IR Passthrough",
"Wiimote IR Passthrough",
"Take the Wiimote camera's view of the sensor bar straight from the frontend, instead of deriving it from a cursor position. The frontend supplies up to four IR objects on pointer indices 1-4; Wiimote IR Mode, Total Yaw, Total Pitch and Vertical Offset are all bypassed. For frontends that know the real geometry (a VR room, a tracked light gun) this is exact, and it carries roll and distance, which a cursor cannot. Leave off for a mouse or a gamepad.",
nullptr,
CATEGORY_WIIMOTE,
{
{ "disabled", nullptr },
{ "enabled", nullptr },
{ nullptr, nullptr }
},
"disabled"
},

#if defined(HAS_OPENGL) && defined(__WEBOS__)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinLibretro/Common/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace wiimote {
constexpr const char IR_MODIFIER[] = "dolphin_ir_modifier";
constexpr const char SWING_MODIFIER[] = "dolphin_swing_modifier";
constexpr const char SWING_ANGLE[] = "dolphin_swing_angle";
constexpr const char IR_PASSTHROUGH[] = "dolphin_ir_passthrough";
} // namespace wiimote

// ======================================================
Expand Down
55 changes: 50 additions & 5 deletions Source/Core/DolphinLibretro/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControlGroup/IRPassthrough.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCAdapter.h"
Expand Down Expand Up @@ -407,11 +408,22 @@ Device::Device(unsigned device, unsigned p) : m_device(device), m_port(p)
AddButton(RETRO_DEVICE_ID_MOUSE_BUTTON_5, "Button5");
return;
case RETRO_DEVICE_POINTER:
AddButton(RETRO_DEVICE_ID_POINTER_PRESSED, "Pressed0", 0);
AddAxis(RETRO_DEVICE_ID_POINTER_X, -0x8000, "X0-", 0);
AddAxis(RETRO_DEVICE_ID_POINTER_X, 0x7FFF, "X0+", 0);
AddAxis(RETRO_DEVICE_ID_POINTER_Y, -0x8000, "Y0-", 0);
AddAxis(RETRO_DEVICE_ID_POINTER_Y, 0x7FFF, "Y0+", 0);
// Four touch indices, one per IR object. Index 0 keeps its old names.
{
static const char* const kPressed[] = { "Pressed0", "Pressed1", "Pressed2", "Pressed3" };
static const char* const kXNeg[] = { "X0-", "X1-", "X2-", "X3-" };
static const char* const kXPos[] = { "X0+", "X1+", "X2+", "X3+" };
static const char* const kYNeg[] = { "Y0-", "Y1-", "Y2-", "Y3-" };
static const char* const kYPos[] = { "Y0+", "Y1+", "Y2+", "Y3+" };
for (unsigned i = 0; i < 4; ++i)
{
AddButton(RETRO_DEVICE_ID_POINTER_PRESSED, kPressed[i], i);
AddAxis(RETRO_DEVICE_ID_POINTER_X, -0x8000, kXNeg[i], i);
AddAxis(RETRO_DEVICE_ID_POINTER_X, 0x7FFF, kXPos[i], i);
AddAxis(RETRO_DEVICE_ID_POINTER_Y, -0x8000, kYNeg[i], i);
AddAxis(RETRO_DEVICE_ID_POINTER_Y, 0x7FFF, kYPos[i], i);
}
}
return;
case RETRO_DEVICE_KEYBOARD:
return;
Expand Down Expand Up @@ -946,6 +958,37 @@ void UpdateWiimoteMappings(const WiimoteUpdateFlags& f, unsigned port, unsigned
}
}

// Raw IR: the frontend supplies the camera's view directly, bypassing the
// Point group and Total Yaw/Pitch. Objects arrive on pointer indices 0-3,
// X/Y over the camera's 0..1 field, PRESSED marking the object visible.
// Size is a constant; games only read it to reject noise.
if (f.irPassthrough)
{
auto* wmIRPass = static_cast<ControllerEmu::IRPassthrough*>(
wm->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::IRPassthrough));
const bool passthrough =
Libretro::Options::GetCached<bool>(Libretro::Options::wiimote::IR_PASSTHROUGH);

if (wmIRPass)
{
const std::string devPointer =
Libretro::Input::GetQualifiedName(port, RETRO_DEVICE_POINTER);
wmIRPass->enabled.SetValue(passthrough);
static const char* const kObj[] = { "0", "1", "2", "3" };
for (int i = 0; i < 4; ++i)
{
// Cleared when off; AreInputsBound() is half of what selects this path.
const std::string idx = kObj[i];
wmIRPass->SetControlExpression(i * 3 + 0,
passthrough ? "`" + devPointer + ":X" + idx + "+`" : "");
wmIRPass->SetControlExpression(i * 3 + 1,
passthrough ? "`" + devPointer + ":Y" + idx + "+`" : "");
wmIRPass->SetControlExpression(i * 3 + 2,
passthrough ? "`" + devPointer + ":Pressed" + idx + "` * 0.2" : "");
}
}
}

if (f.swingAngle)
{
ControllerEmu::ControlGroup* wmSwing = wm->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Swing);
Expand Down Expand Up @@ -1516,6 +1559,8 @@ void retro_set_controller_port_device_wii(unsigned port, unsigned device)
f.irModifier = true;
f.swingModifier = true;
f.sideways = true;
// Raised at setup so the option applies on a cold boot.
f.irPassthrough = true;
Libretro::Input::UpdateWiimoteMappings(f, port, device);

wmShake->SetControlExpression(0, bindMouse("L2", devMouse + ":Middle")); // Wiimote shake X
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DolphinLibretro/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ struct WiimoteUpdateFlags
bool sideways = false;
bool rumble = false;
bool gcMicBtn = false;
bool irPassthrough = false;

bool any() const {
return irMode || irOffset || irYaw || irPitch ||
irDeadzone || irModifier || swingModifier ||
swingAngle || sideways || rumble || gcMicBtn;
swingAngle || sideways || rumble || gcMicBtn || irPassthrough;
}
};

Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinLibretro/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ void retro_run(void)
flags.swingModifier = Libretro::Options::IsUpdated(Libretro::Options::wiimote::SWING_MODIFIER);
flags.swingAngle = Libretro::Options::IsUpdated(Libretro::Options::wiimote::SWING_ANGLE);
flags.sideways = Libretro::Options::IsUpdated(Libretro::Options::wiimote::HOTKEY_SIDEWAYS_TOGGLE);
flags.irPassthrough = Libretro::Options::IsUpdated(Libretro::Options::wiimote::IR_PASSTHROUGH);
}

flags.rumble = Libretro::Options::IsUpdated(Libretro::Options::sysconf::ENABLE_RUMBLE);
Expand Down