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
|
|
|
|
2023-10-22 14:10:25 +00:00
|
|
|
#include <mutex>
|
2024-02-23 20:57:57 +00:00
|
|
|
#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 {
|
2024-02-23 20:57:57 +00:00
|
|
|
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 {
|
2024-02-23 20:57:57 +00:00
|
|
|
public:
|
2023-10-13 06:40:59 +00:00
|
|
|
GameController();
|
|
|
|
virtual ~GameController() = default;
|
|
|
|
|
|
|
|
void readState(State* state, bool* isConnected, int* connectedCount);
|
2024-04-05 06:27:13 +00:00
|
|
|
int ReadStates(State* states, int states_num, bool* isConnected, int* connectedCount);
|
2023-10-13 06:40:59 +00:00
|
|
|
State getLastState() const;
|
2024-04-14 14:09:51 +00:00
|
|
|
void checkButton(int id, u32 button, bool isPressed);
|
2023-10-13 06:40:59 +00:00
|
|
|
void addState(const State& state);
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
private:
|
2024-04-05 06:27:13 +00:00
|
|
|
struct StateInternal {
|
|
|
|
bool obtained = false;
|
|
|
|
};
|
|
|
|
|
2023-10-22 14:10:25 +00:00
|
|
|
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
|