Commit ab9ca34 1 parent 5dba443 commit ab9ca34 Copy full SHA for ab9ca34
File tree 2 files changed +11
-0
lines changed
src/controller/physicaldevice
2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ ConnectedPhysicalDeviceManager::GetConnectedSDLGamepadsForPort(uint8_t portIndex
13
13
return mConnectedSDLGamepads ;
14
14
}
15
15
16
+ std::vector<std::string> ConnectedPhysicalDeviceManager::GetConnectedSDLGamepadNames () {
17
+ return mConnectedSDLGamepadNames ;
18
+ }
19
+
16
20
void ConnectedPhysicalDeviceManager::HandlePhysicalDeviceConnect (int32_t sdlDeviceIndex) {
17
21
RefreshConnectedSDLGamepads ();
18
22
}
@@ -23,6 +27,7 @@ void ConnectedPhysicalDeviceManager::HandlePhysicalDeviceDisconnect(int32_t sdlJ
23
27
24
28
void ConnectedPhysicalDeviceManager::RefreshConnectedSDLGamepads () {
25
29
mConnectedSDLGamepads .clear ();
30
+ mConnectedSDLGamepadNames .clear ();
26
31
for (int32_t i = 0 ; i < SDL_NumJoysticks (); i++) {
27
32
// skip if this SDL joystick isn't a Gamepad
28
33
if (!SDL_IsGameController (i)) {
@@ -31,8 +36,10 @@ void ConnectedPhysicalDeviceManager::RefreshConnectedSDLGamepads() {
31
36
32
37
auto gamepad = SDL_GameControllerOpen (i);
33
38
auto instanceId = SDL_JoystickInstanceID (SDL_GameControllerGetJoystick (gamepad));
39
+ auto name = SDL_GameControllerName (gamepad);
34
40
35
41
mConnectedSDLGamepads [instanceId] = gamepad;
42
+ mConnectedSDLGamepadNames .push_back (name);
36
43
}
37
44
}
38
45
} // namespace Ship
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
3
#include < unordered_map>
4
+ #include < vector>
5
+ #include < string>
4
6
#include < SDL2/SDL.h>
5
7
6
8
namespace Ship {
@@ -11,12 +13,14 @@ class ConnectedPhysicalDeviceManager {
11
13
~ConnectedPhysicalDeviceManager ();
12
14
13
15
std::unordered_map<int32_t , SDL_GameController*> GetConnectedSDLGamepadsForPort (uint8_t portIndex);
16
+ std::vector<std::string> GetConnectedSDLGamepadNames ();
14
17
15
18
void HandlePhysicalDeviceConnect (int32_t sdlDeviceIndex);
16
19
void HandlePhysicalDeviceDisconnect (int32_t sdlJoystickInstanceId);
17
20
void RefreshConnectedSDLGamepads ();
18
21
19
22
private:
20
23
std::unordered_map<int32_t , SDL_GameController*> mConnectedSDLGamepads ;
24
+ std::vector<std::string> mConnectedSDLGamepadNames ;
21
25
};
22
26
} // namespace Ship
You can’t perform that action at this time.
0 commit comments