shadPS4/src/input/controller.h

45 lines
1 KiB
C
Raw Normal View History

2024-02-23 21:32:32 +00:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2023-10-13 06:40:59 +00:00
#pragma once
2024-02-23 21:32:32 +00:00
#include <mutex>
#include "common/types.h"
2023-10-13 06:40:59 +00:00
2024-04-13 21:41:51 +00:00
namespace Input {
2023-10-13 06:40:59 +00:00
struct State {
u32 buttonsState = 0;
2023-10-30 06:57:43 +00:00
u64 time = 0;
2023-10-13 06:40:59 +00:00
};
constexpr u32 MAX_STATES = 64;
class GameController {
public:
2023-10-13 06:40:59 +00:00
GameController();
virtual ~GameController() = default;
void readState(State* state, bool* isConnected, int* connectedCount);
int ReadStates(State* states, int states_num, bool* isConnected, int* connectedCount);
2023-10-13 06:40:59 +00:00
State getLastState() const;
void checkButton(int id, u32 button, bool isPressed);
2023-10-13 06:40:59 +00:00
void addState(const State& state);
private:
struct StateInternal {
bool obtained = false;
};
std::mutex m_mutex;
2023-10-13 06:40:59 +00:00
bool m_connected = false;
State m_last_state;
int m_connected_count = 0;
u32 m_states_num = 0;
u32 m_first_state = 0;
2024-04-13 21:41:51 +00:00
std::array<State, MAX_STATES> m_states;
std::array<StateInternal, MAX_STATES> m_private;
2023-10-13 06:40:59 +00:00
};
2024-04-13 21:41:51 +00:00
} // namespace Input