@kmamal/sdl 0.7.7 → 0.7.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.7",
2
+ "version": "0.7.8",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -27,6 +27,8 @@ class ControllerInstance extends EventsViaPoll {
27
27
 
28
28
  this._device = device
29
29
 
30
+ this._rumbleTimeout = null
31
+ this._rumbleTriggersTimeout = null
30
32
  this._closed = false
31
33
 
32
34
  Globals.controllerInstances.all.add(this)
@@ -83,10 +85,18 @@ class ControllerInstance extends EventsViaPoll {
83
85
  if (highFreqRumble < 0 || highFreqRumble > 1) { throw Object.assign(new Error("highFreqRumble must be between 0 and 1"), { highFreqRumble }) }
84
86
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
85
87
 
88
+ Globals.events.poll()
86
89
  Bindings.joystick_rumble(this._device.id, lowFreqRumble, highFreqRumble, duration)
90
+ clearTimeout(this._rumbleTimeout)
91
+ this._rumbleTimeout = setTimeout(() => { this.stopRumble() }, duration)
87
92
  }
88
93
 
89
- stopRumble () { this.rumble(0, 0) }
94
+ stopRumble () {
95
+ clearTimeout(this._rumbleTimeout)
96
+ this._rumbleTimeout = null
97
+ Bindings.joystick_rumble(this._device.id, 0, 0, 0)
98
+ Globals.events.poll()
99
+ }
90
100
 
91
101
  get hasRumbleTriggers () { return this._hasRumbleTriggers }
92
102
  rumbleTriggers (leftRumble = 1, rightRumble = 1, duration = 1e3) {
@@ -98,10 +108,18 @@ class ControllerInstance extends EventsViaPoll {
98
108
  if (rightRumble < 0 || rightRumble > 1) { throw Object.assign(new Error("rightRumble must be between 0 and 1"), { rightRumble }) }
99
109
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
100
110
 
111
+ Globals.events.poll()
101
112
  Bindings.joystick_rumbleTriggers(this._device.id, leftRumble, rightRumble, duration)
113
+ clearTimeout(this._rumbleTriggersTimeout)
114
+ this._rumbleTriggersTimeout = setTimeout(() => { this.stopRumble() }, duration)
102
115
  }
103
116
 
104
- stopRumbleTriggers () { this.rumbleTriggers(0, 0) }
117
+ stopRumbleTriggers () {
118
+ clearTimeout(this._rumbleTriggersTimeout)
119
+ this._rumbleTriggersTimeout = null
120
+ Bindings.joystick_rumbleTriggers(this._device.id, 0, 0, 0)
121
+ Globals.events.poll()
122
+ }
105
123
 
106
124
  get closed () { return this._closed }
107
125
  close () {
@@ -68,7 +68,7 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
68
68
  }
69
69
 
70
70
 
71
- const handleEvents = () => {
71
+ const poll = () => {
72
72
  let event
73
73
  while ((event = Bindings.events_poll())) {
74
74
  const { family, type } = event
@@ -368,7 +368,7 @@ const handleEvents = () => {
368
368
  let eventsInterval = null
369
369
 
370
370
  const startPolling = () => {
371
- eventsInterval = setInterval(handleEvents, 0)
371
+ eventsInterval = setInterval(poll, 0)
372
372
  }
373
373
 
374
374
  const stopPolling = () => {
@@ -379,4 +379,5 @@ const stopPolling = () => {
379
379
  Globals.events = {
380
380
  startPolling,
381
381
  stopPolling,
382
+ poll,
382
383
  }
@@ -21,5 +21,5 @@ module.exports = {
21
21
  byId: new Map(),
22
22
  },
23
23
 
24
- events: null, // Set later to { startPolling, stopPolling }
24
+ events: null, // Set later to { startPolling, stopPolling, poll }
25
25
  }
@@ -30,6 +30,8 @@ class JoystickInstance extends EventsViaPoll {
30
30
 
31
31
  this._device = device
32
32
 
33
+ this._rumbleTimeout = null
34
+ this._rumbleTriggersTimeout = null
33
35
  this._closed = false
34
36
 
35
37
  Globals.joystickInstances.all.add(this)
@@ -88,10 +90,18 @@ class JoystickInstance extends EventsViaPoll {
88
90
  if (highFreqRumble < 0 || highFreqRumble > 1) { throw Object.assign(new Error("highFreqRumble must be between 0 and 1"), { highFreqRumble }) }
89
91
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
90
92
 
93
+ Globals.events.poll()
91
94
  Bindings.joystick_rumble(this._device.id, lowFreqRumble, highFreqRumble, duration)
95
+ clearTimeout(this._rumbleTimeout)
96
+ this._rumbleTimeout = setTimeout(() => { this.stopRumble() }, duration)
92
97
  }
93
98
 
94
- stopRumble () { this.rumble(0, 0) }
99
+ stopRumble () {
100
+ clearTimeout(this._rumbleTimeout)
101
+ this._rumbleTimeout = null
102
+ Bindings.joystick_rumble(this._device.id, 0, 0, 0)
103
+ Globals.events.poll()
104
+ }
95
105
 
96
106
  get hasRumbleTriggers () { return this._hasRumbleTriggers }
97
107
  rumbleTriggers (leftRumble = 1, rightRumble = 1, duration = 1e3) {
@@ -103,10 +113,18 @@ class JoystickInstance extends EventsViaPoll {
103
113
  if (rightRumble < 0 || rightRumble > 1) { throw Object.assign(new Error("rightRumble must be between 0 and 1"), { rightRumble }) }
104
114
  if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
105
115
 
116
+ Globals.events.poll()
106
117
  Bindings.joystick_rumbleTriggers(this._device.id, leftRumble, rightRumble, duration)
118
+ clearTimeout(this._rumbleTriggersTimeout)
119
+ this._rumbleTriggersTimeout = setTimeout(() => { this.stopRumble() }, duration)
107
120
  }
108
121
 
109
- stopRumbleTriggers () { this.rumbleTriggers(0, 0) }
122
+ stopRumbleTriggers () {
123
+ clearTimeout(this._rumbleTriggersTimeout)
124
+ this._rumbleTriggersTimeout = null
125
+ Bindings.joystick_rumbleTriggers(this._device.id, 0, 0, 0)
126
+ Globals.events.poll()
127
+ }
110
128
 
111
129
  get closed () { return this._closed }
112
130
  close () {
@@ -693,7 +693,6 @@ initialize (Variant & object)
693
693
  // Hints
694
694
  {
695
695
  SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
696
- SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "0");
697
696
  }
698
697
 
699
698
  MAKE_MAP(object);