Skip to content
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

Emscripten gamepad event draft #7243

Conversation

Jonathhhan
Copy link
Contributor

@Jonathhhan Jonathhhan commented Dec 11, 2022

This is a (well) working draft for using gamepads with Emscripten (tested with an xbox one controller).
https://emscripten.org/docs/api_reference/html5.h.html#gamepad
I got most of the code from this test / example: https://chromium.googlesource.com/external/github.com/emscripten-core/emscripten/+/refs/tags/1.38.39/tests/test_gamepad.c
Here is a good page for reference: https://gamepad-tester.com/

The event array:

static inline const char* emscripten_event_type_to_string(int eventType) {
  const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize", 
    "scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange", 
    "visibilitychange", "touchstart", "touchend", "touchmove", "touchcancel", "gamepadconnected", "gamepaddisconnected", "beforeunload", 
    "batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "(invalid)" };
  ++eventType;
  if (eventType < 0) eventType = 0;
  if (eventType >= sizeof(events)/sizeof(events[0])) eventType = sizeof(events)/sizeof(events[0])-1;
  return events[eventType];
}

Could be useful for other events to.
The gamepad events need to be updated every draw cycle (or as often as you want to get the output).
Not sure, if I put the things at the right place, but I think its a good start.
Where it hangs again is, that I do not now how to pass those values in the best way to ofApp.cpp.
Once I made a simple class, there I used notify: https://github.com/Jonathhhan/OF-GUI-library
And then I have a general question about formatting the code correct (in OF style), sometimes not sure where to leave a space and where not etc....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant