@kmamal/sdl 1.0.0-2 → 1.0.0-4
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 +81 -218
- package/README.md +22 -8
- package/binding.gyp +1 -0
- package/package.json +7 -7
- package/scripts/build.mjs +1 -6
- package/scripts/util/common.js +0 -2
- package/src/javascript/audio/audio-stream.js +7 -4
- package/src/javascript/audio/format-helpers.js +4 -0
- package/src/javascript/events/index.js +7 -0
- package/src/javascript/gamepad/gamepad-instance.js +6 -4
- package/src/javascript/index.js +1 -1
- package/src/javascript/joystick/joystick-instance.js +6 -4
- package/src/javascript/joystick/shared.js +2 -0
- package/src/javascript/sensor/sensor-instance.js +4 -2
- package/src/javascript/video/format-helpers.js +28 -10
- package/src/javascript/video/index.js +7 -0
- package/src/javascript/video/window.js +44 -34
- package/src/javascript/{helpers.js → worker.js} +43 -0
- package/src/native/audio.cpp +65 -3
- package/src/native/audio.h +3 -0
- package/src/native/gamepad.cpp +1 -1
- package/src/native/global.cpp +29 -0
- package/src/native/global.h +5 -0
- package/src/native/module.cpp +2 -0
- package/src/native/window.cpp +12 -12
- package/src/types/index.d.ts +35 -33
- package/src/types/{helpers.d.ts → worker.d.ts} +16 -9
package/src/native/global.h
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
#define _GLOBAL_H_
|
|
3
3
|
|
|
4
4
|
#include <napi.h>
|
|
5
|
+
#include <mutex>
|
|
5
6
|
|
|
6
7
|
namespace global {
|
|
7
8
|
|
|
9
|
+
std::mutex &lock();
|
|
10
|
+
void assertReady(Napi::Env &env);
|
|
11
|
+
void registerEnv(Napi::Env env);
|
|
12
|
+
|
|
8
13
|
Napi::Value initialize(const Napi::CallbackInfo &info);
|
|
9
14
|
Napi::Value cleanup(const Napi::CallbackInfo &info);
|
|
10
15
|
|
package/src/native/module.cpp
CHANGED
package/src/native/window.cpp
CHANGED
|
@@ -58,7 +58,7 @@ updateRenderer(
|
|
|
58
58
|
Napi::Env &env,
|
|
59
59
|
SDL_Window *window,
|
|
60
60
|
bool *is_accelerated,
|
|
61
|
-
|
|
61
|
+
int *vsync
|
|
62
62
|
) {
|
|
63
63
|
int window_id = SDL_GetWindowID(window);
|
|
64
64
|
// Not likely to fail.
|
|
@@ -82,20 +82,20 @@ updateRenderer(
|
|
|
82
82
|
|
|
83
83
|
if (renderer == nullptr) {
|
|
84
84
|
std::ostringstream message;
|
|
85
|
-
message << "SDL_CreateRenderer(" << window_id << ", " << *is_accelerated << ", " << *
|
|
85
|
+
message << "SDL_CreateRenderer(" << window_id << ", " << *is_accelerated << ", " << *vsync << ") error: " << SDL_GetError();
|
|
86
86
|
SDL_ClearError();
|
|
87
87
|
throw Napi::Error::New(env, message.str());
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
if (!SDL_SetRenderVSync(renderer, *
|
|
90
|
+
if (!SDL_SetRenderVSync(renderer, *vsync)) { SDL_ClearError(); }
|
|
91
91
|
|
|
92
92
|
const char *renderer_name = SDL_GetRendererName(renderer);
|
|
93
93
|
if (renderer_name == nullptr) { SDL_ClearError(); }
|
|
94
94
|
else { *is_accelerated = SDL_strcmp(renderer_name, SDL_SOFTWARE_RENDERER) != 0; }
|
|
95
95
|
|
|
96
|
-
int
|
|
97
|
-
if (!SDL_GetRenderVSync(renderer, &
|
|
98
|
-
else { *
|
|
96
|
+
int actual_vsync;
|
|
97
|
+
if (!SDL_GetRenderVSync(renderer, &actual_vsync)) { SDL_ClearError(); }
|
|
98
|
+
else { *vsync = actual_vsync; }
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
|
|
@@ -119,7 +119,7 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
119
119
|
bool is_webgpu = info[14].As<Napi::Boolean>().Value();
|
|
120
120
|
bool has_renderer = !is_opengl && !is_webgpu;
|
|
121
121
|
bool is_accelerated = has_renderer && info[11].As<Napi::Boolean>().Value();
|
|
122
|
-
|
|
122
|
+
int vsync = has_renderer ? info[12].As<Napi::Number>().Int32Value() : 0;
|
|
123
123
|
|
|
124
124
|
Uint64 desired_flags = 0
|
|
125
125
|
| SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY
|
|
@@ -294,7 +294,7 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
294
294
|
native.Set("gpu", Napi::Buffer<GPU_NativeData>::Copy(env, &native_gpu, 1));
|
|
295
295
|
}
|
|
296
296
|
else {
|
|
297
|
-
updateRenderer(env, window, &is_accelerated, &
|
|
297
|
+
updateRenderer(env, window, &is_accelerated, &vsync);
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
if (is_visible && !SDL_ShowWindow(window)) {
|
|
@@ -339,7 +339,7 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
339
339
|
result.Set("alwaysOnTop", is_always_on_top);
|
|
340
340
|
if (has_renderer) {
|
|
341
341
|
result.Set("accelerated", is_accelerated);
|
|
342
|
-
result.Set("vsync",
|
|
342
|
+
result.Set("vsync", vsync);
|
|
343
343
|
}
|
|
344
344
|
else {
|
|
345
345
|
result.Set("accelerated", env.Null());
|
|
@@ -538,15 +538,15 @@ window::setAcceleratedAndVsync (const Napi::CallbackInfo &info)
|
|
|
538
538
|
|
|
539
539
|
int window_id = info[0].As<Napi::Number>().Int32Value();
|
|
540
540
|
bool is_accelerated = info[1].As<Napi::Boolean>().Value();
|
|
541
|
-
|
|
541
|
+
int vsync = info[2].As<Napi::Number>().Int32Value();
|
|
542
542
|
|
|
543
543
|
SDL_Window *window = getWindow(env, window_id);
|
|
544
544
|
|
|
545
|
-
updateRenderer(env, window, &is_accelerated, &
|
|
545
|
+
updateRenderer(env, window, &is_accelerated, &vsync);
|
|
546
546
|
|
|
547
547
|
Napi::Object result = Napi::Object::New(env);
|
|
548
548
|
result.Set("accelerated", is_accelerated);
|
|
549
|
-
result.Set("vsync",
|
|
549
|
+
result.Set("vsync", vsync);
|
|
550
550
|
|
|
551
551
|
return result;
|
|
552
552
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -294,7 +294,7 @@ export namespace Events {
|
|
|
294
294
|
|
|
295
295
|
export interface SteamHandleUpdate extends GamepadEvent {
|
|
296
296
|
readonly type: 'steamHandleUpdate'
|
|
297
|
-
readonly steamHandle:
|
|
297
|
+
readonly steamHandle: bigint | null
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
export interface Remap extends GamepadEvent { readonly type: 'remap' }
|
|
@@ -505,14 +505,6 @@ export namespace Sdl {
|
|
|
505
505
|
| 'argb128f'
|
|
506
506
|
| 'bgra128f'
|
|
507
507
|
| 'abgr128f'
|
|
508
|
-
| 'rgba32'
|
|
509
|
-
| 'argb32'
|
|
510
|
-
| 'bgra32'
|
|
511
|
-
| 'abgr32'
|
|
512
|
-
| 'rgbx32'
|
|
513
|
-
| 'xrgb32'
|
|
514
|
-
| 'bgrx32'
|
|
515
|
-
| 'xbgr32'
|
|
516
508
|
| 'yv12'
|
|
517
509
|
| 'iyuv'
|
|
518
510
|
| 'yuy2'
|
|
@@ -522,6 +514,16 @@ export namespace Sdl {
|
|
|
522
514
|
| 'nv21'
|
|
523
515
|
| 'p010'
|
|
524
516
|
|
|
517
|
+
export type FormatAlias
|
|
518
|
+
= 'rgba32'
|
|
519
|
+
| 'argb32'
|
|
520
|
+
| 'bgra32'
|
|
521
|
+
| 'abgr32'
|
|
522
|
+
| 'rgbx32'
|
|
523
|
+
| 'xrgb32'
|
|
524
|
+
| 'bgrx32'
|
|
525
|
+
| 'xbgr32'
|
|
526
|
+
|
|
525
527
|
export type Scaling
|
|
526
528
|
= 'nearest'
|
|
527
529
|
| 'linear'
|
|
@@ -618,15 +620,12 @@ export namespace Sdl {
|
|
|
618
620
|
readonly accelerated: boolean | null
|
|
619
621
|
setAccelerated (accelerated: boolean): void
|
|
620
622
|
|
|
621
|
-
readonly vsync:
|
|
622
|
-
setVsync (vsync:
|
|
623
|
+
readonly vsync: number | null
|
|
624
|
+
setVsync (vsync: number): void
|
|
623
625
|
|
|
624
626
|
readonly opengl: boolean
|
|
625
627
|
readonly webgpu: boolean
|
|
626
|
-
readonly native:
|
|
627
|
-
handle: Buffer | null,
|
|
628
|
-
subsystem: 'x11' | 'wayland' | null,
|
|
629
|
-
}
|
|
628
|
+
readonly native: unknown
|
|
630
629
|
|
|
631
630
|
readonly maximized: boolean
|
|
632
631
|
maximize (): void
|
|
@@ -646,7 +645,7 @@ export namespace Sdl {
|
|
|
646
645
|
setRelativeMouseMode (relative?: boolean): void
|
|
647
646
|
unsetRelativeMouseMode (): void
|
|
648
647
|
|
|
649
|
-
render (width: number, height: number, stride: number, format: Format, buffer: Buffer, options?: {
|
|
648
|
+
render (width: number, height: number, stride: number, format: Format | FormatAlias, buffer: Buffer, options?: {
|
|
650
649
|
scaling?: Scaling,
|
|
651
650
|
dstRect?: {
|
|
652
651
|
x: number,
|
|
@@ -656,7 +655,7 @@ export namespace Sdl {
|
|
|
656
655
|
} | null
|
|
657
656
|
}): void
|
|
658
657
|
|
|
659
|
-
setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
|
|
658
|
+
setIcon (width: number, height: number, stride: number, format: Format | FormatAlias, buffer: Buffer): void
|
|
660
659
|
|
|
661
660
|
flash (untilFocused?: boolean): void
|
|
662
661
|
stopFlashing (): void
|
|
@@ -696,15 +695,16 @@ export namespace Sdl {
|
|
|
696
695
|
borderless?: boolean
|
|
697
696
|
alwaysOnTop?: boolean
|
|
698
697
|
accelerated?: boolean
|
|
699
|
-
vsync?:
|
|
698
|
+
vsync?: number
|
|
700
699
|
opengl?: boolean
|
|
701
700
|
webgpu?: boolean
|
|
702
701
|
}): Window
|
|
703
702
|
|
|
704
|
-
bytesPerPixel (format: Format): number
|
|
705
|
-
isYuv (format: Format): boolean
|
|
706
|
-
isPlanarYuv (format: Format): boolean
|
|
707
|
-
|
|
703
|
+
bytesPerPixel (format: Format | FormatAlias): number
|
|
704
|
+
isYuv (format: Format | FormatAlias): boolean
|
|
705
|
+
isPlanarYuv (format: Format | FormatAlias): boolean
|
|
706
|
+
minStride (format: Format | FormatAlias, width: number): number
|
|
707
|
+
minBufferSize (format: Format | FormatAlias, stride: number, height: number): number
|
|
708
708
|
}
|
|
709
709
|
}
|
|
710
710
|
|
|
@@ -1023,7 +1023,7 @@ export namespace Sdl {
|
|
|
1023
1023
|
|
|
1024
1024
|
setCursor (cursor: Cursor): void
|
|
1025
1025
|
resetCursor (): void
|
|
1026
|
-
setCursorImage (width: number, height: number, stride: number, format: Video.Format, buffer: Buffer, x: number, y: number): void
|
|
1026
|
+
setCursorImage (width: number, height: number, stride: number, format: Video.Format | Video.FormatAlias, buffer: Buffer, x: number, y: number): void
|
|
1027
1027
|
|
|
1028
1028
|
showCursor (show?: boolean): void
|
|
1029
1029
|
hideCursor (): void
|
|
@@ -1242,7 +1242,7 @@ export namespace Sdl {
|
|
|
1242
1242
|
readonly device: Device
|
|
1243
1243
|
readonly firmwareVersion: number | null
|
|
1244
1244
|
readonly serialNumber: string | null
|
|
1245
|
-
readonly steamHandle:
|
|
1245
|
+
readonly steamHandle: bigint | null
|
|
1246
1246
|
|
|
1247
1247
|
readonly axes: { readonly [axis in Axis]: number }
|
|
1248
1248
|
readonly buttons: { readonly [button in Button]: boolean }
|
|
@@ -1342,12 +1342,14 @@ export namespace Sdl {
|
|
|
1342
1342
|
| 'u8'
|
|
1343
1343
|
| 's16le'
|
|
1344
1344
|
| 's16be'
|
|
1345
|
-
| 's16'
|
|
1346
1345
|
| 's32le'
|
|
1347
1346
|
| 's32be'
|
|
1348
|
-
| 's32'
|
|
1349
1347
|
| 'f32le'
|
|
1350
1348
|
| 'f32be'
|
|
1349
|
+
|
|
1350
|
+
export type FormatAlias
|
|
1351
|
+
= 's16'
|
|
1352
|
+
| 's32'
|
|
1351
1353
|
| 'f32'
|
|
1352
1354
|
|
|
1353
1355
|
export interface Device {
|
|
@@ -1362,7 +1364,7 @@ export namespace Sdl {
|
|
|
1362
1364
|
export interface StreamOptions {
|
|
1363
1365
|
readonly channels?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
|
|
1364
1366
|
readonly frequency?: number
|
|
1365
|
-
readonly format?: Format
|
|
1367
|
+
readonly format?: Format | FormatAlias
|
|
1366
1368
|
readonly buffered?: number
|
|
1367
1369
|
}
|
|
1368
1370
|
|
|
@@ -1420,12 +1422,12 @@ export namespace Sdl {
|
|
|
1420
1422
|
readonly playback: DeviceModule<AudioPlaybackStream>
|
|
1421
1423
|
readonly recording: DeviceModule<AudioRecordingStream>
|
|
1422
1424
|
|
|
1423
|
-
bytesPerSample (format: Format): number
|
|
1424
|
-
minSampleValue (format: Format): number
|
|
1425
|
-
maxSampleValue (format: Format): number
|
|
1426
|
-
zeroSampleValue (format: Format): number
|
|
1427
|
-
readSample (format: Format, buffer: Buffer, offset?: number): number
|
|
1428
|
-
writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
|
|
1425
|
+
bytesPerSample (format: Format | FormatAlias): number
|
|
1426
|
+
minSampleValue (format: Format | FormatAlias): number
|
|
1427
|
+
maxSampleValue (format: Format | FormatAlias): number
|
|
1428
|
+
zeroSampleValue (format: Format | FormatAlias): number
|
|
1429
|
+
readSample (format: Format | FormatAlias, buffer: Buffer, offset?: number): number
|
|
1430
|
+
writeSample (format: Format | FormatAlias, buffer: Buffer, value: number, offset?: number): number
|
|
1429
1431
|
}
|
|
1430
1432
|
}
|
|
1431
1433
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
1
|
import type { Sdl } from './index'
|
|
3
2
|
|
|
4
|
-
export namespace
|
|
3
|
+
export namespace SdlWorker {
|
|
5
4
|
|
|
6
5
|
export namespace Video {
|
|
7
6
|
|
|
8
|
-
export type Format = Sdl.Video.Format
|
|
7
|
+
export type Format = Sdl.Video.Format | Sdl.Video.FormatAlias
|
|
9
8
|
|
|
10
9
|
interface Module {
|
|
11
10
|
bytesPerPixel (format: Format): number
|
|
12
11
|
isYuv (format: Format): boolean
|
|
13
12
|
isPlanarYuv (format: Format): boolean
|
|
13
|
+
minStride (format: Format, width: number): number
|
|
14
14
|
minBufferSize (format: Format, stride: number, height: number): number
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -42,7 +42,7 @@ export namespace SdlHelpers {
|
|
|
42
42
|
|
|
43
43
|
export namespace Audio {
|
|
44
44
|
|
|
45
|
-
export type Format = Sdl.Audio.Format
|
|
45
|
+
export type Format = Sdl.Audio.Format | Sdl.Audio.FormatAlias
|
|
46
46
|
|
|
47
47
|
interface Module {
|
|
48
48
|
bytesPerSample (format: Format): number
|
|
@@ -51,14 +51,21 @@ export namespace SdlHelpers {
|
|
|
51
51
|
zeroSampleValue (format: Format): number
|
|
52
52
|
readSample (format: Format, buffer: Buffer, offset?: number): number
|
|
53
53
|
writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
|
|
54
|
+
|
|
55
|
+
readonly playback: DeviceModule<Sdl.Audio.AudioPlaybackStream>
|
|
56
|
+
readonly recording: DeviceModule<Sdl.Audio.AudioRecordingStream>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface DeviceModule<Stream extends Sdl.Audio.AudioStream> {
|
|
60
|
+
openDevice (device?: Sdl.Audio.Device | null, options?: Sdl.Audio.StreamOptions): Stream
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
export const video:
|
|
61
|
-
export const keyboard:
|
|
62
|
-
export const mouse:
|
|
63
|
-
export const sensor:
|
|
64
|
-
export const audio:
|
|
67
|
+
export const video: SdlWorker.Video.Module
|
|
68
|
+
export const keyboard: SdlWorker.Keyboard.Module
|
|
69
|
+
export const mouse: SdlWorker.Mouse.Module
|
|
70
|
+
export const sensor: SdlWorker.Sensor.Module
|
|
71
|
+
export const audio: SdlWorker.Audio.Module
|