-
Notifications
You must be signed in to change notification settings - Fork 15
gamepad: add Gamepad package #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
type Buttons struct { | ||
A, B, Y, X Button | ||
Left, Right, Up, Down Button | ||
LT, RT, LB, RB Button | ||
LeftThumb, RightThumb Button | ||
Start, Back Button | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace to map[ButtonID]float32
?
for name, button := range mappingButton { | ||
controller.Buttons.setButtonForce(button, float32(C.getButtonFrom(state, name))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds very inefficient, but it's easier to understand.
Maybe change the map to [...][2]uinptr
(the first is NSString and the second item is the offset struct-item) and provide access directly to controller.Buttons
). So, the C code will change the Go-Struct directly, so it's a single call to C, instead of multiple calls.
I'm using Xbox One Controller on Windows and iOS; Nintendo Switch Pro Controller and Xbox on macOS. I notice some issues with remapping on macOS/iOS, that I will fix soon. Since Nintendo Switch uses a "reverted scheme" pressing "A" acts like "B". I think makes more sense to map to the physical button position. Pressing "B" on Nintendo Pro Controller must be the same as "A" on Xbox, and "X" on Playstation (all those buttons have the same position in the gamepad). Another function or field to explain "what is the controller" (brand, name....) might be useful, but some APIs (Windows/XInput) doesn't support it. I can't implement for Linux because I fail to enable pass-through the USB to VM machine. The Android not work based on snapshot/state. The Android is the only one that is event-based exclusive (similar to keystrokes) and those events are sent to the View. Maybe I can manage a way to create a custom invisible View to get those inputs, but I'm not sure if that will work. |
Support gamepad for Windows, macOS, iOS and JS. Signed-off-by: Inkeliz <[email protected]>
What is the exact issue? The logs will be nice. What is the version of macOS did you have? It requires macOS 12, but it should act as "no-op" for older macOS versions. I compile to amd64 (using
It's not possible on all OSes. On iOS/macOS the user can remap in the OS settings and that settings is honored by |
I don't know how can we use it. On JS (Gamepad API) the only map supported is
https://w3c.github.io/gamepad/#gamepadmappingtype-enum Currently, it's not checked. But, maybe it must only support "standard" and any other type must be reported as "disconnected". On Windows, the XInput only supports
Again, maybe we can enforce to only support On MacOS/iOS the button mapping can be changed on user settings:
That function is currently used by Gamepad package, so the user can map their gamepad on the OS itself, and some devices are already mapped (like Nintendo Switch). Actually, that is why that package only works on macOS 12+ and iOS 15+. On Android, I don't know, it have other issues. What I want is to add some way to get the device name. That is useful to show the correct icons, for instance show "X" instead of "A". Maybe it can be changed on the in-game settings, but could also be changed by the name of the device. If the name contains "XBOX" it will be "A", if the name contains "DualShock" it will show "X" icon. However, the gamepad package will always report as "A", that is just visual change. |
@whereswaldon, similar to Share Dialog, it's preferable to drop it from Gio-x? |
@inkeliz I'm more interested in this joining |
Yes.🙂 The only point that I don't remember is the Android. I need to revisit and check what is required to implement Android. |
Related to mapping, @gedw99, this file seems to be related to SDL2/GLFW. This package (and Gio) doesn't use SDL/GLFW. I think Ebiten uses GLFW (at least in the past, I'm not sure currently). Honestly, I'm not sure how we can use that, and if that is (so) important. You can always re-map the gamepad externally to the package. Some OSes (MacOS/iOS) allows the user to customize the gamepad layout and also seems to detect it. On WASM it have only one layout: "There is currently one canonical layout, the Standard Gamepad" (https://www.w3.org/TR/gamepad/#remapping). I think exists another mapping for VR/AR controller, but that is part of XR API. |
If you are looking for some basic demo, its parked at gioui/gio-example#3. That can be broken now, due to changes in gio-x/gio. In order to remap you can use |
@inkeliz I'm very sorry for the multi-year PR. I've found it extremely difficult (as a new parent) to make time to test this since it involves lots of hardware permutations, and I honestly don't see that changing in the short term. As such, I don't think I can accept it into
Which path would you like to pursue? |
Support gamepad for Windows, macOS, iOS and JS.
Signed-off-by: Inkeliz [email protected]