@kmamal/sdl 0.11.9 → 0.11.10

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/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v0.11.10] - 2025-07-19
9
+
10
+ ### Changed
11
+
12
+ - Made it optional to initialize the joystick, controller, haptic, or sensor subsystems during SDL initialization. Failing to initialize any of these is not fatal to the application. The new `sdl.info.initialized` object contains relevant information.
13
+
8
14
  ## [v0.11.9] - 2025-07-18
9
15
 
10
16
  ### Fixed
@@ -26,7 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
32
 
27
33
  - Started keeping this changelog.
28
34
 
29
- [unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.9...HEAD
30
- [v0.11.8]: https://github.com/kmamal/node-sdl/compare/v0.11.8...v0.11.9
35
+ [unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.10...HEAD
36
+ [v0.11.10]: https://github.com/kmamal/node-sdl/compare/v0.11.9...v0.11.10
37
+ [v0.11.9]: https://github.com/kmamal/node-sdl/compare/v0.11.8...v0.11.9
31
38
  [v0.11.8]: https://github.com/kmamal/node-sdl/compare/v0.11.7...v0.11.8
32
39
  [v0.11.7]: https://github.com/kmamal/node-sdl/releases/tag/v0.11.7
package/README.md CHANGED
@@ -383,6 +383,13 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
383
383
  * `audio: <object>`
384
384
  * `all: <string>[]` A list of all audio drivers.
385
385
  * `current: <string>|<null>` The audio driver that is currently selected.
386
+ * `initialized: <object>`
387
+ * `video: <boolean>`: Is `true` if the video subsystem was sucessfully initialized, or `false` otherwise.
388
+ * `audio: <boolean>`: Is `true` if the audio subsystem was sucessfully initialized, or `false` otherwise.
389
+ * `joystick: <boolean>`: Is `true` if the joystick subsystem was sucessfully initialized, or `false` otherwise.
390
+ * `controller: <boolean>`: Is `true` if the controller subsystem was sucessfully initialized, or `false` otherwise.
391
+ * `haptic: <boolean>`: Is `true` if the haptic subsystem was sucessfully initialized, or `false` otherwise.
392
+ * `sensor: <boolean>`: Is `true` if the sensor subsystem was sucessfully initialized, or `false` otherwise.
386
393
 
387
394
  The `sdl.info` object is filled with information produced during the initialization of SDL.
388
395
  All the values remain constant throughout the execution of the program.
@@ -411,6 +418,14 @@ Sample data for Ubuntu:
411
418
  current: 'pulseaudio',
412
419
  },
413
420
  },
421
+ initialized: {
422
+ video: true,
423
+ audio: true,
424
+ joystick: true,
425
+ controller: true,
426
+ haptic: true,
427
+ sensor: true,
428
+ },
414
429
  }
415
430
  ```
416
431
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.11.9",
2
+ "version": "0.11.10",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -6,18 +6,18 @@ import * as Tar from 'tar'
6
6
 
7
7
  const url = `https://github.com/${C.sdl.owner}/${C.sdl.repo}/releases/download/v${C.sdl.version}/${C.sdl.assetName}`
8
8
 
9
- console.log("fetch", url)
10
9
  try {
10
+ console.log("fetch", url)
11
11
  const response = await fetch(url)
12
12
 
13
-
14
13
  console.log("unpack to", C.dir.sdl)
15
14
  await Fs.promises.rm(C.dir.sdl, { recursive: true }).catch(() => {})
16
15
  await Fs.promises.mkdir(C.dir.sdl, { recursive: true })
17
16
  const tar = Tar.extract({ gzip: true, C: C.dir.sdl })
18
17
  response.stream().pipe(tar)
19
18
  await once(tar, 'finish')
20
- } catch (error) {
19
+ }
20
+ catch (error) {
21
21
  console.log(error)
22
22
  throw error
23
23
  }
@@ -167,8 +167,6 @@ 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
-
172
170
  // controller::types[SDL_CONTROLLER_TYPE_UNKNOWN] = nullptr;
173
171
  controller::types[SDL_CONTROLLER_TYPE_XBOX360] = "xbox360";
174
172
  controller::types[SDL_CONTROLLER_TYPE_XBOXONE] = "xboxOne";
@@ -237,15 +235,11 @@ global::initialize(const Napi::CallbackInfo &info)
237
235
  power::states[SDL_POWERSTATE_CHARGED] = "charged";
238
236
 
239
237
 
238
+ Napi::Object initialized = Napi::Object::New(env);
239
+
240
240
  SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
241
241
 
242
- if (SDL_Init(0
243
- | SDL_INIT_EVENTS
244
- | SDL_INIT_JOYSTICK
245
- | SDL_INIT_GAMECONTROLLER
246
- | SDL_INIT_HAPTIC
247
- | SDL_INIT_SENSOR
248
- ) < 0) {
242
+ if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
249
243
  std::ostringstream message;
250
244
  message << "SDL_Init() error: " << SDL_GetError();
251
245
  SDL_ClearError();
@@ -272,7 +266,7 @@ global::initialize(const Napi::CallbackInfo &info)
272
266
  versions.Set("compile", compile_version);
273
267
  versions.Set("runtime", runtime_version);
274
268
 
275
- const char *platform_name = SDL_GetPlatform();
269
+ const char *platform = SDL_GetPlatform();
276
270
 
277
271
  Napi::Array all_video_drivers = Napi::Array::New(env);
278
272
 
@@ -304,9 +298,11 @@ global::initialize(const Napi::CallbackInfo &info)
304
298
  throw Napi::Error::New(env, message.str());
305
299
  }
306
300
  current_video_driver = Napi::String::New(env, name);
301
+ initialized.Set("video", true);
307
302
  }
308
303
  else {
309
304
  current_video_driver = env.Null();
305
+ initialized.Set("video", false);
310
306
  }
311
307
 
312
308
  Napi::Object video_drivers = Napi::Object::New(env);
@@ -344,9 +340,11 @@ global::initialize(const Napi::CallbackInfo &info)
344
340
  throw Napi::Error::New(env, message.str());
345
341
  }
346
342
  current_audio_driver = Napi::String::New(env, name);
343
+ initialized.Set("audio", true);
347
344
  }
348
345
  else {
349
346
  current_audio_driver = env.Null();
347
+ initialized.Set("audio", false);
350
348
  }
351
349
 
352
350
  Napi::Object audio_drivers = Napi::Object::New(env);
@@ -357,6 +355,11 @@ global::initialize(const Napi::CallbackInfo &info)
357
355
  drivers.Set("video", video_drivers);
358
356
  drivers.Set("audio", audio_drivers);
359
357
 
358
+ initialized.Set("joystick", SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0);
359
+ initialized.Set("controller", SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0);
360
+ initialized.Set("haptic", SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0);
361
+ initialized.Set("sensor", SDL_InitSubSystem(SDL_INIT_SENSOR) == 0);
362
+
360
363
  SDL_ClearError();
361
364
  global::no_error = SDL_GetError();
362
365
 
@@ -370,10 +373,13 @@ global::initialize(const Napi::CallbackInfo &info)
370
373
  reenableInertialScrolling();
371
374
  #endif
372
375
 
376
+ SDL_memset(&joystick::zero_guid, 0, sizeof(joystick::zero_guid));
377
+
373
378
  Napi::Object result = Napi::Object::New(env);
374
379
  result.Set("version", versions);
375
- result.Set("platform", platform_name);
380
+ result.Set("platform", platform);
376
381
  result.Set("drivers", drivers);
382
+ result.Set("initialized", initialized);
377
383
 
378
384
  return result;
379
385
  }
@@ -328,6 +328,14 @@ export namespace Sdl {
328
328
  readonly current: string
329
329
  }
330
330
  }
331
+ readonly initialized: {
332
+ video: boolean
333
+ audio: boolean
334
+ joystick: boolean
335
+ controller: boolean
336
+ haptic: boolean
337
+ sensor: boolean
338
+ }
331
339
  }
332
340
 
333
341
  export namespace Video {