@@ -43,70 +43,46 @@ std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFrom
43
43
}
44
44
45
45
std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFromSDLInput (uint8_t portIndex) {
46
- std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithGyro;
47
46
std::shared_ptr<ControllerGyroMapping> mapping = nullptr ;
48
47
49
- // todo: gyro
50
- // for (auto [lusIndex, indexMapping] :
51
- // Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
52
- // auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
53
-
54
- // if (sdlIndexMapping == nullptr) {
55
- // // this LUS index isn't mapped to an SDL index
56
- // continue;
57
- // }
58
-
59
- // auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
60
-
61
- // if (!SDL_IsGameController(sdlIndex)) {
62
- // // this SDL device isn't a game controller
63
- // continue;
64
- // }
65
-
66
- // auto controller = SDL_GameControllerOpen(sdlIndex);
67
- // if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)) {
68
- // sdlControllersWithGyro[lusIndex] = SDL_GameControllerOpen(sdlIndex);
69
- // } else {
70
- // SDL_GameControllerClose(controller);
71
- // }
72
- // }
73
-
74
- // for (auto [lusIndex, controller] : sdlControllersWithGyro) {
75
- // for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
76
- // if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
77
- // mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
78
- // mapping->Recalibrate();
79
- // break;
80
- // }
81
- // }
82
-
83
- // if (mapping != nullptr) {
84
- // break;
85
- // }
86
-
87
- // for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
88
- // const auto axis = static_cast<SDL_GameControllerAxis>(i);
89
- // const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
90
- // int32_t axisDirection = 0;
91
- // if (axisValue < -0.7f) {
92
- // axisDirection = NEGATIVE;
93
- // } else if (axisValue > 0.7f) {
94
- // axisDirection = POSITIVE;
95
- // }
48
+ for (auto [lusIndex, controller] :
49
+ Context::GetInstance ()->GetControlDeck ()->GetConnectedPhysicalDeviceManager ()->GetConnectedSDLGamepadsForPort (
50
+ portIndex)) {
51
+ if (!SDL_GameControllerHasSensor (controller, SDL_SENSOR_GYRO)) {
52
+ continue ;
53
+ }
96
54
97
- // if (axisDirection == 0) {
98
- // continue;
99
- // }
55
+ for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
56
+ if (SDL_GameControllerGetButton (controller, static_cast <SDL_GameControllerButton>(button))) {
57
+ mapping = std::make_shared<SDLGyroMapping>(portIndex, 1 .0f , 0 .0f , 0 .0f , 0 .0f );
58
+ mapping->Recalibrate ();
59
+ break ;
60
+ }
61
+ }
100
62
101
- // mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
102
- // mapping->Recalibrate();
103
- // break;
104
- // }
105
- // }
63
+ if (mapping != nullptr ) {
64
+ break ;
65
+ }
106
66
107
- // for (auto [i, controller] : sdlControllersWithGyro) {
108
- // SDL_GameControllerClose(controller);
109
- // }
67
+ for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
68
+ const auto axis = static_cast <SDL_GameControllerAxis>(i);
69
+ const auto axisValue = SDL_GameControllerGetAxis (controller, axis) / 32767 .0f ;
70
+ int32_t axisDirection = 0 ;
71
+ if (axisValue < -0 .7f ) {
72
+ axisDirection = NEGATIVE;
73
+ } else if (axisValue > 0 .7f ) {
74
+ axisDirection = POSITIVE;
75
+ }
76
+
77
+ if (axisDirection == 0 ) {
78
+ continue ;
79
+ }
80
+
81
+ mapping = std::make_shared<SDLGyroMapping>(portIndex, 1 .0f , 0 .0f , 0 .0f , 0 .0f );
82
+ mapping->Recalibrate ();
83
+ break ;
84
+ }
85
+ }
110
86
111
87
return mapping;
112
88
}
0 commit comments