@kmamal/sdl 0.11.8 → 0.11.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.11.8",
2
+ "version": "0.11.9",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -60,18 +60,20 @@
60
60
  "clean": "cd scripts && node clean.mjs"
61
61
  },
62
62
  "dependencies": {
63
- "node-addon-api": "^8.3.1",
64
- "node-gyp": "^11.1.0",
65
63
  "tar": "^7.4.3"
66
64
  },
67
- "sdl": {
68
- "owner": "kmamal",
69
- "repo": "build-sdl",
70
- "version": "2.32.8"
71
- },
72
65
  "devDependencies": {
73
66
  "@kmamal/evdev": "^0.0.2",
74
67
  "@kmamal/testing": "^0.0.31",
75
- "@types/node": "^22.13.5"
68
+ "@types/node": "^22.13.5",
69
+ "node-addon-api": "^8.3.1",
70
+ "node-gyp": "^11.1.0"
71
+ },
72
+ "config": {
73
+ "sdl": {
74
+ "owner": "kmamal",
75
+ "repo": "build-sdl",
76
+ "version": "2.32.8"
77
+ }
76
78
  }
77
79
  }
@@ -18,7 +18,7 @@ const { platform, arch } = process
18
18
  const targetArch = process.env.CROSS_COMPILE_ARCH || arch
19
19
  const assetName = `sdl.node-v${version}-${platform}-${targetArch}.tar.gz`
20
20
 
21
- const sdl = pkg.sdl
21
+ const sdl = pkg.config.sdl
22
22
  sdl.assetName = `SDL-v${sdl.version}-${platform}-${targetArch}.tar.gz`
23
23
 
24
24
  module.exports = {
@@ -10,7 +10,7 @@ const make = (device) => {
10
10
  return {
11
11
  ...rest,
12
12
  mapping: controllerMapping,
13
- name: controllerName,
13
+ name: controllerName ?? rest.name,
14
14
  type: controllerType,
15
15
  }
16
16
  }
@@ -2,7 +2,6 @@ const Globals = require('../globals')
2
2
  const Bindings = require('../bindings')
3
3
  const { EventsViaPoll } = require('../events/events-via-poll')
4
4
  const { ControllerInstance } = require('./controller-instance')
5
- const { reconcileJoystickAndControllerDevices } = require('../events/reconcile-joystick-and-controller-devices')
6
5
 
7
6
  const validEvents = [ 'deviceAdd', 'deviceRemove' ]
8
7
 
@@ -26,7 +25,8 @@ const controller = new class extends EventsViaPoll {
26
25
  Globals.events.poll()
27
26
 
28
27
  const devices = Bindings.joystick_getDevices()
29
- reconcileJoystickAndControllerDevices(devices)
28
+ require('../events/reconcile-joystick-and-controller-devices')
29
+ .reconcileJoystickAndControllerDevices(devices)
30
30
  }
31
31
  }()
32
32
 
@@ -1,11 +1,12 @@
1
1
  const Globals = require('../globals')
2
2
  const { reconcileDevices } = require('./reconcile')
3
3
 
4
+ const { audio: audioModule } = require('../audio')
4
5
  const { compare: compareAudioDevice } = require('../audio/device')
5
6
 
6
7
  const reconcileAudioDevices = (audioDevices, audioDeviceType) => {
7
8
  reconcileDevices(
8
- require('../audio').audio,
9
+ audioModule,
9
10
  Globals.audioDevices[audioDeviceType],
10
11
  audioDevices,
11
12
  compareAudioDevice,
@@ -1,11 +1,12 @@
1
1
  const Globals = require('../globals')
2
2
  const { reconcileDevices } = require('./reconcile')
3
3
 
4
+ const { video: videoModule } = require('../video')
4
5
  const { compare: compareDisplays } = require('../video/display')
5
6
 
6
7
  const reconcileDisplays = (displays) => {
7
8
  reconcileDevices(
8
- require('../video').video,
9
+ videoModule,
9
10
  Globals.displays,
10
11
  displays,
11
12
  compareDisplays,
@@ -1,10 +1,13 @@
1
1
  const Globals = require('../globals')
2
2
  const { reconcileDevices } = require('./reconcile')
3
3
 
4
+ const { joystick: joystickModule } = require('../joystick')
4
5
  const {
5
6
  make: makeJoystickDevice,
6
7
  compare: compareJoystickDevice,
7
8
  } = require('../joystick/device')
9
+
10
+ const { controller: controllerModule } = require('../controller')
8
11
  const {
9
12
  make: makeControllerDevice,
10
13
  compare: compareControllerDevice,
@@ -20,14 +23,14 @@ const reconcileJoystickAndControllerDevices = (devices) => {
20
23
  .map(makeControllerDevice)
21
24
 
22
25
  reconcileDevices(
23
- require('../joystick').joystick,
26
+ joystickModule,
24
27
  Globals.joystickDevices,
25
28
  joystickDevices,
26
29
  compareJoystickDevice,
27
30
  )
28
31
 
29
32
  reconcileDevices(
30
- require('../controller').controller,
33
+ controllerModule,
31
34
  Globals.controllerDevices,
32
35
  controllerDevices,
33
36
  compareControllerDevice,
@@ -135,7 +135,7 @@ controller::open (const Napi::CallbackInfo &info)
135
135
  : env.Null() ;
136
136
 
137
137
  const char *_serial_number = SDL_GameControllerGetSerial(controller);
138
- Napi::Value serial_number = _serial_number != 0
138
+ Napi::Value serial_number = _serial_number != nullptr
139
139
  ? Napi::String::New(env, _serial_number)
140
140
  : env.Null();
141
141
 
@@ -167,6 +167,8 @@ global::initialize(const Napi::CallbackInfo &info)
167
167
  joystick::hat_positions[SDL_HAT_LEFTUP] = "leftup";
168
168
  joystick::hat_positions[SDL_HAT_LEFTDOWN] = "leftdown";
169
169
 
170
+ SDL_memset(&joystick::zero_guid, 0, sizeof(joystick::zero_guid));
171
+
170
172
  // controller::types[SDL_CONTROLLER_TYPE_UNKNOWN] = nullptr;
171
173
  controller::types[SDL_CONTROLLER_TYPE_XBOX360] = "xbox360";
172
174
  controller::types[SDL_CONTROLLER_TYPE_XBOXONE] = "xboxOne";
@@ -302,7 +304,8 @@ global::initialize(const Napi::CallbackInfo &info)
302
304
  throw Napi::Error::New(env, message.str());
303
305
  }
304
306
  current_video_driver = Napi::String::New(env, name);
305
- } else {
307
+ }
308
+ else {
306
309
  current_video_driver = env.Null();
307
310
  }
308
311
 
@@ -341,7 +344,8 @@ global::initialize(const Napi::CallbackInfo &info)
341
344
  throw Napi::Error::New(env, message.str());
342
345
  }
343
346
  current_audio_driver = Napi::String::New(env, name);
344
- } else {
347
+ }
348
+ else {
345
349
  current_audio_driver = env.Null();
346
350
  }
347
351
 
@@ -10,7 +10,7 @@
10
10
  std::map<Uint8, std::string> joystick::hat_positions;
11
11
  std::map<SDL_JoystickType, std::string> joystick::types;
12
12
  std::map<SDL_JoystickPowerLevel, std::string> joystick::power_levels;
13
-
13
+ SDL_JoystickGUID joystick::zero_guid;
14
14
 
15
15
  double
16
16
  joystick::mapAxis (SDL_Joystick *joystick, int axis) {
@@ -49,29 +49,27 @@ joystick::_getDevices (Napi::Env &env)
49
49
  throw Napi::Error::New(env, message.str());
50
50
  }
51
51
 
52
- const char *name = SDL_JoystickNameForIndex(i);
53
- if (name == nullptr) {
54
- std::ostringstream message;
55
- message << "SDL_JoystickNameForIndex(" << i << ") error: " << SDL_GetError();
56
- SDL_ClearError();
57
- throw Napi::Error::New(env, message.str());
58
- }
59
-
60
- const char *path = SDL_JoystickPathForIndex(i);
61
- if (path == nullptr) {
62
- std::ostringstream message;
63
- message << "SDL_JoystickPathForIndex(" << i << ") error: " << SDL_GetError();
64
- SDL_ClearError();
65
- throw Napi::Error::New(env, message.str());
66
- }
52
+ const char *_name = SDL_JoystickNameForIndex(i);
53
+ Napi::Value name = _name != nullptr
54
+ ? Napi::String::New(env, _name)
55
+ : env.Null();
67
56
 
68
- // This function can only error if the index is invalid.
69
- SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
57
+ const char *_path = SDL_JoystickPathForIndex(i);
58
+ Napi::Value path = _path != nullptr
59
+ ? Napi::String::New(env, _path)
60
+ : env.Null();
70
61
 
71
- char guid_string[33];
72
- SDL_JoystickGetGUIDString(guid, guid_string, 33);
62
+ SDL_JoystickGUID _guid = SDL_JoystickGetDeviceGUID(i);
63
+ Napi::Value guid;
64
+ if (SDL_memcmp(&_guid, &zero_guid, sizeof(SDL_JoystickGUID)) != 0) {
65
+ char guid_string[33];
66
+ SDL_JoystickGetGUIDString(_guid, guid_string, 33);
67
+ guid = Napi::String::New(env, guid_string);
68
+ }
69
+ else {
70
+ guid = env.Null();
71
+ }
73
72
 
74
- // This function can only error if the index is invalid.
75
73
  SDL_JoystickType _type = SDL_JoystickGetDeviceType(i);
76
74
  Napi::Value type = _type != SDL_JOYSTICK_TYPE_UNKNOWN
77
75
  ? Napi::String::New(env, joystick::types[_type])
@@ -104,30 +102,23 @@ joystick::_getDevices (Napi::Env &env)
104
102
  Napi::Value controller_type;
105
103
 
106
104
  if (is_controller) {
107
- const char *_controller_mapping = SDL_GameControllerMappingForDeviceIndex(i);
108
- if (_controller_mapping == nullptr) {
109
- std::ostringstream message;
110
- message << "SDL_GameControllerMappingForDeviceIndex(" << i << ") error: " << SDL_GetError();
111
- SDL_ClearError();
112
- throw Napi::Error::New(env, message.str());
113
- }
114
- controller_mapping = Napi::String::New(env, _controller_mapping);
105
+ char *_controller_mapping = SDL_GameControllerMappingForDeviceIndex(i);
106
+ controller_mapping = _controller_mapping != nullptr
107
+ ? Napi::String::New(env, _controller_mapping)
108
+ : env.Null();
109
+ SDL_free(_controller_mapping);
115
110
 
116
111
  const char *_controller_name = SDL_GameControllerNameForIndex(i);
117
- if (_controller_name == nullptr) {
118
- std::ostringstream message;
119
- message << "SDL_GameControllerNameForIndex(" << i << ") error: " << SDL_GetError();
120
- SDL_ClearError();
121
- throw Napi::Error::New(env, message.str());
122
- }
123
- controller_name = Napi::String::New(env, _controller_name);
124
-
125
- // This function can only error if the index is invalid.
112
+ controller_name = _controller_name != nullptr
113
+ ? Napi::String::New(env, _controller_name)
114
+ : env.Null();
115
+
126
116
  SDL_GameControllerType _controller_type = SDL_GameControllerTypeForIndex(i);
127
117
  controller_type = _controller_type != SDL_CONTROLLER_TYPE_UNKNOWN
128
118
  ? Napi::String::New(env, controller::types[_controller_type])
129
119
  : env.Null();
130
- } else {
120
+ }
121
+ else {
131
122
  controller_mapping = env.Null();
132
123
  controller_name = env.Null();
133
124
  controller_type = env.Null();
@@ -138,8 +129,8 @@ joystick::_getDevices (Napi::Env &env)
138
129
  device.Set("id", id);
139
130
  device.Set("name", name);
140
131
  device.Set("path", path);
141
- device.Set("guid", guid_string);
142
132
  device.Set("type", type);
133
+ device.Set("guid", guid);
143
134
  device.Set("vendor", vendor);
144
135
  device.Set("product", product);
145
136
  device.Set("version", version);
@@ -11,6 +11,7 @@ namespace joystick {
11
11
  extern std::map<SDL_JoystickType, std::string> types;
12
12
  extern std::map<Uint8, std::string> hat_positions;
13
13
  extern std::map<SDL_JoystickPowerLevel, std::string> power_levels;
14
+ extern SDL_JoystickGUID zero_guid;
14
15
 
15
16
  double mapAxis (SDL_Joystick *joystick, int axis);
16
17
  double mapAxisValue (SDL_Joystick *joystick, int axis, int value);
@@ -33,7 +33,6 @@ sensor::getDevices (const Napi::CallbackInfo &info)
33
33
  throw Napi::Error::New(env, message.str());
34
34
  }
35
35
 
36
- // This function can only error if the index is invalid.
37
36
  SDL_SensorType _type = SDL_SensorGetDeviceType(i);
38
37
  Napi::Value type = _type != SDL_SENSOR_UNKNOWN
39
38
  ? Napi::String::New(env, sensor::types[_type])
@@ -25,13 +25,10 @@ video::getDisplays(const Napi::CallbackInfo &info)
25
25
  Napi::Array displays = Napi::Array::New(env, num_displays);
26
26
 
27
27
  for (int i = 0; i < num_displays; i++) {
28
- const char *name = SDL_GetDisplayName(i);
29
- if(name == nullptr) {
30
- std::ostringstream message;
31
- message << "SDL_GetDisplayName(" << i << ") error: " << SDL_GetError();
32
- SDL_ClearError();
33
- throw Napi::Error::New(env, message.str());
34
- }
28
+ const char *_name = SDL_GetDisplayName(i);
29
+ Napi::Value name = _name != nullptr
30
+ ? Napi::String::New(env, _name)
31
+ : env.Null();
35
32
 
36
33
  SDL_DisplayMode mode;
37
34
  if (SDL_GetCurrentDisplayMode(i, &mode) < 0) {
@@ -72,7 +69,8 @@ video::getDisplays(const Napi::CallbackInfo &info)
72
69
  float ddpi, hdpi, vdpi;
73
70
  if (SDL_GetDisplayDPI(i, &ddpi, &hdpi, &vdpi) < 0) {
74
71
  dpi = env.Null();
75
- } else {
72
+ }
73
+ else {
76
74
  Napi::Object dpi_obj = Napi::Object::New(env);
77
75
  dpi_obj.Set("diagonal", ddpi);
78
76
  dpi_obj.Set("horizontal", hdpi);
@@ -382,7 +382,7 @@ export namespace Sdl {
382
382
  | 'best'
383
383
 
384
384
  export interface Display {
385
- readonly name: string
385
+ readonly name: string | null
386
386
  readonly format: Format
387
387
  readonly frequency: number
388
388
  readonly geometry: {
@@ -508,7 +508,7 @@ export namespace Sdl {
508
508
 
509
509
  setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
510
510
 
511
- flash (untilFocused: boolean): void
511
+ flash (untilFocused?: boolean): void
512
512
  stopFlashing (): void
513
513
 
514
514
  readonly destroyed: boolean
@@ -902,10 +902,10 @@ export namespace Sdl {
902
902
 
903
903
  export interface Device {
904
904
  readonly id: number
905
- readonly name: string
906
- readonly path: string
907
- readonly guid: string
905
+ readonly name: string | null
906
+ readonly path: string | null
908
907
  readonly type: JoystickType | null
908
+ readonly guid: string | null
909
909
  readonly vendor: number | null
910
910
  readonly product: number | null
911
911
  readonly version: number | null
@@ -1012,14 +1012,14 @@ export namespace Sdl {
1012
1012
  export interface Device {
1013
1013
  readonly id: number
1014
1014
  readonly name: string
1015
- readonly path: string
1016
- readonly guid: string
1017
- readonly type: ControllerType | null;
1015
+ readonly path: string | null
1016
+ readonly type: ControllerType | null
1017
+ readonly guid: string | null
1018
1018
  readonly vendor: number | null
1019
1019
  readonly product: number | null
1020
1020
  readonly version: number | null
1021
1021
  readonly player: number | null
1022
- readonly mapping: string
1022
+ readonly mapping: string | null
1023
1023
  }
1024
1024
 
1025
1025
  export class ControllerInstance {