mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-05 17:02:40 +00:00
More work on review comments
This commit is contained in:
parent
346c5ccf03
commit
09856df67b
@ -795,6 +795,8 @@ set(INPUT src/input/controller.cpp
|
||||
src/input/controller.h
|
||||
src/input/input_handler.cpp
|
||||
src/input/input_handler.h
|
||||
src/input/input_mouse.cpp
|
||||
src/input/input_mouse.h
|
||||
)
|
||||
|
||||
set(EMULATOR src/emulator.cpp
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "common/path_util.h"
|
||||
#include "common/version.h"
|
||||
#include "input/controller.h"
|
||||
#include "input/input_mouse.h"
|
||||
|
||||
namespace Input {
|
||||
/*
|
||||
@ -55,10 +56,7 @@ Don't be an idiot and test only the changed part expecting everything else to no
|
||||
|
||||
// Flags and values for varying purposes
|
||||
// todo: can we change these?
|
||||
int mouse_joystick_binding = 0;
|
||||
float mouse_deadzone_offset = 0.5, mouse_speed = 1, mouse_speed_offset = 0.1250;
|
||||
Uint32 mouse_polling_id = 0;
|
||||
bool mouse_enabled = false, leftjoystick_halfmode = false, rightjoystick_halfmode = false;
|
||||
bool leftjoystick_halfmode = false, rightjoystick_halfmode = false;
|
||||
|
||||
std::list<std::pair<u32, bool>> pressed_keys;
|
||||
std::list<u32> toggled_keys;
|
||||
@ -98,11 +96,6 @@ auto output_array = std::array{
|
||||
ControllerOutput(OrbisPadButtonDataOffset::None, Axis::AxisMax),
|
||||
};
|
||||
|
||||
// We had to go through 3 files of indirection just to update a flag
|
||||
void ToggleMouseEnabled() {
|
||||
mouse_enabled ^= true;
|
||||
}
|
||||
|
||||
// parsing related functions
|
||||
u32 GetAxisInputId(AxisMapping a) {
|
||||
// LOG_INFO(Input, "Parsing an axis...");
|
||||
@ -218,9 +211,9 @@ void ParseInputConfig(const std::string game_id = "") {
|
||||
// we reset these here so in case the user fucks up or doesn't include this,
|
||||
// we can fall back to default
|
||||
connections.clear();
|
||||
mouse_deadzone_offset = 0.5;
|
||||
mouse_speed = 1;
|
||||
mouse_speed_offset = 0.125;
|
||||
float mouse_deadzone_offset = 0.5;
|
||||
float mouse_speed = 1;
|
||||
float mouse_speed_offset = 0.125;
|
||||
int lineCount = 0;
|
||||
|
||||
std::ifstream file(config_file);
|
||||
@ -260,11 +253,12 @@ void ParseInputConfig(const std::string game_id = "") {
|
||||
|
||||
if (output_string == "mouse_to_joystick") {
|
||||
if (input_string == "left") {
|
||||
mouse_joystick_binding = 1;
|
||||
SetMouseToJoystick(1);
|
||||
} else if (input_string == "right") {
|
||||
mouse_joystick_binding = 2;
|
||||
SetMouseToJoystick(2);
|
||||
} else {
|
||||
mouse_joystick_binding = 0; // default to 'none' or invalid
|
||||
LOG_WARNING(Input, "Invalid argument for mouse-to-joystick binding");
|
||||
SetMouseToJoystick(0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -645,45 +639,4 @@ void ActivateOutputsFromInputs() {
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval) {
|
||||
auto* controller = (GameController*)param;
|
||||
if (!mouse_enabled)
|
||||
return interval;
|
||||
|
||||
Axis axis_x, axis_y;
|
||||
switch (mouse_joystick_binding) {
|
||||
case 1:
|
||||
axis_x = Axis::LeftX;
|
||||
axis_y = Axis::LeftY;
|
||||
break;
|
||||
case 2:
|
||||
axis_x = Axis::RightX;
|
||||
axis_y = Axis::RightY;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
return interval; // no update needed
|
||||
}
|
||||
|
||||
float d_x = 0, d_y = 0;
|
||||
SDL_GetRelativeMouseState(&d_x, &d_y);
|
||||
|
||||
float output_speed =
|
||||
SDL_clamp((sqrt(d_x * d_x + d_y * d_y) + mouse_speed_offset * 128) * mouse_speed,
|
||||
mouse_deadzone_offset * 128, 128.0);
|
||||
|
||||
float angle = atan2(d_y, d_x);
|
||||
float a_x = cos(angle) * output_speed, a_y = sin(angle) * output_speed;
|
||||
|
||||
if (d_x != 0 && d_y != 0) {
|
||||
controller->Axis(0, axis_x, GetAxis(-0x80, 0x80, a_x));
|
||||
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, a_y));
|
||||
} else {
|
||||
controller->Axis(0, axis_x, GetAxis(-0x80, 0x80, 0));
|
||||
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, 0));
|
||||
}
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
} // namespace Input
|
||||
} // namespace Input
|
||||
|
@ -188,9 +188,6 @@ const std::map<std::string, u32> string_to_keyboard_key_map = {
|
||||
{"capslock", SDLK_CAPSLOCK},
|
||||
};
|
||||
|
||||
// literally the only flag that needs external access
|
||||
void ToggleMouseEnabled();
|
||||
|
||||
void ParseInputConfig(const std::string game_id);
|
||||
|
||||
class InputBinding {
|
||||
@ -338,9 +335,4 @@ bool UpdatePressedKeys(u32 button, bool is_pressed);
|
||||
|
||||
void ActivateOutputsFromInputs();
|
||||
|
||||
void UpdateMouse(GameController* controller);
|
||||
|
||||
// Polls the mouse for changes, and simulates joystick movement from it.
|
||||
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval);
|
||||
|
||||
} // namespace Input
|
||||
} // namespace Input
|
||||
|
73
src/input/input_mouse.cpp
Normal file
73
src/input/input_mouse.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "input_mouse.h"
|
||||
|
||||
#include "common/types.h"
|
||||
#include "controller.h"
|
||||
|
||||
#include "SDL3/SDL.h"
|
||||
|
||||
namespace Input {
|
||||
|
||||
int mouse_joystick_binding = 0;
|
||||
float mouse_deadzone_offset = 0.5, mouse_speed = 1, mouse_speed_offset = 0.1250;
|
||||
Uint32 mouse_polling_id = 0;
|
||||
bool mouse_enabled = false;
|
||||
|
||||
// We had to go through 3 files of indirection just to update a flag
|
||||
void ToggleMouseEnabled() {
|
||||
mouse_enabled = !mouse_enabled;
|
||||
}
|
||||
|
||||
void SetMouseToJoystick(int joystick) {
|
||||
mouse_joystick_binding = joystick;
|
||||
}
|
||||
|
||||
void SetMouseParams(float mdo, float ms, float mso) {
|
||||
mouse_deadzone_offset = mdo;
|
||||
mouse_speed = ms;
|
||||
mouse_speed_offset = mso;
|
||||
}
|
||||
|
||||
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval) {
|
||||
auto* controller = (GameController*)param;
|
||||
if (!mouse_enabled)
|
||||
return interval;
|
||||
|
||||
Axis axis_x, axis_y;
|
||||
switch (mouse_joystick_binding) {
|
||||
case 1:
|
||||
axis_x = Axis::LeftX;
|
||||
axis_y = Axis::LeftY;
|
||||
break;
|
||||
case 2:
|
||||
axis_x = Axis::RightX;
|
||||
axis_y = Axis::RightY;
|
||||
break;
|
||||
default:
|
||||
return interval; // no update needed
|
||||
}
|
||||
|
||||
float d_x = 0, d_y = 0;
|
||||
SDL_GetRelativeMouseState(&d_x, &d_y);
|
||||
|
||||
float output_speed =
|
||||
SDL_clamp((sqrt(d_x * d_x + d_y * d_y) + mouse_speed_offset * 128) * mouse_speed,
|
||||
mouse_deadzone_offset * 128, 128.0);
|
||||
|
||||
float angle = atan2(d_y, d_x);
|
||||
float a_x = cos(angle) * output_speed, a_y = sin(angle) * output_speed;
|
||||
|
||||
if (d_x != 0 && d_y != 0) {
|
||||
controller->Axis(0, axis_x, GetAxis(-0x80, 0x80, a_x));
|
||||
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, a_y));
|
||||
} else {
|
||||
controller->Axis(0, axis_x, GetAxis(-0x80, 0x80, 0));
|
||||
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, 0));
|
||||
}
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
} // namespace Input
|
18
src/input/input_mouse.h
Normal file
18
src/input/input_mouse.h
Normal file
@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SDL3/SDL.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Input {
|
||||
|
||||
void ToggleMouseEnabled();
|
||||
void SetMouseToJoystick(int joystick);
|
||||
void SetMouseParams(float mouse_deadzone_offset, float mouse_speed, float mouse_speed_offset);
|
||||
|
||||
// Polls the mouse for changes, and simulates joystick movement from it.
|
||||
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval);
|
||||
|
||||
} // namespace Input
|
@ -16,6 +16,7 @@
|
||||
#include "imgui/renderer/imgui_core.h"
|
||||
#include "input/controller.h"
|
||||
#include "input/input_handler.h"
|
||||
#include "input/input_mouse.h"
|
||||
#include "sdl_window.h"
|
||||
#include "video_core/renderdoc.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user