File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,32 @@ - (void)onControllerDisconnected:(NSNotification*)connectedNotification
140
140
observerConnection: ^(GCController* gcController) {
141
141
auto controller = new Controller ();
142
142
controller->_impl ->_gcController = gcController;
143
- controller->_deviceName = [gcController.vendorName UTF8String ];
143
+
144
+ // get the player index
145
+ GCControllerPlayerIndex playerIndex = gcController.playerIndex ;
146
+ if (playerIndex == GCControllerPlayerIndexUnset) {
147
+ // apple support up to 4 players
148
+ // ref: https://developer.apple.com/documentation/gamecontroller/gccontrollerplayerindex
149
+ for (int i = 0 ; i < 4 ; ++i) {
150
+ bool indexInUse = false ;
151
+
152
+ for (GCController *existingController in [GCController controllers ]) {
153
+ if (existingController.playerIndex == i) {
154
+ indexInUse = true ;
155
+ break ;
156
+ }
157
+ }
158
+
159
+ if (!indexInUse) {
160
+ gcController.playerIndex = static_cast <GCControllerPlayerIndex>(i);
161
+ playerIndex = static_cast <GCControllerPlayerIndex>(i);
162
+ break ;
163
+ }
164
+ }
165
+ }
166
+
167
+ controller->_deviceId = static_cast <int >(playerIndex);
168
+ controller->_deviceName = [gcController.vendorName UTF8String ];
144
169
145
170
s_allController.push_back (controller);
146
171
You can’t perform that action at this time.
0 commit comments