@kmamal/sdl 1.0.0-8 → 1.0.0-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +2 -2
  3. package/binding.gyp +18 -4
  4. package/package.json +1 -1
  5. package/scripts/build.mjs +3 -1
  6. package/scripts/install.mjs +2 -0
  7. package/scripts/util/common.js +1 -0
  8. package/src/javascript/audio/audio-stream.js +4 -3
  9. package/src/javascript/audio/prevent-exit.js +1 -1
  10. package/src/javascript/events/events-via-poll.js +2 -4
  11. package/src/javascript/events/index.js +14 -1
  12. package/src/javascript/events/try.js +3 -0
  13. package/src/javascript/joystick/joystick-device-instance.js +1 -0
  14. package/src/javascript/validate.js +5 -0
  15. package/src/javascript/video/events.js +3 -3
  16. package/src/javascript/video/window.js +53 -7
  17. package/src/native/audio.cpp +24 -26
  18. package/src/native/audio.h +24 -24
  19. package/src/native/clipboard.h +2 -2
  20. package/src/native/enums.cpp +14 -1
  21. package/src/native/enums.h +1 -1
  22. package/src/native/events.cpp +1 -69
  23. package/src/native/events.h +69 -69
  24. package/src/native/gamepad.cpp +65 -4
  25. package/src/native/gamepad.h +8 -8
  26. package/src/native/global.cpp +11 -273
  27. package/src/native/global.h +9 -9
  28. package/src/native/joystick.cpp +26 -3
  29. package/src/native/joystick.h +13 -13
  30. package/src/native/keyboard.cpp +6 -6
  31. package/src/native/keyboard.h +3 -3
  32. package/src/native/module.cpp +3 -0
  33. package/src/native/mouse.cpp +1 -1
  34. package/src/native/mouse.h +9 -9
  35. package/src/native/packed.cpp +5 -12
  36. package/src/native/packed.h +8 -13
  37. package/src/native/power.cpp +7 -1
  38. package/src/native/power.h +2 -2
  39. package/src/native/sensor.cpp +19 -2
  40. package/src/native/sensor.h +6 -6
  41. package/src/native/testing.cpp +17 -0
  42. package/src/native/testing.h +6 -5
  43. package/src/native/threads.cpp +1 -0
  44. package/src/native/threads.h +13 -13
  45. package/src/native/touch.cpp +7 -2
  46. package/src/native/touch.h +2 -2
  47. package/src/native/video.cpp +68 -5
  48. package/src/native/video.h +5 -5
  49. package/src/native/window.cpp +46 -1
  50. package/src/native/window.h +24 -21
  51. package/src/types/index.d.ts +16 -1
@@ -15,74 +15,6 @@
15
15
  #include <algorithm>
16
16
 
17
17
 
18
- packed::Str events::targets::APP;
19
- packed::Str events::targets::VIDEO;
20
- packed::Str events::targets::WINDOW;
21
- packed::Str events::targets::KEYBOARD;
22
- packed::Str events::targets::JOYSTICK;
23
- packed::Str events::targets::GAMEPAD;
24
- packed::Str events::targets::SENSOR;
25
- packed::Str events::targets::CLIPBOARD;
26
- packed::Str events::targets::JOYSTICK_DEVICE;
27
- packed::Str events::targets::GAMEPAD_DEVICE;
28
- packed::Str events::targets::AUDIO_DEVICE;
29
- packed::Str events::targets::CHANGE;
30
-
31
- packed::Str events::types::QUIT;
32
- packed::Str events::types::DISPLAY_ADD;
33
- packed::Str events::types::DISPLAY_REMOVE;
34
- packed::Str events::types::DISPLAY_ORIENT;
35
- packed::Str events::types::DISPLAY_MOVE;
36
- packed::Str events::types::DISPLAY_SCALE;
37
- packed::Str events::types::DISPLAY_MODE;
38
- packed::Str events::types::DISPLAY_USABLE;
39
- packed::Str events::types::DISPLAY_CHANGE;
40
- packed::Str events::types::SHOW;
41
- packed::Str events::types::HIDE;
42
- packed::Str events::types::EXPOSE;
43
- packed::Str events::types::MOVE;
44
- packed::Str events::types::RESIZE;
45
- packed::Str events::types::MINIMIZE;
46
- packed::Str events::types::MAXIMIZE;
47
- packed::Str events::types::RESTORE;
48
- packed::Str events::types::ENTER_FULLSCREEN;
49
- packed::Str events::types::LEAVE_FULLSCREEN;
50
- packed::Str events::types::FOCUS;
51
- packed::Str events::types::BLUR;
52
- packed::Str events::types::HOVER;
53
- packed::Str events::types::LEAVE;
54
- packed::Str events::types::KEY_DOWN;
55
- packed::Str events::types::KEY_UP;
56
- packed::Str events::types::TEXT_INPUT;
57
- packed::Str events::types::MOUSE_MOVE;
58
- packed::Str events::types::MOUSE_BUTTON_DOWN;
59
- packed::Str events::types::MOUSE_BUTTON_UP;
60
- packed::Str events::types::MOUSE_WHEEL;
61
- packed::Str events::types::DROP_BEGIN;
62
- packed::Str events::types::DROP_COMPLETE;
63
- packed::Str events::types::DROP_FILE;
64
- packed::Str events::types::DROP_TEXT;
65
- packed::Str events::types::CLOSE;
66
- packed::Str events::types::RENDER_DEVICE_LOST;
67
- packed::Str events::types::KEYMAP_CHANGE;
68
- packed::Str events::types::FINGER_DOWN;
69
- packed::Str events::types::FINGER_UP;
70
- packed::Str events::types::FINGER_MOVE;
71
- packed::Str events::types::FINGER_CANCEL;
72
- packed::Str events::types::DEVICE_ADD;
73
- packed::Str events::types::DEVICE_REMOVE;
74
- packed::Str events::types::DEVICE_FORMAT_CHANGE;
75
- packed::Str events::types::AXIS_MOTION;
76
- packed::Str events::types::BUTTON_DOWN;
77
- packed::Str events::types::BUTTON_UP;
78
- packed::Str events::types::BALL_MOTION;
79
- packed::Str events::types::HAT_MOTION;
80
- packed::Str events::types::POWER_UPDATE;
81
- packed::Str events::types::STEAM_HANDLE_UPDATE;
82
- packed::Str events::types::REMAP;
83
- packed::Str events::types::UPDATE;
84
-
85
-
86
18
  static Napi::Env *poll_env = nullptr;
87
19
  static Napi::Function *poll_callback = nullptr;
88
20
 
@@ -650,7 +582,7 @@ events::isDispatchingFromWatch (const Napi::CallbackInfo &info)
650
582
  }
651
583
 
652
584
  bool
653
- events::dispatchEventFromWatch(const SDL_Event &event)
585
+ events::dispatchEventFromWatch (const SDL_Event &event)
654
586
  {
655
587
  // Only dispatch while no JS callback is running; otherwise the event arrives through the normal poll.
656
588
  if (in_callback) { return false; }
@@ -9,81 +9,81 @@
9
9
  namespace events {
10
10
 
11
11
  namespace targets {
12
- extern packed::Str APP;
13
- extern packed::Str VIDEO;
14
- extern packed::Str WINDOW;
15
- extern packed::Str KEYBOARD;
16
- extern packed::Str JOYSTICK;
17
- extern packed::Str GAMEPAD;
18
- extern packed::Str SENSOR;
19
- extern packed::Str CLIPBOARD;
20
- extern packed::Str JOYSTICK_DEVICE;
21
- extern packed::Str GAMEPAD_DEVICE;
22
- extern packed::Str AUDIO_DEVICE;
23
- extern packed::Str CHANGE;
12
+ inline constexpr packed::Str APP { "app" };
13
+ inline constexpr packed::Str VIDEO { "video" };
14
+ inline constexpr packed::Str WINDOW { "window" };
15
+ inline constexpr packed::Str KEYBOARD { "keyboard" };
16
+ inline constexpr packed::Str JOYSTICK { "joystick" };
17
+ inline constexpr packed::Str GAMEPAD { "gamepad" };
18
+ inline constexpr packed::Str SENSOR { "sensor" };
19
+ inline constexpr packed::Str CLIPBOARD { "clipboard" };
20
+ inline constexpr packed::Str JOYSTICK_DEVICE { "joystickDevice" };
21
+ inline constexpr packed::Str GAMEPAD_DEVICE { "gamepadDevice" };
22
+ inline constexpr packed::Str AUDIO_DEVICE { "audioDevice" };
23
+ inline constexpr packed::Str CHANGE { "change" };
24
24
  };
25
25
 
26
26
  namespace types {
27
- extern packed::Str QUIT;
28
- extern packed::Str DISPLAY_ADD;
29
- extern packed::Str DISPLAY_REMOVE;
30
- extern packed::Str DISPLAY_ORIENT;
31
- extern packed::Str DISPLAY_MOVE;
32
- extern packed::Str DISPLAY_SCALE;
33
- extern packed::Str DISPLAY_MODE;
34
- extern packed::Str DISPLAY_USABLE;
35
- extern packed::Str DISPLAY_CHANGE;
36
- extern packed::Str SHOW;
37
- extern packed::Str HIDE;
38
- extern packed::Str EXPOSE;
39
- extern packed::Str MOVE;
40
- extern packed::Str RESIZE;
41
- extern packed::Str MINIMIZE;
42
- extern packed::Str MAXIMIZE;
43
- extern packed::Str RESTORE;
44
- extern packed::Str ENTER_FULLSCREEN;
45
- extern packed::Str LEAVE_FULLSCREEN;
46
- extern packed::Str FOCUS;
47
- extern packed::Str BLUR;
48
- extern packed::Str HOVER;
49
- extern packed::Str LEAVE;
50
- extern packed::Str KEY_DOWN;
51
- extern packed::Str KEY_UP;
52
- extern packed::Str TEXT_INPUT;
53
- extern packed::Str MOUSE_MOVE;
54
- extern packed::Str MOUSE_BUTTON_DOWN;
55
- extern packed::Str MOUSE_BUTTON_UP;
56
- extern packed::Str MOUSE_WHEEL;
57
- extern packed::Str DROP_BEGIN;
58
- extern packed::Str DROP_COMPLETE;
59
- extern packed::Str DROP_FILE;
60
- extern packed::Str DROP_TEXT;
61
- extern packed::Str CLOSE;
62
- extern packed::Str RENDER_DEVICE_LOST;
63
- extern packed::Str KEYMAP_CHANGE;
64
- extern packed::Str FINGER_DOWN;
65
- extern packed::Str FINGER_UP;
66
- extern packed::Str FINGER_MOVE;
67
- extern packed::Str FINGER_CANCEL;
68
- extern packed::Str DEVICE_ADD;
69
- extern packed::Str DEVICE_REMOVE;
70
- extern packed::Str DEVICE_FORMAT_CHANGE;
71
- extern packed::Str AXIS_MOTION;
72
- extern packed::Str BUTTON_DOWN;
73
- extern packed::Str BUTTON_UP;
74
- extern packed::Str BALL_MOTION;
75
- extern packed::Str HAT_MOTION;
76
- extern packed::Str POWER_UPDATE;
77
- extern packed::Str STEAM_HANDLE_UPDATE;
78
- extern packed::Str REMAP;
79
- extern packed::Str UPDATE;
27
+ inline constexpr packed::Str QUIT { "quit" };
28
+ inline constexpr packed::Str DISPLAY_ADD { "displayAdd" };
29
+ inline constexpr packed::Str DISPLAY_REMOVE { "displayRemove" };
30
+ inline constexpr packed::Str DISPLAY_ORIENT { "displayOrient" };
31
+ inline constexpr packed::Str DISPLAY_MOVE { "displayMove" };
32
+ inline constexpr packed::Str DISPLAY_SCALE { "displayScaleChange" };
33
+ inline constexpr packed::Str DISPLAY_MODE { "displayModeChange" };
34
+ inline constexpr packed::Str DISPLAY_USABLE { "displayUsableChange" };
35
+ inline constexpr packed::Str DISPLAY_CHANGE { "displayChange" };
36
+ inline constexpr packed::Str SHOW { "show" };
37
+ inline constexpr packed::Str HIDE { "hide" };
38
+ inline constexpr packed::Str EXPOSE { "expose" };
39
+ inline constexpr packed::Str MOVE { "move" };
40
+ inline constexpr packed::Str RESIZE { "resize" };
41
+ inline constexpr packed::Str MINIMIZE { "minimize" };
42
+ inline constexpr packed::Str MAXIMIZE { "maximize" };
43
+ inline constexpr packed::Str RESTORE { "restore" };
44
+ inline constexpr packed::Str ENTER_FULLSCREEN { "enterFullscreen" };
45
+ inline constexpr packed::Str LEAVE_FULLSCREEN { "leaveFullscreen" };
46
+ inline constexpr packed::Str FOCUS { "focus" };
47
+ inline constexpr packed::Str BLUR { "blur" };
48
+ inline constexpr packed::Str HOVER { "hover" };
49
+ inline constexpr packed::Str LEAVE { "leave" };
50
+ inline constexpr packed::Str KEY_DOWN { "keyDown" };
51
+ inline constexpr packed::Str KEY_UP { "keyUp" };
52
+ inline constexpr packed::Str TEXT_INPUT { "textInput" };
53
+ inline constexpr packed::Str MOUSE_MOVE { "mouseMove" };
54
+ inline constexpr packed::Str MOUSE_BUTTON_DOWN { "mouseButtonDown" };
55
+ inline constexpr packed::Str MOUSE_BUTTON_UP { "mouseButtonUp" };
56
+ inline constexpr packed::Str MOUSE_WHEEL { "mouseWheel" };
57
+ inline constexpr packed::Str DROP_BEGIN { "dropBegin" };
58
+ inline constexpr packed::Str DROP_COMPLETE { "dropComplete" };
59
+ inline constexpr packed::Str DROP_FILE { "dropFile" };
60
+ inline constexpr packed::Str DROP_TEXT { "dropText" };
61
+ inline constexpr packed::Str CLOSE { "close" };
62
+ inline constexpr packed::Str RENDER_DEVICE_LOST { "renderDeviceLost" };
63
+ inline constexpr packed::Str KEYMAP_CHANGE { "keymapChange" };
64
+ inline constexpr packed::Str FINGER_DOWN { "fingerDown" };
65
+ inline constexpr packed::Str FINGER_UP { "fingerUp" };
66
+ inline constexpr packed::Str FINGER_MOVE { "fingerMove" };
67
+ inline constexpr packed::Str FINGER_CANCEL { "fingerCancel" };
68
+ inline constexpr packed::Str DEVICE_ADD { "deviceAdd" };
69
+ inline constexpr packed::Str DEVICE_REMOVE { "deviceRemove" };
70
+ inline constexpr packed::Str DEVICE_FORMAT_CHANGE { "deviceFormatChange" };
71
+ inline constexpr packed::Str AXIS_MOTION { "axisMotion" };
72
+ inline constexpr packed::Str BUTTON_DOWN { "buttonDown" };
73
+ inline constexpr packed::Str BUTTON_UP { "buttonUp" };
74
+ inline constexpr packed::Str BALL_MOTION { "ballMotion" };
75
+ inline constexpr packed::Str HAT_MOTION { "hatMotion" };
76
+ inline constexpr packed::Str POWER_UPDATE { "powerUpdate" };
77
+ inline constexpr packed::Str STEAM_HANDLE_UPDATE { "steamHandleUpdate" };
78
+ inline constexpr packed::Str REMAP { "remap" };
79
+ inline constexpr packed::Str UPDATE { "update" };
80
80
  };
81
81
 
82
- bool dispatchEventFromWatch(const SDL_Event &event);
82
+ bool dispatchEventFromWatch (const SDL_Event &event);
83
83
 
84
- Napi::Value isDispatchingFromWatch(const Napi::CallbackInfo &info);
85
- Napi::Value poll(const Napi::CallbackInfo &info);
86
- Napi::Value broadcastChange(const Napi::CallbackInfo &info);
84
+ Napi::Value isDispatchingFromWatch (const Napi::CallbackInfo &info);
85
+ Napi::Value poll (const Napi::CallbackInfo &info);
86
+ Napi::Value broadcastChange (const Napi::CallbackInfo &info);
87
87
 
88
88
  }; // namespace events
89
89
 
@@ -7,10 +7,71 @@
7
7
  #include <string>
8
8
 
9
9
 
10
- std::map<SDL_GamepadType, packed::Str> gamepad::types;
11
- std::map<SDL_GamepadAxis, packed::Str> gamepad::axes;
12
- std::map<SDL_GamepadButton, packed::Str> gamepad::buttons;
13
- std::map<SDL_GamepadButtonLabel, packed::Str> gamepad::button_labels;
10
+ const std::map<SDL_GamepadType, packed::Str> gamepad::types {
11
+ // { SDL_GAMEPAD_TYPE_UNKNOWN, nullptr },
12
+ { SDL_GAMEPAD_TYPE_STANDARD, "standard" },
13
+ { SDL_GAMEPAD_TYPE_XBOX360, "xbox360" },
14
+ { SDL_GAMEPAD_TYPE_XBOXONE, "xboxOne" },
15
+ { SDL_GAMEPAD_TYPE_PS3, "ps3" },
16
+ { SDL_GAMEPAD_TYPE_PS4, "ps4" },
17
+ { SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO, "nintendoSwitchPro" },
18
+ { SDL_GAMEPAD_TYPE_PS5, "ps5" },
19
+ { SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT, "nintendoSwitchJoyconLeft" },
20
+ { SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT, "nintendoSwitchJoyconRight" },
21
+ { SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR, "nintendoSwitchJoyconPair" },
22
+ { SDL_GAMEPAD_TYPE_GAMECUBE, "gamecube" },
23
+ { SDL_GAMEPAD_TYPE_STEAM, "steam" },
24
+ };
25
+
26
+ const std::map<SDL_GamepadAxis, packed::Str> gamepad::axes {
27
+ { SDL_GAMEPAD_AXIS_LEFTX, "leftStickX" },
28
+ { SDL_GAMEPAD_AXIS_LEFTY, "leftStickY" },
29
+ { SDL_GAMEPAD_AXIS_RIGHTX, "rightStickX" },
30
+ { SDL_GAMEPAD_AXIS_RIGHTY, "rightStickY" },
31
+ { SDL_GAMEPAD_AXIS_LEFT_TRIGGER, "leftTrigger" },
32
+ { SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, "rightTrigger" },
33
+ };
34
+
35
+ const std::map<SDL_GamepadButton, packed::Str> gamepad::buttons {
36
+ { SDL_GAMEPAD_BUTTON_DPAD_LEFT, "dpadLeft" },
37
+ { SDL_GAMEPAD_BUTTON_DPAD_RIGHT, "dpadRight" },
38
+ { SDL_GAMEPAD_BUTTON_DPAD_UP, "dpadUp" },
39
+ { SDL_GAMEPAD_BUTTON_DPAD_DOWN, "dpadDown" },
40
+ { SDL_GAMEPAD_BUTTON_SOUTH, "south" },
41
+ { SDL_GAMEPAD_BUTTON_EAST, "east" },
42
+ { SDL_GAMEPAD_BUTTON_WEST, "west" },
43
+ { SDL_GAMEPAD_BUTTON_NORTH, "north" },
44
+ { SDL_GAMEPAD_BUTTON_GUIDE, "guide" },
45
+ { SDL_GAMEPAD_BUTTON_BACK, "back" },
46
+ { SDL_GAMEPAD_BUTTON_START, "start" },
47
+ { SDL_GAMEPAD_BUTTON_LEFT_STICK, "leftStick" },
48
+ { SDL_GAMEPAD_BUTTON_RIGHT_STICK, "rightStick" },
49
+ { SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, "leftShoulder" },
50
+ { SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, "rightShoulder" },
51
+ { SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, "rightPaddle1" },
52
+ { SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, "leftPaddle1" },
53
+ { SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, "rightPaddle2" },
54
+ { SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, "leftPaddle2" },
55
+ { SDL_GAMEPAD_BUTTON_MISC1, "misc1" },
56
+ { SDL_GAMEPAD_BUTTON_MISC2, "misc2" },
57
+ { SDL_GAMEPAD_BUTTON_MISC3, "misc3" },
58
+ { SDL_GAMEPAD_BUTTON_MISC4, "misc4" },
59
+ { SDL_GAMEPAD_BUTTON_MISC5, "misc5" },
60
+ { SDL_GAMEPAD_BUTTON_MISC6, "misc6" },
61
+ { SDL_GAMEPAD_BUTTON_TOUCHPAD, "touchpad" },
62
+ };
63
+
64
+ const std::map<SDL_GamepadButtonLabel, packed::Str> gamepad::button_labels {
65
+ // { SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN, nullptr },
66
+ { SDL_GAMEPAD_BUTTON_LABEL_A, "a" },
67
+ { SDL_GAMEPAD_BUTTON_LABEL_B, "b" },
68
+ { SDL_GAMEPAD_BUTTON_LABEL_X, "x" },
69
+ { SDL_GAMEPAD_BUTTON_LABEL_Y, "y" },
70
+ { SDL_GAMEPAD_BUTTON_LABEL_CROSS, "cross" },
71
+ { SDL_GAMEPAD_BUTTON_LABEL_CIRCLE, "circle" },
72
+ { SDL_GAMEPAD_BUTTON_LABEL_SQUARE, "square" },
73
+ { SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE, "triangle" },
74
+ };
14
75
 
15
76
 
16
77
  double
@@ -8,18 +8,18 @@
8
8
 
9
9
  namespace gamepad {
10
10
 
11
- extern std::map<SDL_GamepadType, packed::Str> types;
12
- extern std::map<SDL_GamepadAxis, packed::Str> axes;
13
- extern std::map<SDL_GamepadButton, packed::Str> buttons;
14
- extern std::map<SDL_GamepadButtonLabel, packed::Str> button_labels;
11
+ extern const std::map<SDL_GamepadType, packed::Str> types;
12
+ extern const std::map<SDL_GamepadAxis, packed::Str> axes;
13
+ extern const std::map<SDL_GamepadButton, packed::Str> buttons;
14
+ extern const std::map<SDL_GamepadButtonLabel, packed::Str> button_labels;
15
15
 
16
16
  double mapAxis (SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
17
17
  void getState (SDL_Gamepad *gamepad, packed::Value &dst);
18
- packed::Value getSteamHandle(SDL_Gamepad *gamepad);
18
+ packed::Value getSteamHandle (SDL_Gamepad *gamepad);
19
19
 
20
- Napi::Value addMappings(const Napi::CallbackInfo &info);
21
- Napi::Value open(const Napi::CallbackInfo &info);
22
- Napi::Value close(const Napi::CallbackInfo &info);
20
+ Napi::Value addMappings (const Napi::CallbackInfo &info);
21
+ Napi::Value open (const Napi::CallbackInfo &info);
22
+ Napi::Value close (const Napi::CallbackInfo &info);
23
23
 
24
24
  }; // namespace gamepad
25
25