@kmamal/sdl 0.6.8 → 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
@@ -38,7 +38,7 @@ npm install @kmamal/sdl
38
38
  ### "Hello, World!"
39
39
 
40
40
  ```js
41
- const sdl = require('@kmamal/sdl')
41
+ import sdl from '@kmamal/sdl'
42
42
 
43
43
  const window = sdl.video.createWindow({ title: "Hello, World!" })
44
44
  window.on('*', console.log)
@@ -63,8 +63,8 @@ window.render(width, height, width * 4, 'bgra32', buffer)
63
63
 
64
64
  ### WebGL
65
65
  ```js
66
- const sdl = require('@kmamal/sdl')
67
- const createContext = require('@kmamal/gl')
66
+ import sdl from '@kmamal/sdl'
67
+ import createContext from '@kmamal/gl'
68
68
 
69
69
  const window = sdl.video.createWindow({title: "WebGL", opengl: true })
70
70
  const { width, height, native } = window
@@ -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)
@@ -198,6 +196,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
198
196
  * [joystickInstance.buttons](#joystickinstancebuttons)
199
197
  * [joystickInstance.hats](#joystickinstancehats)
200
198
  * [joystickInstance.power](#joystickinstancepower)
199
+ * [joystickInstance.setPlayer(index)](#joystickinstancesetplayerindex)
201
200
  * [joystickInstance.hasLed](#joystickinstancehasled)
202
201
  * [joystickInstance.setLed(red, green, blue)](#joystickinstancesetledred-green-blue)
203
202
  * [joystickInstance.hasRumble](#joystickinstancehasrumble)
@@ -226,6 +225,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
226
225
  * [controllerInstance.axes](#controllerinstanceaxes)
227
226
  * [controllerInstance.buttons](#controllerinstancebuttons)
228
227
  * [controllerInstance.power](#controllerinstancepower)
228
+ * [controllerInstance.setPlayer(index)](#controllerinstancesetplayerindex)
229
229
  * [controllerInstance.hasLed](#controllerinstancehasled)
230
230
  * [controllerInstance.setLed(red, green, blue)](#controllerinstancesetledred-green-blue)
231
231
  * [controllerInstance.hasRumble](#controllerinstancehasrumble)
@@ -285,20 +285,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
285
285
 
286
286
  ## sdl
287
287
 
288
- ### Event: 'beforeQuit'
289
-
290
- * `prevent: <function (void) => void>` Call this to prevent the application from closing.
291
-
292
- Fired to indicate that the user has requested the application to close (usually by closing the last window).
293
- If you need to display any confirmation dialogs you should call `event.prevent()` and handle termination manually.
294
- If `prevent` is not called, then this event will be followed by a [`'quit'`](#event-quit) event.
295
-
296
- ### Event: 'quit'
297
-
298
- Indicates that the application is about to close.
299
- Handle any cleanup here.
300
- This event will be followed by a call to `process.exit()`.
301
-
302
288
  ### sdl.info
303
289
 
304
290
  * `<object>`
@@ -582,7 +568,6 @@ If `prevent` is not called, then this event will be followed by a [`'close'`](#e
582
568
 
583
569
  Indicates that the window is about to be destroyed.
584
570
  Handle any cleanup here.
585
- This event will be followed by a call to [`window.destroy()`](#windowdestroy).
586
571
 
587
572
  ### Event: 'keyDown'
588
573
 
@@ -1512,6 +1497,12 @@ An array of values, each corresponding to the position of one of the joystick's
1512
1497
 
1513
1498
  The current power level of the joystick device.
1514
1499
 
1500
+ ### joystickInstance.setPlayer(index)
1501
+
1502
+ * `index: <number>` The player index to assign to the joystick.
1503
+
1504
+ Sets the player index of this joystick.
1505
+
1515
1506
  ### joystickInstance.hasLed
1516
1507
 
1517
1508
  * `<boolean>`
@@ -1726,17 +1717,42 @@ The controller's serial number, or `null` if it's not available.
1726
1717
 
1727
1718
  ### controllerInstance.axes
1728
1719
 
1729
- * `<number>[]`
1730
-
1731
- An array of values, each corresponding to the position of one of the controller's axes.
1720
+ * `<object>`
1721
+ * `leftStickX: <number>` Left stick horizontal position
1722
+ * `leftStickY: <number>` Left stick vertical position
1723
+ * `rightStickX: <number>` Right stick horizontal position
1724
+ * `rightStickY: <number>` Right stick vertical position
1725
+ * `leftTrigger: <number>` Left trigger position
1726
+ * `rightTrigger: <number>` Right trigger position
1727
+
1728
+ An object mapping each axis of the controller's axes to its position.
1732
1729
  The values are normalized from `-1` to `+1`.
1733
1730
  It may be necessary to impose certain tolerances on these values to account for jitter.
1734
1731
 
1735
1732
  ### controllerInstance.buttons
1736
1733
 
1737
- * `<boolean>[]`
1738
-
1739
- An array of values, each corresponding to the state of one of the controller's buttons.
1734
+ * `<object>`
1735
+ * `dpadLeft: <boolean>` D-Pad left pressed
1736
+ * `dpadRight: <boolean>` D-Pad right pressed
1737
+ * `dpadUp: <boolean>` D-Pad up pressed
1738
+ * `dpadDown: <boolean>` D-Pad down pressed
1739
+ * `a: <boolean>` A button pressed
1740
+ * `b: <boolean>` B button pressed
1741
+ * `x: <boolean>` X button pressed
1742
+ * `y: <boolean>` Y button pressed
1743
+ * `guide: <boolean>` Middle button pressed
1744
+ * `back: <boolean>` Back button pressed
1745
+ * `start: <boolean>` Start button pressed
1746
+ * `leftStick: <boolean>` Left stick pressed
1747
+ * `rightStick: <boolean>` Right stick pressed
1748
+ * `leftShoulder: <boolean>` Left shoulder button pressed
1749
+ * `rightShoulder: <boolean>` Right shoulder button pressed
1750
+ * `paddle1: <boolean>` Paddle 1 pressed
1751
+ * `paddle2: <boolean>` Paddle 2 pressed
1752
+ * `paddle3: <boolean>` Paddle 3 pressed
1753
+ * `paddle4: <boolean>` Paddle 4 pressed
1754
+
1755
+ An object mapping each of the controller's buttons to a boolean value.
1740
1756
  The values will be `true` for buttons that are pressed and `false` otherwise.
1741
1757
 
1742
1758
  ### controllerInstance.power
@@ -1745,6 +1761,12 @@ The values will be `true` for buttons that are pressed and `false` otherwise.
1745
1761
 
1746
1762
  The current power level of the controller device.
1747
1763
 
1764
+ ### controllerInstance.setPlayer(index)
1765
+
1766
+ * `index: <number>` The player index to assign to the controller.
1767
+
1768
+ Sets the player index of this controller.
1769
+
1748
1770
  ### controllerInstance.hasLed
1749
1771
 
1750
1772
  * `<boolean>`
@@ -1826,7 +1848,7 @@ The samples in a frame are arranged as follows:
1826
1848
  * For 4 channels (quad) the layout is front-left, front-right, rear-left, rear-right.
1827
1849
  * For 6 channels (5.1) the layout is front-left, front-right, center, low-freq, rear-left, rear-right.
1828
1850
 
1829
- 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:
1830
1852
 
1831
1853
  ```js
1832
1854
  const TWO_PI = 2 * Math.PI
@@ -1862,6 +1884,9 @@ for (let i = 0; i < numFrames; i++) {
1862
1884
  offset = playbackInstance.writeSample(buffer, sample, offset)
1863
1885
  }
1864
1886
  }
1887
+
1888
+ playbackInstance.enqueue(buffer)
1889
+ playbackInstance.play()
1865
1890
  ```
1866
1891
 
1867
1892
  ### Sample formats
@@ -2250,6 +2275,6 @@ There are some npm scripts in `package.json` that could be of use to you:
2250
2275
 
2251
2276
  The SDL headers and libs get downloaded to `sdl/`, the build happens in `build/`, and the final binaries get collected into `dist/`.
2252
2277
 
2253
- The way I normally work is I run `npm run clean` to start fresh, then run `NODE_SDL_FROM_SOURCE=1 npm i` once to prepare everything, then as I make changes I run `npm run build` ro re-build the package.
2278
+ The way I normally work is I run `npm run clean` to start fresh, then run `NODE_SDL_FROM_SOURCE=1 npm i` once to prepare everything, then as I make changes I run `npm run build` to re-build the package.
2254
2279
 
2255
2280
  Have fun!
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.8",
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
  }
package/scripts/test.mjs CHANGED
@@ -1,9 +1,11 @@
1
1
  import Path from 'node:path'
2
2
  import { execSync } from 'node:child_process'
3
- import { fstat } from 'node:fs'
3
+ import Fs from 'node:fs'
4
+ import { fileURLToPath } from 'url'
5
+ const __dirname = Path.dirname(fileURLToPath(import.meta.url))
4
6
 
5
- process.chdir(Path.resolve(__dirname, '../tests'))
6
- const files = await fstat.readdir('.')
7
+ process.chdir(Path.join(__dirname, '../tests'))
8
+ const files = await Fs.promises.readdir('.')
7
9
  for (const name of files) {
8
10
  if (!name.endsWith('.test.js')) { continue }
9
11
  execSync(`node ${name}`, { stdio: 'inherit' })
@@ -2,7 +2,7 @@ const Fs = require('node:fs')
2
2
  const Path = require('node:path')
3
3
 
4
4
  const dir = {}
5
- dir.root = Path.resolve(__dirname, '../..')
5
+ dir.root = Path.join(__dirname, '../..')
6
6
  dir.sdl = Path.join(dir.root, 'sdl')
7
7
  dir.build = Path.join(dir.root, 'build')
8
8
  dir.dist = Path.join(dir.root, 'dist')
@@ -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,9 +1,21 @@
1
1
  const Globals = require('../globals')
2
+ const Bindings = require('../bindings')
3
+ const { make: makeAudioDevice } = require('./device')
2
4
  const { EventsViaPoll } = require('../events/events-via-poll')
3
5
  const { AudioPlaybackInstance } = require('./audio-playback-instance')
4
6
  const { AudioRecordingInstance } = require('./audio-recording-instance')
5
7
  const { AudioFormatHelpers } = require('./format-helpers')
6
8
 
9
+ Globals.audioDevices.playback = Bindings.audio_getDevices(false)
10
+ for (const audioDevice of Globals.audioDevices.playback) {
11
+ makeAudioDevice(audioDevice)
12
+ }
13
+ Globals.audioDevices.recording = Bindings.audio_getDevices(true)
14
+ for (const audioDevice of Globals.audioDevices.recording) {
15
+ makeAudioDevice(audioDevice)
16
+ }
17
+
18
+
7
19
  const validEvents = [ 'deviceAdd', 'deviceRemove' ]
8
20
 
9
21
  const audio = new class extends EventsViaPoll {
@@ -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
  }
@@ -50,6 +50,15 @@ class ControllerInstance extends EventsViaPoll {
50
50
  return Enums.powerLevelNames[power]
51
51
  }
52
52
 
53
+ setPlayer (player) {
54
+ if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
55
+
56
+ if (!Number.isFinite(player)) { throw Object.assign(new Error("player must be a number"), { player }) }
57
+ if (player < 0) { throw Object.assign(new Error("player must be non-negative"), { player }) }
58
+
59
+ Bindings.joystick_setPlayer(this._device.id, player)
60
+ }
61
+
53
62
  get hasLed () { return this._hasLed }
54
63
  setLed (red, green, blue) {
55
64
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
@@ -61,7 +70,7 @@ class ControllerInstance extends EventsViaPoll {
61
70
  if (!Number.isFinite(blue)) { throw Object.assign(new Error("blue must be a number"), { blue }) }
62
71
  if (blue < 0 || blue > 1) { throw Object.assign(new Error("blue must be between 0 and 1"), { blue }) }
63
72
 
64
- Bindings.joystick_rumble(this._device.id, red, green, blue)
73
+ Bindings.joystick_setLed(this._device.id, red, green, blue)
65
74
  }
66
75
 
67
76
  get hasRumble () { return this._hasRumble }
@@ -1,8 +1,19 @@
1
1
  const Bindings = require('../bindings')
2
2
  const Globals = require('../globals')
3
+ const {
4
+ make: makeControllerDevice,
5
+ filter: filterControllerDevice,
6
+ } = require('./device')
3
7
  const { EventsViaPoll } = require('../events/events-via-poll')
4
8
  const { ControllerInstance } = require('./controller-instance')
5
9
 
10
+ Globals.controllerDevices = Bindings.joystick_getDevices(false)
11
+ .filter(filterControllerDevice)
12
+ for (const controllerDevice of Globals.controllerDevices) {
13
+ makeControllerDevice(controllerDevice)
14
+ }
15
+
16
+
6
17
  const validEvents = [ 'deviceAdd', 'deviceRemove', 'deviceRemap' ]
7
18
 
8
19
  const controller = new class extends EventsViaPoll {
@@ -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
+ }
@@ -1,7 +1,15 @@
1
+ const Bindings = require('../bindings')
1
2
  const Globals = require('../globals')
3
+ const { make: makeJoystickDevice } = require('./device')
2
4
  const { EventsViaPoll } = require('../events/events-via-poll')
3
5
  const { JoystickInstance } = require('./joystick-instance')
4
6
 
7
+ Globals.joystickDevices = Bindings.joystick_getDevices(false)
8
+ for (const joystickDevice of Globals.joystickDevices) {
9
+ makeJoystickDevice(joystickDevice)
10
+ }
11
+
12
+
5
13
  const validEvents = [ 'deviceAdd', 'deviceRemove' ]
6
14
 
7
15
  const joystick = new class extends EventsViaPoll {
@@ -55,6 +55,15 @@ class JoystickInstance extends EventsViaPoll {
55
55
  return Enums.powerLevelNames[power]
56
56
  }
57
57
 
58
+ setPlayer (player) {
59
+ if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
60
+
61
+ if (!Number.isFinite(player)) { throw Object.assign(new Error("player must be a number"), { player }) }
62
+ if (player < 0) { throw Object.assign(new Error("player must be non-negative"), { player }) }
63
+
64
+ Bindings.joystick_setPlayer(this._device.id, player)
65
+ }
66
+
58
67
  get hasLed () { return this._hasLed }
59
68
  setLed (red, green, blue) {
60
69
  if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
@@ -66,7 +75,7 @@ class JoystickInstance extends EventsViaPoll {
66
75
  if (!Number.isFinite(blue)) { throw Object.assign(new Error("blue must be a number"), { blue }) }
67
76
  if (blue < 0 || blue > 1) { throw Object.assign(new Error("blue must be between 0 and 1"), { blue }) }
68
77
 
69
- Bindings.joystick_rumble(this._device.id, red, green, blue)
78
+ Bindings.joystick_setLed(this._device.id, red, green, blue)
70
79
  }
71
80
 
72
81
  get hasRumble () { return this._hasRumble }
@@ -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);
@@ -1715,7 +1707,7 @@ window_render (
1715
1707
  RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d, %d) error: %s\n", window_id, texture_width, texture_height, texture_stride, texture_format, SDL_GetError());
1716
1708
  }
1717
1709
 
1718
- if (SDL_BlitSurface(src_surface, NULL, dst_surface, NULL) != 0) {
1710
+ if (SDL_BlitScaled(src_surface, NULL, dst_surface, NULL) != 0) {
1719
1711
  RETURN_ERROR("SDL_BlitSurface(%d) error: %s\n", window_id, SDL_GetError());
1720
1712
  }
1721
1713
 
@@ -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 {}
@@ -758,6 +747,8 @@ export namespace Sdl {
758
747
 
759
748
  readonly power: PowerLevel
760
749
 
750
+ setPlayer (index: number): void
751
+
761
752
  readonly hasLed: boolean
762
753
  setLed (red: number, green: number, blue: number): void
763
754
 
@@ -842,6 +833,8 @@ export namespace Sdl {
842
833
 
843
834
  readonly power: Joystick.PowerLevel
844
835
 
836
+ setPlayer (index: number): void
837
+
845
838
  readonly hasLed: boolean
846
839
  setLed (red: number, green: number, blue: number): void
847
840
 
@@ -979,9 +972,6 @@ export namespace Sdl {
979
972
  }
980
973
 
981
974
  interface Module {
982
- on (event: 'beforeQuit', listener: (event: Events.App.BeforeQuit) => void): this
983
- on (event: 'quit', listener: (event: Events.App.Quit) => void): this
984
-
985
975
  readonly info: Info
986
976
  readonly video: Video.Module
987
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 }