mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-20 10:24:58 +00:00
moved controller to host
This commit is contained in:
parent
08b0057754
commit
e9d2d37aae
5 changed files with 7 additions and 8 deletions
51
src/Emulator/Host/controller.cpp
Normal file
51
src/Emulator/Host/controller.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "controller.h"
|
||||
|
||||
namespace Emulator::Host::Controller {
|
||||
GameController::GameController() { m_states_num = 0;
|
||||
m_last_state = State();
|
||||
}
|
||||
void GameController::readState(State* state, bool* isConnected, int* connectedCount) {
|
||||
Lib::LockMutexGuard lock(m_mutex);
|
||||
|
||||
*isConnected = m_connected;
|
||||
*connectedCount = m_connected_count;
|
||||
*state = getLastState();
|
||||
}
|
||||
|
||||
State GameController::getLastState() const {
|
||||
if (m_states_num == 0) {
|
||||
return m_last_state;
|
||||
}
|
||||
|
||||
auto last = (m_first_state + m_states_num - 1) % MAX_STATES;
|
||||
|
||||
return m_states[last];
|
||||
}
|
||||
|
||||
void GameController::addState(const State& state) {
|
||||
if (m_states_num >= MAX_STATES) {
|
||||
m_states_num = MAX_STATES - 1;
|
||||
m_first_state = (m_first_state + 1) % MAX_STATES;
|
||||
}
|
||||
|
||||
auto index = (m_first_state + m_states_num) % MAX_STATES;
|
||||
|
||||
m_states[index] = state;
|
||||
m_last_state = state;
|
||||
|
||||
m_states_num++;
|
||||
}
|
||||
|
||||
void GameController::checKButton(int id, u32 button, bool isPressed) {
|
||||
Lib::LockMutexGuard lock(m_mutex);
|
||||
auto state = getLastState();
|
||||
if (isPressed) {
|
||||
state.buttonsState |= button;
|
||||
} else {
|
||||
state.buttonsState &= ~button;
|
||||
}
|
||||
|
||||
addState(state);
|
||||
}
|
||||
|
||||
} // namespace Emulator::Host::Controller
|
Loading…
Add table
Add a link
Reference in a new issue