@kmamal/sdl 1.0.0-4 → 1.0.0-8

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 (84) hide show
  1. package/CHANGELOG.md +12 -6
  2. package/binding.gyp +3 -0
  3. package/package.json +6 -13
  4. package/scripts/util/common.js +2 -2
  5. package/src/javascript/audio/audio-playback-stream.js +9 -10
  6. package/src/javascript/audio/audio-recording-stream.js +9 -8
  7. package/src/javascript/audio/audio-stream.js +100 -44
  8. package/src/javascript/audio/conversion.js +41 -0
  9. package/src/javascript/audio/devices.js +11 -0
  10. package/src/javascript/audio/events.js +65 -0
  11. package/src/javascript/audio/format-helpers.js +8 -4
  12. package/src/javascript/audio/index.js +25 -20
  13. package/src/javascript/audio/prevent-exit.js +12 -9
  14. package/src/javascript/audio/validate.js +9 -0
  15. package/src/javascript/cleanup.js +9 -6
  16. package/src/javascript/clipboard/index.js +8 -3
  17. package/src/javascript/device-instance.js +61 -0
  18. package/src/javascript/events/events-via-poll.js +33 -27
  19. package/src/javascript/events/index.js +76 -482
  20. package/src/javascript/events/try.js +22 -0
  21. package/src/javascript/gamepad/{device.js → devices.js} +4 -5
  22. package/src/javascript/gamepad/events.js +66 -0
  23. package/src/javascript/gamepad/gamepad-instance.js +12 -160
  24. package/src/javascript/gamepad/index.js +15 -16
  25. package/src/javascript/globals.js +10 -1
  26. package/src/javascript/index.js +2 -5
  27. package/src/javascript/joystick/devices.js +43 -0
  28. package/src/javascript/joystick/events.js +129 -0
  29. package/src/javascript/joystick/index.js +9 -18
  30. package/src/javascript/joystick/joystick-device-instance.js +175 -0
  31. package/src/javascript/joystick/joystick-instance.js +12 -158
  32. package/src/javascript/keyboard/index.js +20 -10
  33. package/src/javascript/keyboard/key-mapping.js +46 -27
  34. package/src/javascript/mouse/index.js +36 -29
  35. package/src/javascript/sensor/events.js +21 -0
  36. package/src/javascript/sensor/index.js +13 -2
  37. package/src/javascript/sensor/sensor-instance.js +7 -47
  38. package/src/javascript/subsystems.js +56 -0
  39. package/src/javascript/touch/index.js +9 -4
  40. package/src/javascript/validate.js +114 -0
  41. package/src/javascript/video/conversion.js +63 -0
  42. package/src/javascript/video/events.js +179 -0
  43. package/src/javascript/video/format-helpers.js +10 -8
  44. package/src/javascript/video/index.js +28 -14
  45. package/src/javascript/video/validate.js +45 -0
  46. package/src/javascript/video/window.js +144 -161
  47. package/src/native/audio.cpp +457 -151
  48. package/src/native/audio.h +12 -6
  49. package/src/native/clipboard.cpp +8 -37
  50. package/src/native/enums.cpp +2 -0
  51. package/src/native/events.cpp +416 -354
  52. package/src/native/events.h +67 -65
  53. package/src/native/gamepad.cpp +86 -103
  54. package/src/native/gamepad.h +7 -8
  55. package/src/native/global.cpp +190 -85
  56. package/src/native/global.h +48 -2
  57. package/src/native/joystick.cpp +180 -274
  58. package/src/native/joystick.h +12 -6
  59. package/src/native/keyboard.cpp +60 -22
  60. package/src/native/keyboard.h +2 -1
  61. package/src/native/module.cpp +20 -3
  62. package/src/native/mouse.cpp +27 -58
  63. package/src/native/packed.cpp +106 -0
  64. package/src/native/packed.h +91 -0
  65. package/src/native/power.cpp +7 -1
  66. package/src/native/power.h +2 -2
  67. package/src/native/sensor.cpp +61 -69
  68. package/src/native/sensor.h +3 -3
  69. package/src/native/testing.cpp +131 -0
  70. package/src/native/testing.h +16 -0
  71. package/src/native/threads.cpp +300 -0
  72. package/src/native/threads.h +36 -0
  73. package/src/native/touch.cpp +32 -43
  74. package/src/native/touch.h +2 -1
  75. package/src/native/video.cpp +145 -95
  76. package/src/native/video.h +6 -3
  77. package/src/native/window.cpp +155 -218
  78. package/src/native/window.h +21 -20
  79. package/src/types/index.d.ts +141 -69
  80. package/src/javascript/audio/device.js +0 -37
  81. package/src/javascript/joystick/device.js +0 -13
  82. package/src/javascript/joystick/shared.js +0 -90
  83. package/src/javascript/worker.js +0 -88
  84. package/src/types/worker.d.ts +0 -71
@@ -1,88 +0,0 @@
1
- const { isMainThread } = require('node:worker_threads')
2
- if (isMainThread) { throw new Error("@kmamal/sdl/worker can only be used in worker threads, import @kmamal/sdl in the main thread") }
3
-
4
- const Globals = require('./globals')
5
-
6
- Globals.events = {
7
- poll () {},
8
- withoutPolling (fn) { fn() },
9
- switchToPollingFast () {},
10
- switchToPollingSlow () {},
11
- }
12
-
13
- const Enums = require('./enums')
14
- const { getFormatHelpers: getAudioFormatHelpers } = require('./audio/format-helpers')
15
- const { getFormatHelpers: getVideoFormatHelpers } = require('./video/format-helpers')
16
- const { AudioPlaybackStream } = require('./audio/audio-playback-stream')
17
- const { AudioRecordingStream } = require('./audio/audio-recording-stream')
18
- const { makeDefault: makeDefaultDevice } = require('./audio/device')
19
-
20
- const makeModule = (type, Stream) => {
21
- const defaultDevice = makeDefaultDevice()
22
-
23
- return {
24
- openDevice (device = null, options = {}) {
25
- if (device === null) { device = defaultDevice }
26
- else {
27
- if (typeof device !== 'object') { throw Object.assign(new Error("device must be an object"), { device }) }
28
- const { id } = device
29
- if (id !== null && !Number.isInteger(id)) { throw Object.assign(new Error("device.id must be an integer or null"), { id }) }
30
- if (id !== null && (id < 0 || id > 2 ** 32 - 1)) { throw Object.assign(new Error("device.id must be an unsigned 32-bit integer"), { id }) }
31
- }
32
-
33
- return new Stream(device, options)
34
- },
35
- }
36
- }
37
-
38
- module.exports = {
39
- video: {
40
- bytesPerPixel (format) { return getVideoFormatHelpers(format).bytesPerPixel },
41
- isYuv (format) { return getVideoFormatHelpers(format).isYuv },
42
- isPlanarYuv (format) { return getVideoFormatHelpers(format).isPlanarYuv },
43
-
44
- minStride (format, width) {
45
- const helpers = getVideoFormatHelpers(format)
46
- if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
47
- if (width < 0) { throw Object.assign(new Error("width must be non-negative"), { width }) }
48
- return helpers.minStride(width)
49
- },
50
-
51
- minBufferSize (format, stride, height) {
52
- const helpers = getVideoFormatHelpers(format)
53
- if (!Number.isInteger(stride)) { throw Object.assign(new Error("stride must be an integer"), { stride }) }
54
- if (stride < 0) { throw Object.assign(new Error("stride must be non-negative"), { stride }) }
55
- if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
56
- if (height < 0) { throw Object.assign(new Error("height must be non-negative"), { height }) }
57
- return helpers.minBufferSize(stride, height)
58
- },
59
- },
60
- keyboard: {
61
- get SCANCODE () { return Enums.scancodes },
62
- },
63
- mouse: {
64
- get BUTTON () { return Enums.mouseButtons },
65
- },
66
- sensor: {
67
- STANDARD_GRAVITY: 9.80665,
68
- },
69
- audio: {
70
- bytesPerSample (format) { return getAudioFormatHelpers(format).bytesPerSample },
71
- minSampleValue (format) { return getAudioFormatHelpers(format).minSampleValue },
72
- maxSampleValue (format) { return getAudioFormatHelpers(format).maxSampleValue },
73
- zeroSampleValue (format) { return getAudioFormatHelpers(format).zeroSampleValue },
74
-
75
- readSample (format, buffer, offset) {
76
- if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
77
- return getAudioFormatHelpers(format).reader.call(buffer, offset)
78
- },
79
-
80
- writeSample (format, buffer, value, offset) {
81
- if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
82
- return getAudioFormatHelpers(format).writer.call(buffer, value, offset)
83
- },
84
-
85
- playback: makeModule('playback', AudioPlaybackStream),
86
- recording: makeModule('recording', AudioRecordingStream),
87
- },
88
- }
@@ -1,71 +0,0 @@
1
- import type { Sdl } from './index'
2
-
3
- export namespace SdlWorker {
4
-
5
- export namespace Video {
6
-
7
- export type Format = Sdl.Video.Format | Sdl.Video.FormatAlias
8
-
9
- interface Module {
10
- bytesPerPixel (format: Format): number
11
- isYuv (format: Format): boolean
12
- isPlanarYuv (format: Format): boolean
13
- minStride (format: Format, width: number): number
14
- minBufferSize (format: Format, stride: number, height: number): number
15
- }
16
-
17
- }
18
-
19
- export namespace Keyboard {
20
-
21
- interface Module {
22
- readonly SCANCODE: { [name in Sdl.Keyboard.ScancodeNames]: Sdl.Keyboard.Scancode }
23
- }
24
-
25
- }
26
-
27
- export namespace Mouse {
28
-
29
- interface Module {
30
- readonly BUTTON: { [name in Sdl.Mouse.ButtonNames]: Sdl.Mouse.Button }
31
- }
32
-
33
- }
34
-
35
- export namespace Sensor {
36
-
37
- interface Module {
38
- readonly STANDARD_GRAVITY: 9.80665
39
- }
40
-
41
- }
42
-
43
- export namespace Audio {
44
-
45
- export type Format = Sdl.Audio.Format | Sdl.Audio.FormatAlias
46
-
47
- interface Module {
48
- bytesPerSample (format: Format): number
49
- minSampleValue (format: Format): number
50
- maxSampleValue (format: Format): number
51
- zeroSampleValue (format: Format): number
52
- readSample (format: Format, buffer: Buffer, offset?: number): number
53
- writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
54
-
55
- readonly playback: DeviceModule<Sdl.Audio.AudioPlaybackStream>
56
- readonly recording: DeviceModule<Sdl.Audio.AudioRecordingStream>
57
- }
58
-
59
- interface DeviceModule<Stream extends Sdl.Audio.AudioStream> {
60
- openDevice (device?: Sdl.Audio.Device | null, options?: Sdl.Audio.StreamOptions): Stream
61
- }
62
-
63
- }
64
-
65
- }
66
-
67
- export const video: SdlWorker.Video.Module
68
- export const keyboard: SdlWorker.Keyboard.Module
69
- export const mouse: SdlWorker.Mouse.Module
70
- export const sensor: SdlWorker.Sensor.Module
71
- export const audio: SdlWorker.Audio.Module