mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-29 14:53:18 +00:00
core: Library cleanup (#1631)
* core: Split error codes into separate files * Reduces build times and is cleaner * core: Bring structs and enums to codebase style * core: More style changes
This commit is contained in:
parent
3d0aacd43d
commit
5b6e0ab238
114 changed files with 2158 additions and 2509 deletions
|
@ -1,13 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "core/libraries/kernel/time.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include "input/controller.h"
|
||||
|
||||
namespace Input {
|
||||
|
||||
|
@ -59,9 +56,7 @@ State GameController::GetLastState() const {
|
|||
if (m_states_num == 0) {
|
||||
return m_last_state;
|
||||
}
|
||||
|
||||
auto last = (m_first_state + m_states_num - 1) % MAX_STATES;
|
||||
|
||||
const u32 last = (m_first_state + m_states_num - 1) % MAX_STATES;
|
||||
return m_states[last];
|
||||
}
|
||||
|
||||
|
@ -71,19 +66,19 @@ void GameController::AddState(const State& state) {
|
|||
m_first_state = (m_first_state + 1) % MAX_STATES;
|
||||
}
|
||||
|
||||
auto index = (m_first_state + m_states_num) % MAX_STATES;
|
||||
|
||||
const u32 index = (m_first_state + m_states_num) % MAX_STATES;
|
||||
m_states[index] = state;
|
||||
m_last_state = state;
|
||||
m_private[index].obtained = false;
|
||||
m_states_num++;
|
||||
}
|
||||
|
||||
void GameController::CheckButton(int id, u32 button, bool isPressed) {
|
||||
void GameController::CheckButton(int id, Libraries::Pad::OrbisPadButtonDataOffset button,
|
||||
bool is_pressed) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto state = GetLastState();
|
||||
state.time = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
if (isPressed) {
|
||||
if (is_pressed) {
|
||||
state.buttonsState |= button;
|
||||
} else {
|
||||
state.buttonsState &= ~button;
|
||||
|
@ -93,28 +88,28 @@ void GameController::CheckButton(int id, u32 button, bool isPressed) {
|
|||
}
|
||||
|
||||
void GameController::Axis(int id, Input::Axis axis, int value) {
|
||||
using Libraries::Pad::OrbisPadButtonDataOffset;
|
||||
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto state = GetLastState();
|
||||
|
||||
state.time = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
|
||||
int axis_id = static_cast<int>(axis);
|
||||
|
||||
state.axes[axis_id] = value;
|
||||
|
||||
if (axis == Input::Axis::TriggerLeft) {
|
||||
if (value > 0) {
|
||||
state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2;
|
||||
state.buttonsState |= OrbisPadButtonDataOffset::L2;
|
||||
} else {
|
||||
state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2;
|
||||
state.buttonsState &= ~OrbisPadButtonDataOffset::L2;
|
||||
}
|
||||
}
|
||||
|
||||
if (axis == Input::Axis::TriggerRight) {
|
||||
if (value > 0) {
|
||||
state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2;
|
||||
state.buttonsState |= OrbisPadButtonDataOffset::R2;
|
||||
} else {
|
||||
state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2;
|
||||
state.buttonsState &= ~OrbisPadButtonDataOffset::R2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <mutex>
|
||||
#include "common/types.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
|
||||
struct SDL_Gamepad;
|
||||
|
||||
|
@ -28,7 +29,7 @@ struct TouchpadEntry {
|
|||
};
|
||||
|
||||
struct State {
|
||||
u32 buttonsState = 0;
|
||||
Libraries::Pad::OrbisPadButtonDataOffset buttonsState{};
|
||||
u64 time = 0;
|
||||
int axes[static_cast<int>(Axis::AxisMax)] = {128, 128, 128, 128, 0, 0};
|
||||
TouchpadEntry touchpad[2] = {{false, 0, 0}, {false, 0, 0}};
|
||||
|
@ -49,7 +50,7 @@ public:
|
|||
void ReadState(State* state, bool* isConnected, int* connectedCount);
|
||||
int ReadStates(State* states, int states_num, bool* isConnected, int* connectedCount);
|
||||
State GetLastState() const;
|
||||
void CheckButton(int id, u32 button, bool isPressed);
|
||||
void CheckButton(int id, Libraries::Pad::OrbisPadButtonDataOffset button, bool isPressed);
|
||||
void AddState(const State& state);
|
||||
void Axis(int id, Input::Axis axis, int value);
|
||||
void SetLightBarRGB(u8 r, u8 g, u8 b);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue