@kmamal/sdl 0.6.9 → 0.7.0

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.
package/README.md CHANGED
@@ -84,8 +84,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
84
84
  ## Contents
85
85
 
86
86
  * [sdl](#sdl)
87
- * [Event: 'beforeQuit'](#event-beforequit)
88
- * [Event: 'quit'](#event-quit)
89
87
  * [sdl.info](#sdlinfo)
90
88
  * [sdl.video](#sdlvideo)
91
89
  * [Image data](#image-data)
@@ -287,20 +285,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
287
285
 
288
286
  ## sdl
289
287
 
290
- ### Event: 'beforeQuit'
291
-
292
- * `prevent: <function (void) => void>` Call this to prevent the application from closing.
293
-
294
- Fired to indicate that the user has requested the application to close (usually by closing the last window).
295
- If you need to display any confirmation dialogs you should call `event.prevent()` and handle termination manually.
296
- If `prevent` is not called, then this event will be followed by a [`'quit'`](#event-quit) event.
297
-
298
- ### Event: 'quit'
299
-
300
- Indicates that the application is about to close.
301
- Handle any cleanup here.
302
- This event will be followed by a call to `process.exit()`.
303
-
304
288
  ### sdl.info
305
289
 
306
290
  * `<object>`
@@ -584,7 +568,6 @@ If `prevent` is not called, then this event will be followed by a [`'close'`](#e
584
568
 
585
569
  Indicates that the window is about to be destroyed.
586
570
  Handle any cleanup here.
587
- This event will be followed by a call to [`window.destroy()`](#windowdestroy).
588
571
 
589
572
  ### Event: 'keyDown'
590
573
 
@@ -1734,7 +1717,7 @@ The controller's serial number, or `null` if it's not available.
1734
1717
 
1735
1718
  ### controllerInstance.axes
1736
1719
 
1737
- * `axes: <object>`
1720
+ * `<object>`
1738
1721
  * `leftStickX: <number>` Left stick horizontal position
1739
1722
  * `leftStickY: <number>` Left stick vertical position
1740
1723
  * `rightStickX: <number>` Right stick horizontal position
@@ -1748,7 +1731,7 @@ It may be necessary to impose certain tolerances on these values to account for
1748
1731
 
1749
1732
  ### controllerInstance.buttons
1750
1733
 
1751
- * `buttons: <object>`
1734
+ * `<object>`
1752
1735
  * `dpadLeft: <boolean>` D-Pad left pressed
1753
1736
  * `dpadRight: <boolean>` D-Pad right pressed
1754
1737
  * `dpadUp: <boolean>` D-Pad up pressed
@@ -1865,7 +1848,7 @@ The samples in a frame are arranged as follows:
1865
1848
  * For 4 channels (quad) the layout is front-left, front-right, rear-left, rear-right.
1866
1849
  * For 6 channels (5.1) the layout is front-left, front-right, center, low-freq, rear-left, rear-right.
1867
1850
 
1868
- So for example, to fill a buffer with 3 seconds of a 440Hz sine wave, you could do:
1851
+ So for example, to play 3 seconds of a 440Hz sine wave, you could do:
1869
1852
 
1870
1853
  ```js
1871
1854
  const TWO_PI = 2 * Math.PI
@@ -1901,6 +1884,9 @@ for (let i = 0; i < numFrames; i++) {
1901
1884
  offset = playbackInstance.writeSample(buffer, sample, offset)
1902
1885
  }
1903
1886
  }
1887
+
1888
+ playbackInstance.enqueue(buffer)
1889
+ playbackInstance.play()
1904
1890
  ```
1905
1891
 
1906
1892
  ### Sample formats
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.9",
2
+ "version": "0.7.0",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -49,14 +49,14 @@
49
49
  "install-deps-mac": "./scripts/install-deps-mac.sh"
50
50
  },
51
51
  "dependencies": {
52
- "tar": "^6.1.11"
52
+ "tar": "^6.1.13"
53
53
  },
54
54
  "sdl": {
55
55
  "owner": "kmamal",
56
56
  "repo": "build-sdl",
57
- "version": "2.24.1"
57
+ "version": "2.26.4"
58
58
  },
59
59
  "devDependencies": {
60
- "@types/node": "^18.11.10"
60
+ "@types/node": "^18.15.11"
61
61
  }
62
62
  }
@@ -108,7 +108,6 @@ class AudioInstance extends EventsViaPoll {
108
108
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._id }) }
109
109
 
110
110
  Bindings.audio_clearQueue(this._id)
111
- require('./prevent-exit').resetTimeout() // Avoid circular dependency
112
111
  }
113
112
 
114
113
  get closed () { return this._closed }
@@ -1,5 +1,6 @@
1
1
  const Bindings = require('../bindings')
2
2
  const { AudioInstance } = require('./audio-instance')
3
+ const { resetTimeout } = require('./prevent-exit')
3
4
 
4
5
  class AudioPlaybackInstance extends AudioInstance {
5
6
  enqueue (buffer, numBytes = buffer.length) {
@@ -11,6 +12,11 @@ class AudioPlaybackInstance extends AudioInstance {
11
12
 
12
13
  Bindings.audio_enqueue(this._id, buffer, numBytes)
13
14
  }
15
+
16
+ clearQueue () {
17
+ super.clearQueue()
18
+ resetTimeout()
19
+ }
14
20
  }
15
21
 
16
22
  module.exports = { AudioPlaybackInstance }
@@ -1,5 +1,4 @@
1
1
  const Globals = require('../globals')
2
- const { AudioPlaybackInstance } = require('./audio-playback-instance')
3
2
 
4
3
  let timeout
5
4
 
@@ -16,11 +15,12 @@ process.on('beforeExit', (code) => {
16
15
  let duration = 0
17
16
 
18
17
  for (const instance of Globals.audioInstances.values()) {
19
- if (!(instance instanceof AudioPlaybackInstance)) { continue }
20
- const { queued, playing, buffered } = instance
18
+ if (instance.device.type === 'recording') { continue }
19
+
20
+ const { queued, playing } = instance
21
21
  if (!queued || !playing) { continue }
22
22
 
23
- const { channels, frequency, bytesPerSample } = instance
23
+ const { channels, frequency, buffered, bytesPerSample } = instance
24
24
  const bytesPerSecond = channels * frequency * bytesPerSample
25
25
  duration = Math.max(duration, (queued + buffered) / bytesPerSecond)
26
26
  }
@@ -1,7 +1,6 @@
1
1
  const Bindings = require('../bindings')
2
2
  const Globals = require('../globals')
3
3
  const Enums = require('../enums')
4
- const { maybeTriggerQuit } = require('./quit')
5
4
  const { mapping } = require('../keyboard/key-mapping')
6
5
  const { joystick: joystickModule } = require('../joystick')
7
6
  const { controller: controllerModule } = require('../controller')
@@ -78,12 +77,6 @@ const handleEvents = () => {
78
77
  event.type = Enums.eventTypeNames[type]
79
78
 
80
79
  switch (family) {
81
- case Enums.eventFamily.app: {
82
- if (type === Enums.eventType.quit) {
83
- maybeTriggerQuit()
84
- }
85
- } break
86
-
87
80
  case Enums.eventFamily.window: {
88
81
  const { windowId } = event
89
82
  delete event.windowId
@@ -158,8 +151,6 @@ const handleEvents = () => {
158
151
  }
159
152
 
160
153
  window.emit(event.type, event)
161
-
162
- if (type === Enums.eventType.close) { window.destroy() }
163
154
  } break
164
155
 
165
156
  case Enums.eventFamily.keyboard: {
@@ -5,7 +5,6 @@ const Bindings = require('./bindings')
5
5
 
6
6
  const info = Bindings.initialize()
7
7
 
8
- const { sdl } = require('./sdl')
9
8
  const { video } = require('./video')
10
9
  const { keyboard } = require('./keyboard')
11
10
  const { mouse } = require('./mouse')
@@ -14,17 +13,16 @@ const { controller } = require('./controller')
14
13
  const { audio } = require('./audio')
15
14
  const { clipboard } = require('./clipboard')
16
15
 
17
- sdl.info = info
18
- sdl.video = video
19
- sdl.keyboard = keyboard
20
- sdl.mouse = mouse
21
- sdl.joystick = joystick
22
- sdl.controller = controller
23
- sdl.audio = audio
24
- sdl.clipboard = clipboard
25
-
26
16
  require('./events')
27
- require('./audio/prevent-exit')
28
17
  require('./cleanup')
29
18
 
30
- module.exports = sdl
19
+ module.exports = {
20
+ info,
21
+ video,
22
+ keyboard,
23
+ mouse,
24
+ joystick,
25
+ controller,
26
+ audio,
27
+ clipboard,
28
+ }
@@ -2,7 +2,6 @@ const Bindings = require('../bindings')
2
2
  const Globals = require('../globals')
3
3
  const Enums = require('../enums')
4
4
  const { EventsViaPoll } = require('../events/events-via-poll')
5
- const { maybeTriggerQuit } = require('../events/quit')
6
5
 
7
6
  const validEvents = [
8
7
  'show',
@@ -122,6 +121,14 @@ class Window extends EventsViaPoll {
122
121
 
123
122
  // This also keeps Node.js alive while windows are open
124
123
  this.on('close', () => {
124
+ if (Globals.windows.hovered === this) { Globals.windows.hovered = null }
125
+ if (Globals.windows.focused === this) { Globals.windows.focused = null }
126
+
127
+ Bindings.window_destroy(this._id)
128
+ this._destroyed = true
129
+
130
+ Globals.windows.all.delete(this._id)
131
+
125
132
  process.nextTick(() => { this.removeAllListeners() })
126
133
  })
127
134
 
@@ -130,6 +137,7 @@ class Window extends EventsViaPoll {
130
137
  this.emit('resize', {
131
138
  width: this._width,
132
139
  height: this._height,
140
+ type: 'resize',
133
141
  })
134
142
  })
135
143
  }
@@ -321,15 +329,7 @@ class Window extends EventsViaPoll {
321
329
  destroy () {
322
330
  if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
323
331
 
324
- if (Globals.windows.hovered === this) { Globals.windows.hovered = null }
325
- if (Globals.windows.focused === this) { Globals.windows.focused = null }
326
-
327
- Bindings.window_destroy(this._id)
328
- this._destroyed = true
329
-
330
- Globals.windows.all.delete(this._id)
331
-
332
- maybeTriggerQuit()
332
+ this.emit('close', { type: 'close' })
333
333
  }
334
334
  }
335
335
 
@@ -120,7 +120,6 @@ ErrorMessage::
120
120
 
121
121
 
122
122
  enum class EventFamily {
123
- APP,
124
123
  WINDOW,
125
124
  KEYBOARD,
126
125
  MOUSE,
@@ -138,7 +137,6 @@ enum_getEventFamilies (Variant & families)
138
137
  {
139
138
  MAKE_MAP(families);
140
139
 
141
- SET_NUM(families, "app", (int) EventFamily::APP);
142
140
  SET_NUM(families, "window", (int) EventFamily::WINDOW);
143
141
  SET_NUM(families, "keyboard", (int) EventFamily::KEYBOARD);
144
142
  SET_NUM(families, "mouse", (int) EventFamily::MOUSE);
@@ -911,12 +909,6 @@ packageEvent (const SDL_Event & event, Variant & object)
911
909
 
912
910
  Variant value;
913
911
  switch (event.type) {
914
- case SDL_QUIT: {
915
- SET_NUM(object, "family", (int) EventFamily::APP);
916
- SET_NUM(object, "type", (int) EventType::QUIT);
917
- break;
918
- }
919
-
920
912
  case SDL_WINDOWEVENT: {
921
913
  SET_NUM(object, "family", (int) EventFamily::WINDOW);
922
914
  SET_NUM(object, "windowId", event.window.windowID);
@@ -5,17 +5,6 @@ export namespace Events {
5
5
 
6
6
  type PreventCallback = () => void
7
7
 
8
- namespace App {
9
-
10
- interface BeforeQuit extends BaseEvent {
11
- readonly type: 'beforeQuit'
12
- readonly prevent: PreventCallback
13
- }
14
-
15
- interface Quit extends BaseEvent { readonly type: 'quit' }
16
-
17
- }
18
-
19
8
  namespace Window {
20
9
 
21
10
  interface WindowEvent extends BaseEvent {}
@@ -983,9 +972,6 @@ export namespace Sdl {
983
972
  }
984
973
 
985
974
  interface Module {
986
- on (event: 'beforeQuit', listener: (event: Events.App.BeforeQuit) => void): this
987
- on (event: 'quit', listener: (event: Events.App.Quit) => void): this
988
-
989
975
  readonly info: Info
990
976
  readonly video: Video.Module
991
977
  readonly keyboard: Keyboard.Module
@@ -1,23 +0,0 @@
1
- const Globals = require('../globals')
2
- const { sdl } = require('../sdl')
3
-
4
-
5
- const maybeTriggerQuit = () => {
6
- if (Globals.windows.all.size > 0) { return }
7
-
8
- let shouldPrevent = false
9
- const prevent = () => { shouldPrevent = true }
10
-
11
- const type1 = 'beforeQuit'
12
- const event1 = { type: type1, prevent }
13
- sdl.emit(type1, event1)
14
-
15
- if (shouldPrevent) { return }
16
-
17
- const type2 = 'quit'
18
- const event2 = { type: type2 }
19
- sdl.emit(type2, event2)
20
- process.exit()
21
- }
22
-
23
- module.exports = { maybeTriggerQuit }
@@ -1,5 +0,0 @@
1
- const { EventsViaPoll } = require('./events/events-via-poll')
2
-
3
- const sdl = new EventsViaPoll([ 'beforeQuit', 'quit' ])
4
-
5
- module.exports = { sdl }