RhythmGame 1.4.3
Loading...
Searching...
No Matches
GamepadManager.h
Go to the documentation of this file.
1//
2// Created by bobini on 07.12.23.
3//
4
5#ifndef GAMEPADMANAGER_H
6#define GAMEPADMANAGER_H
7#include <QObject>
8#include <QTimer>
9#include <SDL_gamecontroller.h>
10#include <memory>
11#include <unordered_map>
12
13namespace input {
15{
16 Q_GADGET
17 Q_PROPERTY(QString name MEMBER name)
18 Q_PROPERTY(QString guid MEMBER guid)
24 Q_PROPERTY(int index MEMBER index)
25
26 public:
27 QString name;
28 QString guid;
29 int index{};
30
31 auto operator<=>(const Gamepad& gamepad) const
32 {
33 return std::tie(name, guid, index) <=>
34 std::tie(gamepad.name, gamepad.guid, gamepad.index);
35 }
36
37 auto operator==(const Gamepad& gamepad) const -> bool;
38
39 friend auto operator>>(QDataStream& stream, Gamepad& gamepad)
40 -> QDataStream&;
41 friend auto operator<<(QDataStream& stream, const Gamepad& gamepad)
42 -> QDataStream&;
43};
44} // namespace input
45
46template<>
47struct std::hash<input::Gamepad>
48{
49 auto operator()(const input::Gamepad& s) const noexcept -> std::size_t;
50};
51namespace input {
52class GamepadManager : public QObject
53{
54 Q_OBJECT
55
56 std::unordered_map<
57 SDL_JoystickID,
58 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)>>
59 controllers;
60 std::unordered_map<SDL_JoystickID, Gamepad> gamepads;
61 QTimer pollTimer;
62
63 void addController(int index);
64 void pollEvents();
65
66 public:
67 explicit GamepadManager(QObject* parent = nullptr);
68 ~GamepadManager() override;
69
70 signals:
71
72 void axisMoved(Gamepad gamepad, Uint8 axis, double value, uint64_t time);
73 void buttonPressed(Gamepad gamepad, Uint8 uint8, uint64_t time);
74 void buttonReleased(Gamepad gamepad, Uint8 uint8, uint64_t time);
75 void gamepadRemoved(Gamepad gamepad);
76 void gamepadAdded(Gamepad gamepad);
77};
78
79} // namespace input
80
81#endif // GAMEPADMANAGER_H
double value
Definition BmsNotesData.cpp:35
zip_uint64_t index
Definition SongAssetStore.cpp:436
Definition GamepadManager.h:53
void gamepadRemoved(Gamepad gamepad)
~GamepadManager() override
Definition GamepadManager.cpp:20
void gamepadAdded(Gamepad gamepad)
void axisMoved(Gamepad gamepad, Uint8 axis, double value, uint64_t time)
void buttonReleased(Gamepad gamepad, Uint8 uint8, uint64_t time)
void buttonPressed(Gamepad gamepad, Uint8 uint8, uint64_t time)
Definition GamepadManager.h:15
friend auto operator<<(QDataStream &stream, const Gamepad &gamepad) -> QDataStream &
Definition GamepadManager.cpp:111
friend auto operator>>(QDataStream &stream, Gamepad &gamepad) -> QDataStream &
Definition GamepadManager.cpp:106
auto operator==(const Gamepad &gamepad) const -> bool
Definition GamepadManager.cpp:100
QString name
Definition GamepadManager.h:17
QString guid
Definition GamepadManager.h:18
auto operator<=>(const Gamepad &gamepad) const
Definition GamepadManager.h:31
int index
The index of the gamepad. It will get incremented if two gamepads with the same guid are connected to...
Definition GamepadManager.h:24
Various input-related classes and functions.
Definition BmsKeys.h:12