-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRetroInputBackend.h
More file actions
142 lines (122 loc) · 3.72 KB
/
Copy pathQRetroInputBackend.h
File metadata and controls
142 lines (122 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef QRETRO_INPUT_BACKEND_H
#define QRETRO_INPUT_BACKEND_H
#include <QObject>
#include <QString>
#include <QVector>
#include <libretro.h>
/// Sentinel value meaning "no physical device assigned to this port".
static constexpr unsigned QRETRO_NO_DEVICE = ~0u;
/// Sentinel value meaning "the keyboard is assigned to this port", used in
/// place of a physical device ID in gamepad-assignment combo boxes.
static constexpr unsigned QRETRO_KEYBOARD_DEVICE = ~0u - 1;
/// Name and opaque backend ID for a single connected gamepad.
struct QRetroGamepadInfo
{
unsigned deviceId;
QString name;
};
class QRetroInputJoypad;
class QRetroInputBackend : public QObject
{
Q_OBJECT
public:
explicit QRetroInputBackend(QObject *parent = nullptr)
: QObject(parent)
{
}
virtual ~QRetroInputBackend() = default;
/**
* Called once after construction. The backend receives a pointer to the
* shared joypad array and its capacity. The backend does NOT own the array.
*/
virtual void init(QRetroInputJoypad *joypads, unsigned maxUsers) = 0;
/**
* Called by QRetroInput::poll() before keyboard-macro processing.
* Signal-driven backends (e.g. QGamepad) may leave this as a no-op.
*/
virtual void poll() = 0;
/**
* Sets the rumble motor strength for a given port.
* effect is RETRO_RUMBLE_STRONG (low-frequency) or RETRO_RUMBLE_WEAK
* (high-frequency). strength ranges from 0 (off) to 0xFFFF (full).
* Returns true if rumble was applied, false if unsupported.
*/
virtual bool setRumble(unsigned port, retro_rumble_effect effect, uint16_t strength)
{
Q_UNUSED(port)
Q_UNUSED(effect)
Q_UNUSED(strength)
return false;
}
/**
* Enables or disables a sensor (accelerometer, gyroscope, illuminance).
* Returns true if the sensor was handled, false if unsupported.
*/
virtual bool setSensorState(unsigned port, retro_sensor_action action, unsigned rate)
{
Q_UNUSED(port)
Q_UNUSED(action)
Q_UNUSED(rate)
return false;
}
/**
* Returns the current value of a sensor axis for a given port.
* id is one of the RETRO_SENSOR_* constants.
*/
virtual float getSensorInput(unsigned port, unsigned id)
{
Q_UNUSED(port)
Q_UNUSED(id)
return 0.0f;
}
/**
* Returns true if the backend currently has a live sensor feed for the
* given port and axis id. Unlike cached flags, this reflects real-time
* state — e.g. returns false if the gamepad is not connected, even if
* the core previously called setSensorState(ENABLE).
*/
virtual bool sensorActive(unsigned port, unsigned id)
{
Q_UNUSED(port)
Q_UNUSED(id)
return false;
}
/**
* Returns a human-readable name for the physical device assigned to
* the given port, or an empty string if no device is connected.
*/
virtual QString deviceName(unsigned port) const
{
Q_UNUSED(port)
return QString();
}
/**
* Returns a list of every gamepad the backend currently sees as connected,
* whether or not it is assigned to a port.
*/
virtual QVector<QRetroGamepadInfo> connectedGamepads() const { return {}; }
/**
* Assigns the physical device identified by deviceId to the given port.
* Pass QRETRO_NO_DEVICE to disconnect any device from that port.
* Returns true on success.
*/
virtual bool assignGamepad(unsigned port, unsigned deviceId)
{
Q_UNUSED(port)
Q_UNUSED(deviceId)
return false;
}
/**
* Returns the device ID currently assigned to the given port, or
* QRETRO_NO_DEVICE if the port has no physical device.
*/
virtual unsigned assignedDeviceId(unsigned port) const
{
Q_UNUSED(port)
return QRETRO_NO_DEVICE;
}
signals:
void gamepadConnected(unsigned port);
void gamepadDisconnected(unsigned port);
};
#endif