sfml.js 1.0.0 → 1.1.0
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 +40 -48
- 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/operators.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Angle, positiveRemainder, radians } from './angle';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Time,
|
|
4
|
+
checkedMicroseconds,
|
|
5
|
+
scaleTime,
|
|
6
|
+
remainderTime,
|
|
7
|
+
} from './time';
|
|
3
8
|
import { Vector2, Vector2i, Vector2u, Vector2f } from './vector2';
|
|
4
9
|
import { Vector3, Vector3i, Vector3u, Vector3f } from './vector3';
|
|
5
10
|
import { Color } from '../graphics/color';
|
|
@@ -12,45 +17,87 @@ import { IpAddress } from '../network/ip-address';
|
|
|
12
17
|
import { Bvec2, Bvec3, BooleanVector } from '../graphics/boolean-vector';
|
|
13
18
|
import { glslStorage } from '../internal/glsl-value';
|
|
14
19
|
import {
|
|
15
|
-
type ScalarType,
|
|
16
|
-
|
|
20
|
+
type ScalarType,
|
|
21
|
+
type Scalar,
|
|
22
|
+
type ScalarArray,
|
|
23
|
+
type NumberScalar,
|
|
24
|
+
toScalar,
|
|
25
|
+
scalarProduct,
|
|
26
|
+
isBigIntScalar,
|
|
27
|
+
convertScalar,
|
|
17
28
|
} from '../internal/scalar';
|
|
18
29
|
import {
|
|
19
|
-
angleStorage,
|
|
20
|
-
|
|
30
|
+
angleStorage,
|
|
31
|
+
timeStorage,
|
|
32
|
+
vector2Storage,
|
|
33
|
+
vector3Storage,
|
|
34
|
+
colorStorage,
|
|
35
|
+
rectStorage,
|
|
36
|
+
transformStorage,
|
|
21
37
|
type ReadonlyValue as R,
|
|
22
38
|
} from '../internal/value-storage';
|
|
23
39
|
|
|
24
|
-
type Intersect<U> = (
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
type Intersect<U> = (
|
|
41
|
+
U extends unknown ? (value: U) => void : never
|
|
42
|
+
) extends (value: infer I) => void
|
|
43
|
+
? I
|
|
44
|
+
: never;
|
|
45
|
+
type VectorAddition = Intersect<
|
|
46
|
+
{
|
|
47
|
+
[T in ScalarType]: {
|
|
48
|
+
(left: R<Vector2<T>>, right: R<Vector2<T>>): Vector2<T>;
|
|
49
|
+
(left: R<Vector3<T>>, right: R<Vector3<T>>): Vector3<T>;
|
|
50
|
+
};
|
|
51
|
+
}[ScalarType]
|
|
52
|
+
>;
|
|
53
|
+
type VectorAdditionAssign = Intersect<
|
|
54
|
+
{
|
|
55
|
+
[T in ScalarType]: {
|
|
56
|
+
(left: Vector2<T>, right: R<Vector2<T>>): Vector2<T>;
|
|
57
|
+
(left: Vector3<T>, right: R<Vector3<T>>): Vector3<T>;
|
|
58
|
+
};
|
|
59
|
+
}[ScalarType]
|
|
60
|
+
>;
|
|
61
|
+
type VectorNegation = Intersect<
|
|
62
|
+
{
|
|
63
|
+
[T in ScalarType]: {
|
|
64
|
+
(value: R<Vector2<T>>): Vector2<T>;
|
|
65
|
+
(value: R<Vector3<T>>): Vector3<T>;
|
|
66
|
+
};
|
|
67
|
+
}[ScalarType]
|
|
68
|
+
>;
|
|
69
|
+
type VectorScale = Intersect<
|
|
70
|
+
{
|
|
71
|
+
[T in ScalarType]: {
|
|
72
|
+
(left: R<Vector2<T>>, right: Scalar<T>): Vector2<T>;
|
|
73
|
+
(left: R<Vector3<T>>, right: Scalar<T>): Vector3<T>;
|
|
74
|
+
};
|
|
75
|
+
}[ScalarType]
|
|
76
|
+
>;
|
|
77
|
+
type VectorScaleAssign = Intersect<
|
|
78
|
+
{
|
|
79
|
+
[T in ScalarType]: {
|
|
80
|
+
(left: Vector2<T>, right: Scalar<T>): Vector2<T>;
|
|
81
|
+
(left: Vector3<T>, right: Scalar<T>): Vector3<T>;
|
|
82
|
+
};
|
|
83
|
+
}[ScalarType]
|
|
84
|
+
>;
|
|
85
|
+
type VectorLeftScale = Intersect<
|
|
86
|
+
{
|
|
87
|
+
[T in ScalarType]: {
|
|
88
|
+
(left: Scalar<T>, right: R<Vector2<T>>): Vector2<T>;
|
|
89
|
+
(left: Scalar<T>, right: R<Vector3<T>>): Vector3<T>;
|
|
90
|
+
};
|
|
91
|
+
}[ScalarType]
|
|
92
|
+
>;
|
|
93
|
+
type VectorEquality = Intersect<
|
|
94
|
+
{
|
|
95
|
+
[T in ScalarType]: {
|
|
96
|
+
(left: R<Vector2<T>>, right: R<Vector2<T>>): boolean;
|
|
97
|
+
(left: R<Vector3<T>>, right: R<Vector3<T>>): boolean;
|
|
98
|
+
};
|
|
99
|
+
}[ScalarType]
|
|
100
|
+
>;
|
|
54
101
|
|
|
55
102
|
interface Addition extends VectorAddition {
|
|
56
103
|
(left: R<Bvec2>, right: R<Bvec2>): Bvec2;
|
|
@@ -112,24 +159,48 @@ interface Equality extends VectorEquality {
|
|
|
112
159
|
}
|
|
113
160
|
|
|
114
161
|
type Value =
|
|
115
|
-
| Time
|
|
116
|
-
|
|
|
162
|
+
| Time
|
|
163
|
+
| Angle
|
|
164
|
+
| Color
|
|
165
|
+
| Vector2<ScalarType>
|
|
166
|
+
| Vector3<ScalarType>
|
|
167
|
+
| Bvec2
|
|
168
|
+
| Bvec3;
|
|
117
169
|
type Input =
|
|
118
|
-
| R<Time>
|
|
119
|
-
| R<
|
|
170
|
+
| R<Time>
|
|
171
|
+
| R<Angle>
|
|
172
|
+
| R<Color>
|
|
173
|
+
| R<Vector2<ScalarType>>
|
|
174
|
+
| R<Vector3<ScalarType>>
|
|
175
|
+
| R<Bvec2>
|
|
176
|
+
| R<Bvec3>;
|
|
120
177
|
|
|
121
178
|
function storage(value: Input) {
|
|
122
|
-
if (value instanceof BooleanVector)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (value instanceof
|
|
126
|
-
|
|
179
|
+
if (value instanceof BooleanVector) {
|
|
180
|
+
return value[glslStorage];
|
|
181
|
+
}
|
|
182
|
+
if (value instanceof Color) {
|
|
183
|
+
return value[colorStorage];
|
|
184
|
+
}
|
|
185
|
+
if (value instanceof Angle) {
|
|
186
|
+
return value[angleStorage];
|
|
187
|
+
}
|
|
188
|
+
if (value instanceof Vector2) {
|
|
189
|
+
return value[vector2Storage];
|
|
190
|
+
}
|
|
191
|
+
if (value instanceof Vector3) {
|
|
192
|
+
return value[vector3Storage];
|
|
193
|
+
}
|
|
127
194
|
throw new TypeError('Expected an Angle, Color, Vector2 or Vector3');
|
|
128
195
|
}
|
|
129
196
|
|
|
130
197
|
function scalarType(value: Input): ScalarType | 'bool' {
|
|
131
|
-
if (value instanceof BooleanVector)
|
|
132
|
-
|
|
198
|
+
if (value instanceof BooleanVector) {
|
|
199
|
+
return 'bool';
|
|
200
|
+
}
|
|
201
|
+
if (value instanceof Angle) {
|
|
202
|
+
return 'f32';
|
|
203
|
+
}
|
|
133
204
|
if (value instanceof Vector2 || value instanceof Vector3) {
|
|
134
205
|
return value.scalarType;
|
|
135
206
|
}
|
|
@@ -149,26 +220,56 @@ function checkPair(left: Input, right: Input): void {
|
|
|
149
220
|
}
|
|
150
221
|
return;
|
|
151
222
|
}
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
223
|
+
if (
|
|
224
|
+
storage(left).length !== storage(right).length ||
|
|
225
|
+
scalarType(left) !== scalarType(right)
|
|
226
|
+
) {
|
|
227
|
+
throw new TypeError(
|
|
228
|
+
'Operands must have the same value and scalar type',
|
|
229
|
+
);
|
|
155
230
|
}
|
|
156
231
|
}
|
|
157
232
|
|
|
158
233
|
function copy(value: Input): Value {
|
|
159
|
-
if (value instanceof Bvec2)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (value instanceof
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (value instanceof
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (value instanceof
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (value instanceof
|
|
234
|
+
if (value instanceof Bvec2) {
|
|
235
|
+
return new Bvec2(value);
|
|
236
|
+
}
|
|
237
|
+
if (value instanceof Bvec3) {
|
|
238
|
+
return new Bvec3(value);
|
|
239
|
+
}
|
|
240
|
+
if (value instanceof Time) {
|
|
241
|
+
return new Time(value);
|
|
242
|
+
}
|
|
243
|
+
if (value instanceof Color) {
|
|
244
|
+
return new Color(value);
|
|
245
|
+
}
|
|
246
|
+
if (value instanceof Angle) {
|
|
247
|
+
return new Angle(value);
|
|
248
|
+
}
|
|
249
|
+
if (value instanceof Vector2i) {
|
|
250
|
+
return new Vector2i(value);
|
|
251
|
+
}
|
|
252
|
+
if (value instanceof Vector2u) {
|
|
253
|
+
return new Vector2u(value);
|
|
254
|
+
}
|
|
255
|
+
if (value instanceof Vector2f) {
|
|
256
|
+
return new Vector2f(value);
|
|
257
|
+
}
|
|
258
|
+
if (value instanceof Vector3i) {
|
|
259
|
+
return new Vector3i(value);
|
|
260
|
+
}
|
|
261
|
+
if (value instanceof Vector3u) {
|
|
262
|
+
return new Vector3u(value);
|
|
263
|
+
}
|
|
264
|
+
if (value instanceof Vector3f) {
|
|
265
|
+
return new Vector3f(value);
|
|
266
|
+
}
|
|
267
|
+
if (value instanceof Vector2) {
|
|
268
|
+
return new Vector2(value);
|
|
269
|
+
}
|
|
270
|
+
if (value instanceof Vector3) {
|
|
271
|
+
return new Vector3(value);
|
|
272
|
+
}
|
|
172
273
|
throw new TypeError('Expected an Angle, Color, Vector2 or Vector3');
|
|
173
274
|
}
|
|
174
275
|
|
|
@@ -179,23 +280,32 @@ function checkMutable(value: Value): void {
|
|
|
179
280
|
}
|
|
180
281
|
|
|
181
282
|
function combine(
|
|
182
|
-
left: Value,
|
|
283
|
+
left: Value,
|
|
284
|
+
right: Input,
|
|
285
|
+
operation: 'add' | 'subtract',
|
|
183
286
|
): Value {
|
|
184
287
|
checkMutable(left);
|
|
185
288
|
checkPair(left, right);
|
|
186
289
|
if (left instanceof Time && right instanceof Time) {
|
|
187
|
-
left[timeStorage] = checkedMicroseconds(
|
|
188
|
-
|
|
189
|
-
|
|
290
|
+
left[timeStorage] = checkedMicroseconds(
|
|
291
|
+
operation === 'add'
|
|
292
|
+
? left.asMicroseconds() + right.asMicroseconds()
|
|
293
|
+
: left.asMicroseconds() - right.asMicroseconds(),
|
|
294
|
+
);
|
|
190
295
|
return left;
|
|
191
296
|
}
|
|
192
297
|
const leftData = storage(left);
|
|
193
298
|
const rightData = storage(right);
|
|
194
|
-
if (
|
|
299
|
+
if (
|
|
300
|
+
leftData instanceof BigInt64Array ||
|
|
301
|
+
leftData instanceof BigUint64Array
|
|
302
|
+
) {
|
|
195
303
|
const b = rightData as BigInt64Array | BigUint64Array;
|
|
196
304
|
for (let index = 0; index < leftData.length; index++) {
|
|
197
|
-
leftData[index] =
|
|
198
|
-
|
|
305
|
+
leftData[index] =
|
|
306
|
+
operation === 'add'
|
|
307
|
+
? leftData[index] + b[index]
|
|
308
|
+
: leftData[index] - b[index];
|
|
199
309
|
}
|
|
200
310
|
return left;
|
|
201
311
|
}
|
|
@@ -204,16 +314,20 @@ function combine(
|
|
|
204
314
|
const isColor = left instanceof Color;
|
|
205
315
|
const isBoolean = left instanceof BooleanVector;
|
|
206
316
|
for (let index = 0; index < a.length; index++) {
|
|
207
|
-
const result =
|
|
208
|
-
? a[index] + b[index] : a[index] - b[index];
|
|
209
|
-
a[index] = isColor
|
|
210
|
-
|
|
317
|
+
const result =
|
|
318
|
+
operation === 'add' ? a[index] + b[index] : a[index] - b[index];
|
|
319
|
+
a[index] = isColor
|
|
320
|
+
? Math.min(255, Math.max(0, result))
|
|
321
|
+
: isBoolean
|
|
322
|
+
? Number(result !== 0)
|
|
323
|
+
: result;
|
|
211
324
|
}
|
|
212
325
|
return left;
|
|
213
326
|
}
|
|
214
327
|
|
|
215
328
|
function modulate(
|
|
216
|
-
left: Value,
|
|
329
|
+
left: Value,
|
|
330
|
+
right: Input | number | bigint | boolean,
|
|
217
331
|
): Color {
|
|
218
332
|
checkMutable(left);
|
|
219
333
|
if (!(left instanceof Color) || !(right instanceof Color)) {
|
|
@@ -223,13 +337,14 @@ function modulate(
|
|
|
223
337
|
const b = right[colorStorage];
|
|
224
338
|
for (let index = 0; index < 4; index++) {
|
|
225
339
|
// Uint8Array truncates the nonnegative quotient, matching SFML.
|
|
226
|
-
a[index] = a[index] * b[index] / 255;
|
|
340
|
+
a[index] = (a[index] * b[index]) / 255;
|
|
227
341
|
}
|
|
228
342
|
return left;
|
|
229
343
|
}
|
|
230
344
|
|
|
231
345
|
function scale(
|
|
232
|
-
left: Value,
|
|
346
|
+
left: Value,
|
|
347
|
+
right: number | bigint | boolean,
|
|
233
348
|
operation: 'multiply' | 'divide',
|
|
234
349
|
): Value {
|
|
235
350
|
checkMutable(left);
|
|
@@ -240,11 +355,15 @@ function scale(
|
|
|
240
355
|
if (operation === 'divide' && !right) {
|
|
241
356
|
throw new RangeError('Cannot divide by zero');
|
|
242
357
|
}
|
|
243
|
-
if (!right)
|
|
358
|
+
if (!right) {
|
|
359
|
+
left[glslStorage].fill(0);
|
|
360
|
+
}
|
|
244
361
|
return left;
|
|
245
362
|
}
|
|
246
363
|
if (left instanceof Time) {
|
|
247
|
-
if (typeof right === 'boolean')
|
|
364
|
+
if (typeof right === 'boolean') {
|
|
365
|
+
throw new TypeError('Expected a scalar');
|
|
366
|
+
}
|
|
248
367
|
left[timeStorage] = scaleTime(left, right, operation);
|
|
249
368
|
return left;
|
|
250
369
|
}
|
|
@@ -253,26 +372,33 @@ function scale(
|
|
|
253
372
|
}
|
|
254
373
|
const type = scalarType(left) as ScalarType;
|
|
255
374
|
if (isBigIntScalar(type)) {
|
|
256
|
-
if (typeof right !== 'bigint')
|
|
375
|
+
if (typeof right !== 'bigint') {
|
|
376
|
+
throw new TypeError('Expected a bigint scalar');
|
|
377
|
+
}
|
|
257
378
|
const scalar = convertScalar(type, right) as bigint;
|
|
258
379
|
if (operation === 'divide' && scalar === 0n) {
|
|
259
380
|
throw new RangeError('Cannot divide by zero');
|
|
260
381
|
}
|
|
261
382
|
const data = storage(left) as BigInt64Array | BigUint64Array;
|
|
262
383
|
for (let i = 0; i < data.length; i++) {
|
|
263
|
-
data[i] =
|
|
384
|
+
data[i] =
|
|
385
|
+
operation === 'multiply' ? data[i] * scalar : data[i] / scalar;
|
|
264
386
|
}
|
|
265
387
|
return left;
|
|
266
388
|
}
|
|
267
|
-
if (typeof right !== 'number')
|
|
389
|
+
if (typeof right !== 'number') {
|
|
390
|
+
throw new TypeError('Expected a scalar');
|
|
391
|
+
}
|
|
268
392
|
const scalar = toScalar(type, right);
|
|
269
393
|
if (operation === 'divide' && scalar === 0) {
|
|
270
394
|
throw new RangeError('Cannot divide by zero');
|
|
271
395
|
}
|
|
272
396
|
const a = storage(left) as ScalarArray<NumberScalar>;
|
|
273
397
|
for (let index = 0; index < a.length; index++) {
|
|
274
|
-
a[index] =
|
|
275
|
-
|
|
398
|
+
a[index] =
|
|
399
|
+
operation === 'multiply'
|
|
400
|
+
? scalarProduct(type, a[index], scalar)
|
|
401
|
+
: a[index] / scalar;
|
|
276
402
|
}
|
|
277
403
|
return left;
|
|
278
404
|
}
|
|
@@ -338,7 +464,9 @@ export const negate = ((value: Input) => {
|
|
|
338
464
|
}
|
|
339
465
|
const data = storage(result);
|
|
340
466
|
if (!(result instanceof BooleanVector)) {
|
|
341
|
-
for (let index = 0; index < data.length; index++)
|
|
467
|
+
for (let index = 0; index < data.length; index++) {
|
|
468
|
+
data[index] = -data[index];
|
|
469
|
+
}
|
|
342
470
|
}
|
|
343
471
|
return result;
|
|
344
472
|
}) as Negation;
|
|
@@ -357,21 +485,31 @@ export const multiply = ((
|
|
|
357
485
|
right: Input | R<Transform> | number | bigint | boolean,
|
|
358
486
|
) => {
|
|
359
487
|
if (left instanceof Transform) {
|
|
360
|
-
if (right instanceof Transform)
|
|
488
|
+
if (right instanceof Transform) {
|
|
489
|
+
return new Transform(left).combine(right);
|
|
490
|
+
}
|
|
361
491
|
if (right instanceof Vector2 && right.scalarType === 'f32') {
|
|
362
492
|
return left.transformPoint(right as R<Vector2f>);
|
|
363
493
|
}
|
|
364
|
-
throw new TypeError(
|
|
494
|
+
throw new TypeError(
|
|
495
|
+
'Transform multiplication requires Transform or Vector2f',
|
|
496
|
+
);
|
|
365
497
|
}
|
|
366
498
|
if (right instanceof Transform) {
|
|
367
|
-
throw new TypeError(
|
|
499
|
+
throw new TypeError(
|
|
500
|
+
'Transform must be the left multiplication operand',
|
|
501
|
+
);
|
|
368
502
|
}
|
|
369
503
|
if (left instanceof Color && right instanceof Color) {
|
|
370
504
|
return modulate(new Color(left), right);
|
|
371
505
|
}
|
|
372
|
-
const leftScalar =
|
|
506
|
+
const leftScalar =
|
|
507
|
+
typeof left === 'number' ||
|
|
508
|
+
typeof left === 'bigint' ||
|
|
373
509
|
typeof left === 'boolean';
|
|
374
|
-
const rightScalar =
|
|
510
|
+
const rightScalar =
|
|
511
|
+
typeof right === 'number' ||
|
|
512
|
+
typeof right === 'bigint' ||
|
|
375
513
|
typeof right === 'boolean';
|
|
376
514
|
if (leftScalar && !rightScalar) {
|
|
377
515
|
return scale(copy(right as Input), left, 'multiply');
|
|
@@ -380,7 +518,8 @@ export const multiply = ((
|
|
|
380
518
|
return scale(copy(left as Input), right, 'multiply');
|
|
381
519
|
}
|
|
382
520
|
throw new TypeError('Multiplication requires one value and one scalar');
|
|
383
|
-
}) as Scale &
|
|
521
|
+
}) as Scale &
|
|
522
|
+
LeftScale & {
|
|
384
523
|
(left: R<Transform>, right: R<Transform>): Transform;
|
|
385
524
|
(left: R<Transform>, right: R<Vector2f>): Vector2f;
|
|
386
525
|
(left: R<Color>, right: R<Color>): Color;
|
|
@@ -400,7 +539,9 @@ export const multiplyAssign = ((
|
|
|
400
539
|
) => {
|
|
401
540
|
if (left instanceof Transform) {
|
|
402
541
|
if (!(right instanceof Transform)) {
|
|
403
|
-
throw new TypeError(
|
|
542
|
+
throw new TypeError(
|
|
543
|
+
'Transform assignment requires another Transform',
|
|
544
|
+
);
|
|
404
545
|
}
|
|
405
546
|
return left.combine(right);
|
|
406
547
|
}
|
|
@@ -410,8 +551,11 @@ export const multiplyAssign = ((
|
|
|
410
551
|
if (left instanceof Color || right instanceof Color) {
|
|
411
552
|
return modulate(left, right as Input | number | bigint | boolean);
|
|
412
553
|
}
|
|
413
|
-
if (
|
|
414
|
-
|
|
554
|
+
if (
|
|
555
|
+
typeof right !== 'number' &&
|
|
556
|
+
typeof right !== 'bigint' &&
|
|
557
|
+
typeof right !== 'boolean'
|
|
558
|
+
) {
|
|
415
559
|
throw new TypeError('Expected a scalar');
|
|
416
560
|
}
|
|
417
561
|
return scale(left, right, 'multiply');
|
|
@@ -426,8 +570,10 @@ export const multiplyAssign = ((
|
|
|
426
570
|
* @ja 左の値をスカラーで直接除算して返す。除数がゼロなら RangeError をスローする。
|
|
427
571
|
* @ko 왼쪽 값을 스칼라로 제자리에서 나누고 반환한다. 제수가 0이면 RangeError를 던진다.
|
|
428
572
|
*/
|
|
429
|
-
export const divideAssign = ((
|
|
430
|
-
|
|
573
|
+
export const divideAssign = ((
|
|
574
|
+
left: Value,
|
|
575
|
+
right: number | bigint | boolean,
|
|
576
|
+
) => scale(left, right, 'divide')) as ScaleAssign;
|
|
431
577
|
|
|
432
578
|
/**
|
|
433
579
|
* Return a new object divided by a scalar; dividing two Time or two Angle
|
|
@@ -439,10 +585,14 @@ export const divideAssign = ((left: Value, right: number | bigint | boolean) =>
|
|
|
439
585
|
* 수치 비율을 반환한다.
|
|
440
586
|
*/
|
|
441
587
|
export const divide = ((
|
|
442
|
-
left: Input,
|
|
588
|
+
left: Input,
|
|
589
|
+
right: Input | number | bigint | boolean,
|
|
443
590
|
) => {
|
|
444
|
-
if (
|
|
445
|
-
|
|
591
|
+
if (
|
|
592
|
+
typeof right === 'number' ||
|
|
593
|
+
typeof right === 'bigint' ||
|
|
594
|
+
typeof right === 'boolean'
|
|
595
|
+
) {
|
|
446
596
|
return scale(copy(left), right, 'divide');
|
|
447
597
|
}
|
|
448
598
|
if (left instanceof Time || right instanceof Time) {
|
|
@@ -457,7 +607,9 @@ export const divide = ((
|
|
|
457
607
|
if (!(left instanceof Angle) || !(right instanceof Angle)) {
|
|
458
608
|
throw new TypeError('Only two angles can be divided to obtain a ratio');
|
|
459
609
|
}
|
|
460
|
-
if (right.asRadians() === 0)
|
|
610
|
+
if (right.asRadians() === 0) {
|
|
611
|
+
throw new RangeError('Cannot divide by zero');
|
|
612
|
+
}
|
|
461
613
|
return Math.fround(left.asRadians() / right.asRadians());
|
|
462
614
|
}) as Scale & {
|
|
463
615
|
(left: R<Time>, right: R<Time>): number;
|
|
@@ -480,7 +632,8 @@ export function modulo(left: R<Time>, right: R<Time>): Time;
|
|
|
480
632
|
*/
|
|
481
633
|
export function modulo(left: R<Angle>, right: R<Angle>): Angle;
|
|
482
634
|
export function modulo(
|
|
483
|
-
left: R<Time> | R<Angle>,
|
|
635
|
+
left: R<Time> | R<Angle>,
|
|
636
|
+
right: R<Time> | R<Angle>,
|
|
484
637
|
): Time | Angle {
|
|
485
638
|
checkPair(left, right);
|
|
486
639
|
if (left instanceof Time && right instanceof Time) {
|
|
@@ -510,7 +663,8 @@ export function moduloAssign(left: Time, right: R<Time>): Time;
|
|
|
510
663
|
*/
|
|
511
664
|
export function moduloAssign(left: Angle, right: R<Angle>): Angle;
|
|
512
665
|
export function moduloAssign(
|
|
513
|
-
left: Time | Angle,
|
|
666
|
+
left: Time | Angle,
|
|
667
|
+
right: R<Time> | R<Angle>,
|
|
514
668
|
): Time | Angle {
|
|
515
669
|
checkMutable(left);
|
|
516
670
|
checkPair(left, right);
|
|
@@ -522,13 +676,21 @@ export function moduloAssign(
|
|
|
522
676
|
throw new TypeError('Expected matching Time or Angle operands');
|
|
523
677
|
}
|
|
524
678
|
left[angleStorage][0] = positiveRemainder(
|
|
525
|
-
left.asRadians(),
|
|
679
|
+
left.asRadians(),
|
|
680
|
+
right.asRadians(),
|
|
526
681
|
);
|
|
527
682
|
return left;
|
|
528
683
|
}
|
|
529
684
|
|
|
530
|
-
type EqualityInput =
|
|
531
|
-
|
|
685
|
+
type EqualityInput =
|
|
686
|
+
| Input
|
|
687
|
+
| R<FloatRect>
|
|
688
|
+
| R<IntRect>
|
|
689
|
+
| R<Transform>
|
|
690
|
+
| Readonly<BlendMode>
|
|
691
|
+
| Readonly<StencilMode>
|
|
692
|
+
| Readonly<VideoMode>
|
|
693
|
+
| IpAddress;
|
|
532
694
|
const transformElements = [ 0, 1, 3, 4, 5, 7, 12, 13, 15 ];
|
|
533
695
|
|
|
534
696
|
function equals(left: EqualityInput, right: EqualityInput): boolean {
|
|
@@ -545,22 +707,28 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
|
|
|
545
707
|
if (!(left instanceof BlendMode) || !(right instanceof BlendMode)) {
|
|
546
708
|
throw new TypeError('BlendMode equality requires two blend modes');
|
|
547
709
|
}
|
|
548
|
-
return
|
|
710
|
+
return (
|
|
711
|
+
left.colorSrcFactor === right.colorSrcFactor &&
|
|
549
712
|
left.colorDstFactor === right.colorDstFactor &&
|
|
550
713
|
left.colorEquation === right.colorEquation &&
|
|
551
714
|
left.alphaSrcFactor === right.alphaSrcFactor &&
|
|
552
715
|
left.alphaDstFactor === right.alphaDstFactor &&
|
|
553
|
-
left.alphaEquation === right.alphaEquation
|
|
716
|
+
left.alphaEquation === right.alphaEquation
|
|
717
|
+
);
|
|
554
718
|
}
|
|
555
719
|
if (left instanceof StencilMode || right instanceof StencilMode) {
|
|
556
720
|
if (!(left instanceof StencilMode) || !(right instanceof StencilMode)) {
|
|
557
|
-
throw new TypeError(
|
|
721
|
+
throw new TypeError(
|
|
722
|
+
'StencilMode equality requires two stencil modes',
|
|
723
|
+
);
|
|
558
724
|
}
|
|
559
|
-
return
|
|
725
|
+
return (
|
|
726
|
+
left.stencilComparison === right.stencilComparison &&
|
|
560
727
|
left.stencilUpdateOperation === right.stencilUpdateOperation &&
|
|
561
728
|
left.stencilReference.value === right.stencilReference.value &&
|
|
562
729
|
left.stencilMask.value === right.stencilMask.value &&
|
|
563
|
-
left.stencilOnly === right.stencilOnly
|
|
730
|
+
left.stencilOnly === right.stencilOnly
|
|
731
|
+
);
|
|
564
732
|
}
|
|
565
733
|
if (left instanceof Transform || right instanceof Transform) {
|
|
566
734
|
if (!(left instanceof Transform) || !(right instanceof Transform)) {
|
|
@@ -571,14 +739,16 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
|
|
|
571
739
|
return transformElements.every(index => a[index] === b[index]);
|
|
572
740
|
}
|
|
573
741
|
if (left instanceof Rect || right instanceof Rect) {
|
|
574
|
-
if (
|
|
575
|
-
|
|
742
|
+
if (
|
|
743
|
+
!(left instanceof Rect) ||
|
|
744
|
+
!(right instanceof Rect) ||
|
|
745
|
+
left.scalarType !== right.scalarType
|
|
746
|
+
) {
|
|
576
747
|
throw new TypeError('Rect operands must have the same scalar type');
|
|
577
748
|
}
|
|
578
749
|
const a = left[rectStorage];
|
|
579
750
|
const b = right[rectStorage];
|
|
580
|
-
return a[0] === b[0] && a[1] === b[1] &&
|
|
581
|
-
a[2] === b[2] && a[3] === b[3];
|
|
751
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
582
752
|
}
|
|
583
753
|
checkPair(left as Input, right as Input);
|
|
584
754
|
if (left instanceof Time && right instanceof Time) {
|
|
@@ -587,7 +757,9 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
|
|
|
587
757
|
const a = storage(left as Input);
|
|
588
758
|
const b = storage(right as Input);
|
|
589
759
|
for (let index = 0; index < a.length; index++) {
|
|
590
|
-
if (a[index] !== b[index])
|
|
760
|
+
if (a[index] !== b[index]) {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
591
763
|
}
|
|
592
764
|
return true;
|
|
593
765
|
}
|
|
@@ -629,7 +801,10 @@ function compare(
|
|
|
629
801
|
return operation(left.compare(right), 0);
|
|
630
802
|
}
|
|
631
803
|
if (left instanceof VideoMode || right instanceof VideoMode) {
|
|
632
|
-
return operation(
|
|
804
|
+
return operation(
|
|
805
|
+
compareVideoModes(left as VideoMode, right as VideoMode),
|
|
806
|
+
0,
|
|
807
|
+
);
|
|
633
808
|
}
|
|
634
809
|
if (left instanceof Time && right instanceof Time) {
|
|
635
810
|
return operation(left.asMicroseconds(), right.asMicroseconds());
|
package/src/system/sleep.ts
CHANGED
|
@@ -11,9 +11,13 @@ const maximumDelay = 2147483647n;
|
|
|
11
11
|
* @ko 비동기 대기. 호출 스레드는 계속 이벤트 루프에서 사용할 수 있다.
|
|
12
12
|
*/
|
|
13
13
|
export async function sleep(duration: ReadonlyValue<Time>): Promise<void> {
|
|
14
|
-
if (!(duration instanceof Time))
|
|
14
|
+
if (!(duration instanceof Time)) {
|
|
15
|
+
throw new TypeError('Expected a Time');
|
|
16
|
+
}
|
|
15
17
|
const microseconds = duration.asMicroseconds();
|
|
16
|
-
if (microseconds <= 0n)
|
|
18
|
+
if (microseconds <= 0n) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
17
21
|
// Round positive fractions up to a millisecond. Snapshot before the await.
|
|
18
22
|
let remaining = (microseconds + 999n) / 1000n;
|
|
19
23
|
while (remaining > 0n) {
|