sfml.js 1.0.0 → 1.2.1
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.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/src/system/time.ts
CHANGED
|
@@ -6,7 +6,9 @@ const minInt64 = -(2n ** 63n);
|
|
|
6
6
|
const maxInt64 = 2n ** 63n - 1n;
|
|
7
7
|
|
|
8
8
|
export function checkedMicroseconds(value: bigint): bigint {
|
|
9
|
-
if (typeof value !== 'bigint')
|
|
9
|
+
if (typeof value !== 'bigint') {
|
|
10
|
+
throw new TypeError('Expected a bigint');
|
|
11
|
+
}
|
|
10
12
|
if (value < minInt64 || value > maxInt64) {
|
|
11
13
|
throw new RangeError('Time must fit in a signed 64-bit microsecond count');
|
|
12
14
|
}
|
|
@@ -18,9 +20,13 @@ export function checkedMicroseconds(value: bigint): bigint {
|
|
|
18
20
|
/* eslint-disable no-bitwise */
|
|
19
21
|
function int64AsFloat(value: bigint): number {
|
|
20
22
|
const magnitude = value < 0n ? -value : value;
|
|
21
|
-
if (magnitude <= 9007199254740991n)
|
|
23
|
+
if (magnitude <= 9007199254740991n) {
|
|
24
|
+
return Math.fround(Number(value));
|
|
25
|
+
}
|
|
22
26
|
let exponent = Math.floor(Math.log2(Number(magnitude)));
|
|
23
|
-
if (magnitude < (1n << BigInt(exponent)))
|
|
27
|
+
if (magnitude < (1n << BigInt(exponent))) {
|
|
28
|
+
exponent--;
|
|
29
|
+
}
|
|
24
30
|
const shift = BigInt(exponent - 23);
|
|
25
31
|
let significand = magnitude >> shift;
|
|
26
32
|
const remainder = magnitude - (significand << shift);
|
|
@@ -35,7 +41,9 @@ function int64AsFloat(value: bigint): number {
|
|
|
35
41
|
/* eslint-enable no-bitwise */
|
|
36
42
|
|
|
37
43
|
function floatScalar(value: number): number {
|
|
38
|
-
if (typeof value !== 'number')
|
|
44
|
+
if (typeof value !== 'number') {
|
|
45
|
+
throw new TypeError('Expected a number');
|
|
46
|
+
}
|
|
39
47
|
const result = Math.fround(value);
|
|
40
48
|
if (!Number.isFinite(result)) {
|
|
41
49
|
throw new RangeError('Time requires a finite float32 value');
|
|
@@ -163,7 +171,9 @@ export function seconds(amount: number): Time {
|
|
|
163
171
|
* 32비트 정수 범위 내여야 한다.
|
|
164
172
|
*/
|
|
165
173
|
export function milliseconds(amount: number): Time {
|
|
166
|
-
if (typeof amount !== 'number')
|
|
174
|
+
if (typeof amount !== 'number') {
|
|
175
|
+
throw new TypeError('Expected a number');
|
|
176
|
+
}
|
|
167
177
|
const integer = Math.trunc(amount);
|
|
168
178
|
if (!Number.isFinite(integer) ||
|
|
169
179
|
integer < -2147483648 || integer > 2147483647) {
|
|
@@ -210,7 +220,9 @@ export function remainderTime(
|
|
|
210
220
|
): bigint {
|
|
211
221
|
const lhs = left.asMicroseconds();
|
|
212
222
|
const rhs = right.asMicroseconds();
|
|
213
|
-
if (rhs === 0n)
|
|
223
|
+
if (rhs === 0n) {
|
|
224
|
+
throw new RangeError('Cannot divide by zero');
|
|
225
|
+
}
|
|
214
226
|
if (lhs === minInt64 && rhs === -1n) {
|
|
215
227
|
throw new RangeError('Time remainder quotient exceeds the int64 range');
|
|
216
228
|
}
|
|
@@ -37,7 +37,10 @@ export class TimeoutWithPredicate {
|
|
|
37
37
|
* @ko 주기적 확인 설정을 생성한다. period 기본값은 1밀리초이며
|
|
38
38
|
* null이면 첫 확인에서 대기를 종료한다.
|
|
39
39
|
*/
|
|
40
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
predicate: TimeoutPredicate | null,
|
|
42
|
+
period?: ReadonlyValue<Time>,
|
|
43
|
+
);
|
|
41
44
|
/**
|
|
42
45
|
* Copy the configuration, retaining the same predicate and copying the
|
|
43
46
|
* check period.
|
|
@@ -47,27 +50,35 @@ export class TimeoutWithPredicate {
|
|
|
47
50
|
*/
|
|
48
51
|
constructor(source: Readonly<TimeoutWithPredicate>);
|
|
49
52
|
constructor(
|
|
50
|
-
source:
|
|
51
|
-
|
|
53
|
+
source:
|
|
54
|
+
| ReadonlyValue<Time>
|
|
55
|
+
| TimeoutPredicate
|
|
56
|
+
| null
|
|
57
|
+
| Readonly<TimeoutWithPredicate>,
|
|
58
|
+
period?: ReadonlyValue<Time>,
|
|
52
59
|
) {
|
|
53
60
|
if (source instanceof Time || source instanceof TimeoutWithPredicate) {
|
|
54
61
|
if (period !== undefined) {
|
|
55
62
|
throw new TypeError('A timeout or copy accepts only one argument');
|
|
56
63
|
}
|
|
57
64
|
this.predicate = source instanceof Time ? stop : source.predicate;
|
|
58
|
-
this.period = Object.freeze(
|
|
59
|
-
source instanceof Time ? source : source.period)
|
|
65
|
+
this.period = Object.freeze(
|
|
66
|
+
new Time(source instanceof Time ? source : source.period),
|
|
67
|
+
);
|
|
60
68
|
return;
|
|
61
69
|
}
|
|
62
70
|
if (source !== null && typeof source !== 'function') {
|
|
63
|
-
throw new TypeError(
|
|
71
|
+
throw new TypeError(
|
|
72
|
+
'Expected a Time, predicate, null or TimeoutWithPredicate',
|
|
73
|
+
);
|
|
64
74
|
}
|
|
65
75
|
if (period !== undefined && !(period instanceof Time)) {
|
|
66
76
|
throw new TypeError('Expected a Time period');
|
|
67
77
|
}
|
|
68
78
|
this.predicate = source ?? stop;
|
|
69
|
-
this.period = Object.freeze(
|
|
70
|
-
period === undefined ? milliseconds(1) : period)
|
|
79
|
+
this.period = Object.freeze(
|
|
80
|
+
new Time(period === undefined ? milliseconds(1) : period),
|
|
81
|
+
);
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
/**
|
package/src/system/vector2.ts
CHANGED
|
@@ -3,26 +3,37 @@ import { LazyValue, nativeValue } from '../internal/lazy-value';
|
|
|
3
3
|
import { Angle, radians } from './angle';
|
|
4
4
|
import type { Bvec2 } from '../graphics/boolean-vector';
|
|
5
5
|
import {
|
|
6
|
-
vector2Storage,
|
|
6
|
+
vector2Storage,
|
|
7
|
+
vector2Native,
|
|
8
|
+
type ReadonlyValue,
|
|
9
|
+
mutableValue,
|
|
7
10
|
} from '../internal/value-storage';
|
|
8
11
|
import {
|
|
9
|
-
scalarArrays,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
scalarArrays,
|
|
13
|
+
requireFloat,
|
|
14
|
+
toScalar,
|
|
15
|
+
scalarProduct,
|
|
16
|
+
convertScalar,
|
|
17
|
+
validateScalar,
|
|
18
|
+
type ScalarType,
|
|
19
|
+
type Scalar,
|
|
20
|
+
type ScalarArray,
|
|
21
|
+
type NumberScalar,
|
|
22
|
+
type FloatScalar,
|
|
12
23
|
} from '../internal/scalar';
|
|
13
24
|
|
|
14
25
|
export type { ScalarType } from '../internal/scalar';
|
|
15
26
|
|
|
16
27
|
type Vector2Source =
|
|
17
|
-
ReadonlyValue<Vector2<ScalarType>>
|
|
28
|
+
| ReadonlyValue<Vector2<ScalarType>>
|
|
29
|
+
| ReadonlyValue<Bvec2>;
|
|
18
30
|
type Vector2Arguments<T extends ScalarType = NumberScalar> =
|
|
19
31
|
| []
|
|
20
|
-
| [
|
|
21
|
-
| [
|
|
22
|
-
type PolarArguments = [
|
|
32
|
+
| [x: Scalar<T>, y: Scalar<T>]
|
|
33
|
+
| [source: Vector2Source];
|
|
34
|
+
type PolarArguments = [r: number, phi: ReadonlyValue<Angle>];
|
|
23
35
|
|
|
24
|
-
type Vector2State =
|
|
25
|
-
LazyValue<'vector2', ScalarArray>;
|
|
36
|
+
type Vector2State = LazyValue<'vector2', ScalarArray>;
|
|
26
37
|
|
|
27
38
|
/**
|
|
28
39
|
* sf::Vector2<T>, with a native handle lazily bound to its existing storage.
|
|
@@ -59,7 +70,9 @@ export class Vector2<T extends ScalarType> {
|
|
|
59
70
|
*/
|
|
60
71
|
constructor(
|
|
61
72
|
scalarType: T,
|
|
62
|
-
...args:
|
|
73
|
+
...args:
|
|
74
|
+
| Vector2Arguments<T>
|
|
75
|
+
| (T extends FloatScalar ? PolarArguments : never)
|
|
63
76
|
);
|
|
64
77
|
/**
|
|
65
78
|
* Copy the vector and its scalar type with independent storage.
|
|
@@ -72,15 +85,18 @@ export class Vector2<T extends ScalarType> {
|
|
|
72
85
|
typeOrSource: T | ReadonlyValue<Vector2<T>>,
|
|
73
86
|
...args: Vector2Arguments<ScalarType> | PolarArguments
|
|
74
87
|
) {
|
|
75
|
-
this.type =
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
this.type =
|
|
89
|
+
typeof typeOrSource === 'string'
|
|
90
|
+
? typeOrSource
|
|
91
|
+
: (typeOrSource.scalarType as T);
|
|
78
92
|
validateScalar(this.type);
|
|
79
93
|
const type = this.type;
|
|
80
|
-
this.state = new LazyValue(new scalarArrays[type](2),
|
|
81
|
-
|
|
94
|
+
this.state = new LazyValue(new scalarArrays[type](2), buffer =>
|
|
95
|
+
native.wrapVector2(type, buffer),
|
|
96
|
+
);
|
|
82
97
|
|
|
83
|
-
const source =
|
|
98
|
+
const source =
|
|
99
|
+
typeof typeOrSource === 'string' ? args[0] : typeOrSource;
|
|
84
100
|
if (typeof source === 'number' || typeof source === 'bigint') {
|
|
85
101
|
if (args[1] instanceof Angle) {
|
|
86
102
|
requireFloat(this.type);
|
|
@@ -97,7 +113,8 @@ export class Vector2<T extends ScalarType> {
|
|
|
97
113
|
if (source instanceof Vector2 && source.scalarType === type) {
|
|
98
114
|
const input = source[vector2Storage];
|
|
99
115
|
new Uint8Array(this.state.values.buffer).set(
|
|
100
|
-
new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
116
|
+
new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
|
|
117
|
+
);
|
|
101
118
|
} else {
|
|
102
119
|
this.x = convertScalar(type, source.x) as Scalar<T>;
|
|
103
120
|
this.y = convertScalar(type, source.y) as Scalar<T>;
|
|
@@ -200,12 +217,17 @@ export class Vector2<T extends ScalarType> {
|
|
|
200
217
|
normalized(this: ReadonlyValue<Vector2<T & FloatScalar>>): Vector2<T>;
|
|
201
218
|
normalized(): Vector2<T> {
|
|
202
219
|
requireFloat(this.type);
|
|
203
|
-
const length = toScalar(
|
|
220
|
+
const length = toScalar(
|
|
221
|
+
this.type,
|
|
222
|
+
Math.sqrt(this.lengthSquared() as number),
|
|
223
|
+
);
|
|
204
224
|
if (length === 0) {
|
|
205
225
|
throw new RangeError('Cannot normalize a vector with zero length');
|
|
206
226
|
}
|
|
207
|
-
return this.createResult(
|
|
208
|
-
(this.
|
|
227
|
+
return this.createResult(
|
|
228
|
+
(this.x as number) / length,
|
|
229
|
+
(this.y as number) / length,
|
|
230
|
+
);
|
|
209
231
|
}
|
|
210
232
|
|
|
211
233
|
/**
|
|
@@ -242,7 +264,9 @@ export class Vector2<T extends ScalarType> {
|
|
|
242
264
|
if (rhs.x === 0 && rhs.y === 0) {
|
|
243
265
|
throw new RangeError('Cannot calculate angle to a zero vector');
|
|
244
266
|
}
|
|
245
|
-
return radians(
|
|
267
|
+
return radians(
|
|
268
|
+
Math.atan2(this.cross(rhs) as number, this.dot(rhs) as number),
|
|
269
|
+
);
|
|
246
270
|
}
|
|
247
271
|
|
|
248
272
|
/**
|
|
@@ -255,7 +279,8 @@ export class Vector2<T extends ScalarType> {
|
|
|
255
279
|
* 화면 좌표에서 양의 각도는 시계 방향이다.
|
|
256
280
|
*/
|
|
257
281
|
rotatedBy(
|
|
258
|
-
this: ReadonlyValue<Vector2<T & FloatScalar>>,
|
|
282
|
+
this: ReadonlyValue<Vector2<T & FloatScalar>>,
|
|
283
|
+
phi: ReadonlyValue<Angle>,
|
|
259
284
|
): Vector2<T>;
|
|
260
285
|
rotatedBy(phi: ReadonlyValue<Angle>): Vector2<T> {
|
|
261
286
|
requireFloat(this.type);
|
|
@@ -288,10 +313,14 @@ export class Vector2<T extends ScalarType> {
|
|
|
288
313
|
if (axis.x === 0 && axis.y === 0) {
|
|
289
314
|
throw new RangeError('Cannot project onto a zero vector');
|
|
290
315
|
}
|
|
291
|
-
const ratio = toScalar(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
316
|
+
const ratio = toScalar(
|
|
317
|
+
this.type,
|
|
318
|
+
(this.dot(axis) as number) / (axis.lengthSquared() as number),
|
|
319
|
+
);
|
|
320
|
+
return this.createResult(
|
|
321
|
+
ratio * (axis.x as number),
|
|
322
|
+
ratio * (axis.y as number),
|
|
323
|
+
);
|
|
295
324
|
}
|
|
296
325
|
|
|
297
326
|
/**
|
|
@@ -303,13 +332,16 @@ export class Vector2<T extends ScalarType> {
|
|
|
303
332
|
dot(rhs: ReadonlyValue<Vector2<T>>): Scalar<T> {
|
|
304
333
|
this.checkScalarType(rhs);
|
|
305
334
|
if (typeof this.x === 'bigint') {
|
|
306
|
-
return convertScalar(
|
|
307
|
-
this.
|
|
308
|
-
(this.y as bigint) * (rhs.y as bigint)
|
|
335
|
+
return convertScalar(
|
|
336
|
+
this.type,
|
|
337
|
+
this.x * (rhs.x as bigint) + (this.y as bigint) * (rhs.y as bigint),
|
|
338
|
+
) as Scalar<T>;
|
|
309
339
|
}
|
|
310
|
-
return toScalar(
|
|
340
|
+
return toScalar(
|
|
341
|
+
this.type,
|
|
311
342
|
scalarProduct(this.type, this.x as number, rhs.x as number) +
|
|
312
|
-
|
|
343
|
+
scalarProduct(this.type, this.y as number, rhs.y as number),
|
|
344
|
+
) as Scalar<T>;
|
|
313
345
|
}
|
|
314
346
|
|
|
315
347
|
/**
|
|
@@ -324,13 +356,16 @@ export class Vector2<T extends ScalarType> {
|
|
|
324
356
|
cross(rhs: ReadonlyValue<Vector2<T>>): Scalar<T> {
|
|
325
357
|
this.checkScalarType(rhs);
|
|
326
358
|
if (typeof this.x === 'bigint') {
|
|
327
|
-
return convertScalar(
|
|
328
|
-
this.
|
|
329
|
-
(this.y as bigint) * (rhs.x as bigint)
|
|
359
|
+
return convertScalar(
|
|
360
|
+
this.type,
|
|
361
|
+
this.x * (rhs.y as bigint) - (this.y as bigint) * (rhs.x as bigint),
|
|
362
|
+
) as Scalar<T>;
|
|
330
363
|
}
|
|
331
|
-
return toScalar(
|
|
364
|
+
return toScalar(
|
|
365
|
+
this.type,
|
|
332
366
|
scalarProduct(this.type, this.x as number, rhs.y as number) -
|
|
333
|
-
|
|
367
|
+
scalarProduct(this.type, this.y as number, rhs.x as number),
|
|
368
|
+
) as Scalar<T>;
|
|
334
369
|
}
|
|
335
370
|
|
|
336
371
|
/**
|
|
@@ -352,8 +387,10 @@ export class Vector2<T extends ScalarType> {
|
|
|
352
387
|
componentWiseMul(rhs: ReadonlyValue<Vector2<T>>): Vector2<T> {
|
|
353
388
|
this.checkScalarType(rhs);
|
|
354
389
|
if (typeof this.x === 'bigint') {
|
|
355
|
-
return this.createResult(
|
|
356
|
-
|
|
390
|
+
return this.createResult(
|
|
391
|
+
this.x * (rhs.x as bigint),
|
|
392
|
+
(this.y as bigint) * (rhs.y as bigint),
|
|
393
|
+
);
|
|
357
394
|
}
|
|
358
395
|
return this.createResult(
|
|
359
396
|
scalarProduct(this.type, this.x as number, rhs.x as number),
|
|
@@ -373,17 +410,26 @@ export class Vector2<T extends ScalarType> {
|
|
|
373
410
|
componentWiseDiv(rhs: ReadonlyValue<Vector2<T>>): Vector2<T> {
|
|
374
411
|
this.checkScalarType(rhs);
|
|
375
412
|
if (rhs.x === 0 || rhs.y === 0 || rhs.x === 0n || rhs.y === 0n) {
|
|
376
|
-
throw new RangeError(
|
|
413
|
+
throw new RangeError(
|
|
414
|
+
'Vector2.componentWiseDiv() cannot divide by zero',
|
|
415
|
+
);
|
|
377
416
|
}
|
|
378
417
|
if (typeof this.x === 'bigint') {
|
|
379
|
-
return this.createResult(
|
|
380
|
-
|
|
418
|
+
return this.createResult(
|
|
419
|
+
this.x / (rhs.x as bigint),
|
|
420
|
+
(this.y as bigint) / (rhs.y as bigint),
|
|
421
|
+
);
|
|
381
422
|
}
|
|
382
|
-
return this.createResult(
|
|
383
|
-
(this.
|
|
423
|
+
return this.createResult(
|
|
424
|
+
(this.x as number) / (rhs.x as number),
|
|
425
|
+
(this.y as number) / (rhs.y as number),
|
|
426
|
+
);
|
|
384
427
|
}
|
|
385
428
|
|
|
386
|
-
protected createResult(
|
|
429
|
+
protected createResult(
|
|
430
|
+
x: number | bigint,
|
|
431
|
+
y: number | bigint,
|
|
432
|
+
): Vector2<T> {
|
|
387
433
|
return new Vector2(this.type, x as Scalar<T>, y as Scalar<T>);
|
|
388
434
|
}
|
|
389
435
|
|
|
@@ -395,7 +441,9 @@ export class Vector2<T extends ScalarType> {
|
|
|
395
441
|
|
|
396
442
|
private checkScalarType(rhs: ReadonlyValue<Vector2<T>>): void {
|
|
397
443
|
if (!(rhs instanceof Vector2) || rhs.scalarType !== this.type) {
|
|
398
|
-
throw new TypeError(
|
|
444
|
+
throw new TypeError(
|
|
445
|
+
'Vector2 operands must have the same scalar type',
|
|
446
|
+
);
|
|
399
447
|
}
|
|
400
448
|
}
|
|
401
449
|
}
|
|
@@ -524,8 +572,11 @@ export class Vector2f extends Vector2<'f32'> {
|
|
|
524
572
|
|
|
525
573
|
const vector2Classes = { i32: Vector2i, u32: Vector2u, f32: Vector2f };
|
|
526
574
|
|
|
527
|
-
function createMemberResult(
|
|
528
|
-
|
|
575
|
+
function createMemberResult(
|
|
576
|
+
this: Vector2<'i32' | 'u32' | 'f32'>,
|
|
577
|
+
x: number,
|
|
578
|
+
y: number,
|
|
579
|
+
) {
|
|
529
580
|
const Constructor = vector2Classes[this.scalarType];
|
|
530
581
|
return new Constructor(x, y);
|
|
531
582
|
}
|
|
@@ -537,7 +588,8 @@ function createMemberResult(this: Vector2<'i32' | 'u32' | 'f32'>,
|
|
|
537
588
|
* @ko 내부 멤버 뷰. 부모를 통해 네이티브 소유권을 확인할 수 있다.
|
|
538
589
|
*/
|
|
539
590
|
export function vector2FromState<T extends 'i32' | 'u32' | 'f32'>(
|
|
540
|
-
type: T,
|
|
591
|
+
type: T,
|
|
592
|
+
state: Vector2State,
|
|
541
593
|
): Vector2<T> {
|
|
542
594
|
// Bypass allocation and initialize the same fields as the value constructor.
|
|
543
595
|
return Object.assign(Object.create(vector2Classes[type].prototype), {
|
package/src/system/vector3.ts
CHANGED
|
@@ -2,20 +2,32 @@ import { native, type NativeValueHandle } from '../internal/native';
|
|
|
2
2
|
import { LazyValue, nativeValue } from '../internal/lazy-value';
|
|
3
3
|
import type { Bvec3 } from '../graphics/boolean-vector';
|
|
4
4
|
import {
|
|
5
|
-
vector3Storage,
|
|
5
|
+
vector3Storage,
|
|
6
|
+
vector3Native,
|
|
7
|
+
mutableValue,
|
|
8
|
+
type ReadonlyValue,
|
|
6
9
|
} from '../internal/value-storage';
|
|
7
10
|
import {
|
|
8
|
-
scalarArrays,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
scalarArrays,
|
|
12
|
+
toScalar,
|
|
13
|
+
scalarProduct,
|
|
14
|
+
requireFloat,
|
|
15
|
+
type ScalarType,
|
|
16
|
+
convertScalar,
|
|
17
|
+
validateScalar,
|
|
18
|
+
type Scalar,
|
|
19
|
+
type ScalarArray,
|
|
20
|
+
type NumberScalar,
|
|
21
|
+
type FloatScalar,
|
|
11
22
|
} from '../internal/scalar';
|
|
12
23
|
|
|
13
24
|
type Vector3Source =
|
|
14
|
-
ReadonlyValue<Vector3<ScalarType>>
|
|
25
|
+
| ReadonlyValue<Vector3<ScalarType>>
|
|
26
|
+
| ReadonlyValue<Bvec3>;
|
|
15
27
|
type Vector3Arguments<T extends ScalarType = NumberScalar> =
|
|
16
28
|
| []
|
|
17
|
-
| [
|
|
18
|
-
| [
|
|
29
|
+
| [x: Scalar<T>, y: Scalar<T>, z: Scalar<T>]
|
|
30
|
+
| [source: Vector3Source];
|
|
19
31
|
|
|
20
32
|
/**
|
|
21
33
|
* sf::Vector3<T>, stored as three consecutive values of its scalar type.
|
|
@@ -26,8 +38,7 @@ type Vector3Arguments<T extends ScalarType = NumberScalar> =
|
|
|
26
38
|
export class Vector3<T extends ScalarType> {
|
|
27
39
|
readonly [mutableValue] = true;
|
|
28
40
|
private readonly type: T;
|
|
29
|
-
private readonly state:
|
|
30
|
-
LazyValue<'vector3', ScalarArray>;
|
|
41
|
+
private readonly state: LazyValue<'vector3', ScalarArray>;
|
|
31
42
|
|
|
32
43
|
/**
|
|
33
44
|
* Create a 3D vector of the specified scalar type.
|
|
@@ -59,13 +70,17 @@ export class Vector3<T extends ScalarType> {
|
|
|
59
70
|
typeOrSource: T | ReadonlyValue<Vector3<T>>,
|
|
60
71
|
...args: Vector3Arguments<ScalarType>
|
|
61
72
|
) {
|
|
62
|
-
this.type =
|
|
63
|
-
|
|
73
|
+
this.type =
|
|
74
|
+
typeof typeOrSource === 'string'
|
|
75
|
+
? typeOrSource
|
|
76
|
+
: (typeOrSource.scalarType as T);
|
|
64
77
|
const type = this.type;
|
|
65
78
|
validateScalar(type);
|
|
66
|
-
this.state = new LazyValue(new scalarArrays[type](3),
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
this.state = new LazyValue(new scalarArrays[type](3), buffer =>
|
|
80
|
+
native.wrapVector3(type, buffer),
|
|
81
|
+
);
|
|
82
|
+
const source =
|
|
83
|
+
typeof typeOrSource === 'string' ? args[0] : typeOrSource;
|
|
69
84
|
if (typeof source === 'number' || typeof source === 'bigint') {
|
|
70
85
|
this.x = source as Scalar<T>;
|
|
71
86
|
this.y = (args[1] ?? 0) as Scalar<T>;
|
|
@@ -74,7 +89,8 @@ export class Vector3<T extends ScalarType> {
|
|
|
74
89
|
if (source instanceof Vector3 && source.scalarType === type) {
|
|
75
90
|
const input = source[vector3Storage];
|
|
76
91
|
new Uint8Array(this.state.values.buffer).set(
|
|
77
|
-
new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
92
|
+
new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
|
|
93
|
+
);
|
|
78
94
|
} else {
|
|
79
95
|
this.x = convertScalar(type, source.x) as Scalar<T>;
|
|
80
96
|
this.y = convertScalar(type, source.y) as Scalar<T>;
|
|
@@ -199,12 +215,16 @@ export class Vector3<T extends ScalarType> {
|
|
|
199
215
|
normalized(this: ReadonlyValue<Vector3<T & FloatScalar>>): Vector3<T>;
|
|
200
216
|
normalized(): Vector3<T> {
|
|
201
217
|
requireFloat(this.type);
|
|
202
|
-
const length = toScalar(
|
|
218
|
+
const length = toScalar(
|
|
219
|
+
this.type,
|
|
220
|
+
Math.sqrt(this.lengthSquared() as number),
|
|
221
|
+
);
|
|
203
222
|
if (length === 0) {
|
|
204
223
|
throw new RangeError('Cannot normalize a vector with zero length');
|
|
205
224
|
}
|
|
206
225
|
return this.createResult(
|
|
207
|
-
(this.x as number) / length,
|
|
226
|
+
(this.x as number) / length,
|
|
227
|
+
(this.y as number) / length,
|
|
208
228
|
(this.z as number) / length,
|
|
209
229
|
);
|
|
210
230
|
}
|
|
@@ -218,16 +238,22 @@ export class Vector3<T extends ScalarType> {
|
|
|
218
238
|
dot(rhs: ReadonlyValue<Vector3<T>>): Scalar<T> {
|
|
219
239
|
this.checkScalarType(rhs);
|
|
220
240
|
if (typeof this.x === 'bigint') {
|
|
221
|
-
return convertScalar(
|
|
241
|
+
return convertScalar(
|
|
242
|
+
this.type,
|
|
222
243
|
this.x * (rhs.x as bigint) +
|
|
223
|
-
|
|
224
|
-
|
|
244
|
+
(this.y as bigint) * (rhs.y as bigint) +
|
|
245
|
+
(this.z as bigint) * (rhs.z as bigint),
|
|
246
|
+
) as Scalar<T>;
|
|
225
247
|
}
|
|
226
|
-
const xy = toScalar(
|
|
248
|
+
const xy = toScalar(
|
|
249
|
+
this.type,
|
|
227
250
|
scalarProduct(this.type, this.x as number, rhs.x as number) +
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
scalarProduct(this.type, this.y as number, rhs.y as number),
|
|
252
|
+
);
|
|
253
|
+
return toScalar(
|
|
254
|
+
this.type,
|
|
255
|
+
xy + scalarProduct(this.type, this.z as number, rhs.z as number),
|
|
256
|
+
) as Scalar<T>;
|
|
231
257
|
}
|
|
232
258
|
|
|
233
259
|
/**
|
|
@@ -267,9 +293,11 @@ export class Vector3<T extends ScalarType> {
|
|
|
267
293
|
componentWiseMul(rhs: ReadonlyValue<Vector3<T>>): Vector3<T> {
|
|
268
294
|
this.checkScalarType(rhs);
|
|
269
295
|
if (typeof this.x === 'bigint') {
|
|
270
|
-
return this.createResult(
|
|
296
|
+
return this.createResult(
|
|
297
|
+
this.x * (rhs.x as bigint),
|
|
271
298
|
(this.y as bigint) * (rhs.y as bigint),
|
|
272
|
-
(this.z as bigint) * (rhs.z as bigint)
|
|
299
|
+
(this.z as bigint) * (rhs.z as bigint),
|
|
300
|
+
);
|
|
273
301
|
}
|
|
274
302
|
return this.createResult(
|
|
275
303
|
scalarProduct(this.type, this.x as number, rhs.x as number),
|
|
@@ -289,29 +317,50 @@ export class Vector3<T extends ScalarType> {
|
|
|
289
317
|
*/
|
|
290
318
|
componentWiseDiv(rhs: ReadonlyValue<Vector3<T>>): Vector3<T> {
|
|
291
319
|
this.checkScalarType(rhs);
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
320
|
+
if (
|
|
321
|
+
rhs.x === 0 ||
|
|
322
|
+
rhs.y === 0 ||
|
|
323
|
+
rhs.z === 0 ||
|
|
324
|
+
rhs.x === 0n ||
|
|
325
|
+
rhs.y === 0n ||
|
|
326
|
+
rhs.z === 0n
|
|
327
|
+
) {
|
|
328
|
+
throw new RangeError(
|
|
329
|
+
'Vector3.componentWiseDiv() cannot divide by zero',
|
|
330
|
+
);
|
|
295
331
|
}
|
|
296
332
|
if (typeof this.x === 'bigint') {
|
|
297
|
-
return this.createResult(
|
|
333
|
+
return this.createResult(
|
|
334
|
+
this.x / (rhs.x as bigint),
|
|
298
335
|
(this.y as bigint) / (rhs.y as bigint),
|
|
299
|
-
(this.z as bigint) / (rhs.z as bigint)
|
|
336
|
+
(this.z as bigint) / (rhs.z as bigint),
|
|
337
|
+
);
|
|
300
338
|
}
|
|
301
|
-
return this.createResult(
|
|
339
|
+
return this.createResult(
|
|
340
|
+
(this.x as number) / (rhs.x as number),
|
|
302
341
|
(this.y as number) / (rhs.y as number),
|
|
303
|
-
(this.z as number) / (rhs.z as number)
|
|
342
|
+
(this.z as number) / (rhs.z as number),
|
|
343
|
+
);
|
|
304
344
|
}
|
|
305
345
|
|
|
306
346
|
protected createResult(
|
|
307
|
-
x: number | bigint,
|
|
347
|
+
x: number | bigint,
|
|
348
|
+
y: number | bigint,
|
|
349
|
+
z: number | bigint,
|
|
308
350
|
): Vector3<T> {
|
|
309
|
-
return new Vector3(
|
|
351
|
+
return new Vector3(
|
|
352
|
+
this.type,
|
|
353
|
+
x as Scalar<T>,
|
|
354
|
+
y as Scalar<T>,
|
|
355
|
+
z as Scalar<T>,
|
|
356
|
+
);
|
|
310
357
|
}
|
|
311
358
|
|
|
312
359
|
private checkScalarType(rhs: ReadonlyValue<Vector3<T>>): void {
|
|
313
360
|
if (!(rhs instanceof Vector3) || rhs.scalarType !== this.type) {
|
|
314
|
-
throw new TypeError(
|
|
361
|
+
throw new TypeError(
|
|
362
|
+
'Vector3 operands must have the same scalar type',
|
|
363
|
+
);
|
|
315
364
|
}
|
|
316
365
|
}
|
|
317
366
|
}
|
package/src/window/clipboard.ts
CHANGED
|
@@ -17,6 +17,8 @@ export function getString(): string {
|
|
|
17
17
|
* @ko 시스템 클립보드 텍스트를 text로 교체한다.
|
|
18
18
|
*/
|
|
19
19
|
export function setString(text: string): void {
|
|
20
|
-
if (typeof text !== 'string')
|
|
20
|
+
if (typeof text !== 'string') {
|
|
21
|
+
throw new TypeError('Expected clipboard text');
|
|
22
|
+
}
|
|
21
23
|
native.setClipboardString(text);
|
|
22
24
|
}
|
package/src/window/context.ts
CHANGED
|
@@ -16,7 +16,9 @@ export type ReadonlyContext = Readonly<Pick<Context, 'getSettings'>>;
|
|
|
16
16
|
|
|
17
17
|
const contexts = new Map<bigint, WeakRef<Context>>();
|
|
18
18
|
const collected = new FinalizationRegistry<bigint>(key => {
|
|
19
|
-
if (!contexts.get(key)?.deref())
|
|
19
|
+
if (!contexts.get(key)?.deref()) {
|
|
20
|
+
contexts.delete(key);
|
|
21
|
+
}
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
function remember(key: bigint, context: Context): void {
|
|
@@ -77,7 +79,9 @@ export class Context {
|
|
|
77
79
|
* 활성화 또는 비활성화한 뒤 성공 여부를 반환한다.
|
|
78
80
|
*/
|
|
79
81
|
setActive(active: boolean): boolean {
|
|
80
|
-
if (typeof active !== 'boolean')
|
|
82
|
+
if (typeof active !== 'boolean') {
|
|
83
|
+
throw new TypeError('Expected a boolean');
|
|
84
|
+
}
|
|
81
85
|
flushGraphics();
|
|
82
86
|
return native.setContextActive(this[graphicsNative], active);
|
|
83
87
|
}
|
|
@@ -103,11 +107,17 @@ export class Context {
|
|
|
103
107
|
*/
|
|
104
108
|
static getActiveContext(): ReadonlyContext | undefined {
|
|
105
109
|
const key = native.getActiveContextKey();
|
|
106
|
-
if (key === undefined)
|
|
110
|
+
if (key === undefined) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
107
113
|
const existing = contexts.get(key)?.deref();
|
|
108
|
-
if (existing)
|
|
114
|
+
if (existing) {
|
|
115
|
+
return existing;
|
|
116
|
+
}
|
|
109
117
|
const mapping = native.referenceActiveContext();
|
|
110
|
-
if (!mapping)
|
|
118
|
+
if (!mapping) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
111
121
|
const context = Object.create(Context.prototype) as Context;
|
|
112
122
|
Object.defineProperties(context, {
|
|
113
123
|
[graphicsNative]: { value: mapping.handle },
|
package/src/window/cursor.ts
CHANGED
|
@@ -76,7 +76,9 @@ export class Cursor {
|
|
|
76
76
|
) {
|
|
77
77
|
const handle = typeof source === 'number' ? systemCursor(source)
|
|
78
78
|
: pixelCursor(source, size!, hotspot!);
|
|
79
|
-
if (!handle)
|
|
79
|
+
if (!handle) {
|
|
80
|
+
throw new SFMLError('Failed to create cursor');
|
|
81
|
+
}
|
|
80
82
|
this[graphicsNative] = handle;
|
|
81
83
|
}
|
|
82
84
|
|