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
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { native, type NativeValueHandle } from '../internal/native';
|
|
2
2
|
import { LazyValue, nativeValue } from '../internal/lazy-value';
|
|
3
3
|
import {
|
|
4
|
-
transformStorage,
|
|
4
|
+
transformStorage,
|
|
5
|
+
transformNative,
|
|
6
|
+
rectStorage,
|
|
7
|
+
mutableValue,
|
|
5
8
|
type ReadonlyValue as R,
|
|
6
9
|
} from '../internal/value-storage';
|
|
7
10
|
import { Vector2, Vector2f } from '../system/vector2';
|
|
@@ -9,18 +12,29 @@ import { Angle } from '../system/angle';
|
|
|
9
12
|
import { Rect, FloatRect } from './rect';
|
|
10
13
|
|
|
11
14
|
type Components = [
|
|
12
|
-
a00: number,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
a00: number,
|
|
16
|
+
a01: number,
|
|
17
|
+
a02: number,
|
|
18
|
+
a10: number,
|
|
19
|
+
a11: number,
|
|
20
|
+
a12: number,
|
|
21
|
+
a20: number,
|
|
22
|
+
a21: number,
|
|
23
|
+
a22: number,
|
|
15
24
|
];
|
|
16
|
-
type Arguments = [] | [
|
|
25
|
+
type Arguments = [] | [source: R<Transform>] | Components;
|
|
17
26
|
type State = LazyValue<'transform', Float32Array> & {
|
|
18
27
|
matrix?: readonly number[];
|
|
19
28
|
};
|
|
20
29
|
const f = Math.fround;
|
|
21
30
|
|
|
22
31
|
function dot3(
|
|
23
|
-
a: number,
|
|
32
|
+
a: number,
|
|
33
|
+
b: number,
|
|
34
|
+
c: number,
|
|
35
|
+
d: number,
|
|
36
|
+
e: number,
|
|
37
|
+
g: number,
|
|
24
38
|
): number {
|
|
25
39
|
return f(f(f(a * b) + f(c * d)) + f(e * g));
|
|
26
40
|
}
|
|
@@ -30,7 +44,11 @@ function minor(a: number, b: number, c: number, d: number): number {
|
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
function pointCoordinate(
|
|
33
|
-
a: number,
|
|
47
|
+
a: number,
|
|
48
|
+
x: number,
|
|
49
|
+
b: number,
|
|
50
|
+
y: number,
|
|
51
|
+
offset: number,
|
|
34
52
|
): number {
|
|
35
53
|
return f(f(f(a * x) + f(b * y)) + offset);
|
|
36
54
|
}
|
|
@@ -46,7 +64,8 @@ function matrixView(values: Float32Array): readonly number[] {
|
|
|
46
64
|
const view = new Array<number>(16);
|
|
47
65
|
for (let i = 0; i < 16; i++) {
|
|
48
66
|
Object.defineProperty(view, i, {
|
|
49
|
-
enumerable: true,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: () => values[i],
|
|
50
69
|
});
|
|
51
70
|
}
|
|
52
71
|
return Object.freeze(view);
|
|
@@ -68,7 +87,8 @@ export class Transform {
|
|
|
68
87
|
* @ko 변환 행렬의 지연 네이티브 래퍼 및 선택적 행렬 뷰 캐시입니다.
|
|
69
88
|
*/
|
|
70
89
|
private readonly state: State = new LazyValue(
|
|
71
|
-
new Float32Array(16),
|
|
90
|
+
new Float32Array(16),
|
|
91
|
+
buffer => native.wrapTransform(buffer),
|
|
72
92
|
);
|
|
73
93
|
|
|
74
94
|
/**
|
|
@@ -84,11 +104,15 @@ export class Transform {
|
|
|
84
104
|
values[0] = values[5] = values[10] = values[15] = 1;
|
|
85
105
|
} else if (args.length === 1 && args[0] instanceof Transform) {
|
|
86
106
|
values.set(args[0][transformStorage]);
|
|
87
|
-
} else if (
|
|
88
|
-
|
|
107
|
+
} else if (
|
|
108
|
+
args.length === 9 &&
|
|
109
|
+
args.every(value => typeof value === 'number')
|
|
110
|
+
) {
|
|
89
111
|
this.assign(...args);
|
|
90
112
|
} else {
|
|
91
|
-
throw new TypeError(
|
|
113
|
+
throw new TypeError(
|
|
114
|
+
'Transform requires zero, one Transform or 9 numbers',
|
|
115
|
+
);
|
|
92
116
|
}
|
|
93
117
|
}
|
|
94
118
|
|
|
@@ -125,9 +149,13 @@ export class Transform {
|
|
|
125
149
|
const q = minor(a[15], a[4], a[7], a[12]);
|
|
126
150
|
const r = minor(a[13], a[4], a[5], a[12]);
|
|
127
151
|
const determinant = f(f(f(a[0] * p) - f(a[1] * q)) + f(a[3] * r));
|
|
128
|
-
if (determinant === 0)
|
|
152
|
+
if (determinant === 0) {
|
|
153
|
+
return new Transform();
|
|
154
|
+
}
|
|
129
155
|
return new Transform(
|
|
130
|
-
p / determinant,
|
|
156
|
+
p / determinant,
|
|
157
|
+
-q / determinant,
|
|
158
|
+
r / determinant,
|
|
131
159
|
-minor(a[15], a[1], a[3], a[13]) / determinant,
|
|
132
160
|
minor(a[15], a[0], a[3], a[12]) / determinant,
|
|
133
161
|
-minor(a[13], a[0], a[1], a[12]) / determinant,
|
|
@@ -177,10 +205,16 @@ export class Transform {
|
|
|
177
205
|
const x = pointCoordinate(a[0], px, a[4], py, a[12]);
|
|
178
206
|
const y = pointCoordinate(a[1], px, a[5], py, a[13]);
|
|
179
207
|
// Ordered comparisons preserve SFML's NaN and signed-zero behavior.
|
|
180
|
-
if (x < minX)
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
|
|
208
|
+
if (x < minX) {
|
|
209
|
+
minX = x;
|
|
210
|
+
} else if (x > maxX) {
|
|
211
|
+
maxX = x;
|
|
212
|
+
}
|
|
213
|
+
if (y < minY) {
|
|
214
|
+
minY = y;
|
|
215
|
+
} else if (y > maxY) {
|
|
216
|
+
maxY = y;
|
|
217
|
+
}
|
|
184
218
|
}
|
|
185
219
|
const result = new FloatRect();
|
|
186
220
|
const values = result[rectStorage];
|
|
@@ -205,7 +239,15 @@ export class Transform {
|
|
|
205
239
|
}
|
|
206
240
|
const b = transform[transformStorage];
|
|
207
241
|
return this.combineMatrix(
|
|
208
|
-
b[0],
|
|
242
|
+
b[0],
|
|
243
|
+
b[4],
|
|
244
|
+
b[12],
|
|
245
|
+
b[1],
|
|
246
|
+
b[5],
|
|
247
|
+
b[13],
|
|
248
|
+
b[3],
|
|
249
|
+
b[7],
|
|
250
|
+
b[15],
|
|
209
251
|
) as this;
|
|
210
252
|
}
|
|
211
253
|
|
|
@@ -218,7 +260,15 @@ export class Transform {
|
|
|
218
260
|
translate(this: Transform, offset: R<Vector2f>): this {
|
|
219
261
|
requireVector(offset);
|
|
220
262
|
return this.combineMatrix(
|
|
221
|
-
1,
|
|
263
|
+
1,
|
|
264
|
+
0,
|
|
265
|
+
offset.x,
|
|
266
|
+
0,
|
|
267
|
+
1,
|
|
268
|
+
offset.y,
|
|
269
|
+
0,
|
|
270
|
+
0,
|
|
271
|
+
1,
|
|
222
272
|
) as this;
|
|
223
273
|
}
|
|
224
274
|
|
|
@@ -229,15 +279,21 @@ export class Transform {
|
|
|
229
279
|
* @ja center(既定は原点)を中心とした拡大縮小行列をその場で右から乗算し、this を返します。
|
|
230
280
|
* @ko center(기본값은 원점)를 중심으로 하는 크기 조절 행렬을 제자리에서 오른쪽에 곱하고 this를 반환합니다.
|
|
231
281
|
*/
|
|
232
|
-
scale(
|
|
233
|
-
this: Transform, factors: R<Vector2f>, center?: R<Vector2f>,
|
|
234
|
-
): this {
|
|
282
|
+
scale(this: Transform, factors: R<Vector2f>, center?: R<Vector2f>): this {
|
|
235
283
|
requireVector(factors);
|
|
236
|
-
if (center !== undefined)
|
|
284
|
+
if (center !== undefined) {
|
|
285
|
+
requireVector(center);
|
|
286
|
+
}
|
|
237
287
|
return this.combineMatrix(
|
|
238
|
-
factors.x,
|
|
239
|
-
0,
|
|
240
|
-
|
|
288
|
+
factors.x,
|
|
289
|
+
0,
|
|
290
|
+
center === undefined ? 0 : f(center.x * f(1 - factors.x)),
|
|
291
|
+
0,
|
|
292
|
+
factors.y,
|
|
293
|
+
center === undefined ? 0 : f(center.y * f(1 - factors.y)),
|
|
294
|
+
0,
|
|
295
|
+
0,
|
|
296
|
+
1,
|
|
241
297
|
) as this;
|
|
242
298
|
}
|
|
243
299
|
|
|
@@ -248,17 +304,23 @@ export class Transform {
|
|
|
248
304
|
* @ja center(既定は原点)を中心とした回転行列をその場で右から乗算し、this を返します。
|
|
249
305
|
* @ko center(기본값은 원점)를 중심으로 하는 회전 행렬을 제자리에서 오른쪽에 곱하고 this를 반환합니다.
|
|
250
306
|
*/
|
|
251
|
-
rotate(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (center !== undefined)
|
|
307
|
+
rotate(this: Transform, angle: R<Angle>, center?: R<Vector2f>): this {
|
|
308
|
+
if (!(angle instanceof Angle)) {
|
|
309
|
+
throw new TypeError('Expected an Angle');
|
|
310
|
+
}
|
|
311
|
+
if (center !== undefined) {
|
|
312
|
+
requireVector(center);
|
|
313
|
+
}
|
|
256
314
|
const cos = f(Math.cos(angle.asRadians()));
|
|
257
315
|
const sin = f(Math.sin(angle.asRadians()));
|
|
258
|
-
const tx =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
316
|
+
const tx =
|
|
317
|
+
center === undefined
|
|
318
|
+
? 0
|
|
319
|
+
: f(f(center.x * f(1 - cos)) + f(center.y * sin));
|
|
320
|
+
const ty =
|
|
321
|
+
center === undefined
|
|
322
|
+
? 0
|
|
323
|
+
: f(f(center.y * f(1 - cos)) - f(center.x * sin));
|
|
262
324
|
return this.combineMatrix(cos, -sin, tx, sin, cos, ty, 0, 0, 1) as this;
|
|
263
325
|
}
|
|
264
326
|
|
|
@@ -269,9 +331,15 @@ export class Transform {
|
|
|
269
331
|
* @ko 열 우선 저장 공간에 3×3 행렬을 제자리에서 오른쪽에 곱합니다.
|
|
270
332
|
*/
|
|
271
333
|
private combineMatrix(
|
|
272
|
-
b00: number,
|
|
273
|
-
|
|
274
|
-
|
|
334
|
+
b00: number,
|
|
335
|
+
b01: number,
|
|
336
|
+
b02: number,
|
|
337
|
+
b10: number,
|
|
338
|
+
b11: number,
|
|
339
|
+
b12: number,
|
|
340
|
+
b20: number,
|
|
341
|
+
b21: number,
|
|
342
|
+
b22: number,
|
|
275
343
|
): this {
|
|
276
344
|
if (Object.isFrozen(this)) {
|
|
277
345
|
throw new TypeError('Cannot modify a constant Transform');
|
|
@@ -298,16 +366,33 @@ export class Transform {
|
|
|
298
366
|
* @ko 행 순서의 성분 9개를 열 우선 저장 공간에 씁니다.
|
|
299
367
|
*/
|
|
300
368
|
private assign(
|
|
301
|
-
a00: number,
|
|
302
|
-
|
|
303
|
-
|
|
369
|
+
a00: number,
|
|
370
|
+
a01: number,
|
|
371
|
+
a02: number,
|
|
372
|
+
a10: number,
|
|
373
|
+
a11: number,
|
|
374
|
+
a12: number,
|
|
375
|
+
a20: number,
|
|
376
|
+
a21: number,
|
|
377
|
+
a22: number,
|
|
304
378
|
): void {
|
|
305
379
|
const values = this.state.values;
|
|
306
|
-
values[0] = a00;
|
|
307
|
-
values[
|
|
308
|
-
values[
|
|
309
|
-
values[
|
|
310
|
-
|
|
380
|
+
values[0] = a00;
|
|
381
|
+
values[4] = a01;
|
|
382
|
+
values[12] = a02;
|
|
383
|
+
values[1] = a10;
|
|
384
|
+
values[5] = a11;
|
|
385
|
+
values[13] = a12;
|
|
386
|
+
values[3] = a20;
|
|
387
|
+
values[7] = a21;
|
|
388
|
+
values[15] = a22;
|
|
389
|
+
values[2] =
|
|
390
|
+
values[6] =
|
|
391
|
+
values[8] =
|
|
392
|
+
values[9] =
|
|
393
|
+
values[11] =
|
|
394
|
+
values[14] =
|
|
395
|
+
0;
|
|
311
396
|
values[10] = 1;
|
|
312
397
|
}
|
|
313
398
|
|
|
@@ -23,7 +23,9 @@ class TransformableResource {
|
|
|
23
23
|
}
|
|
24
24
|
const { handle, buffer } = native.createTransformable();
|
|
25
25
|
const values = new Float32Array(buffer);
|
|
26
|
-
if (source)
|
|
26
|
+
if (source) {
|
|
27
|
+
values.set(source[transformableState].values);
|
|
28
|
+
}
|
|
27
29
|
this[transformableState] = { handle, values };
|
|
28
30
|
}
|
|
29
31
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
native,
|
|
3
|
+
type NativeGraphicsHandle,
|
|
4
|
+
type NativeVertices,
|
|
5
|
+
} from '../internal/native';
|
|
2
6
|
import { LazyValue } from '../internal/lazy-value';
|
|
3
7
|
import {
|
|
4
|
-
dispatchDrawable,
|
|
8
|
+
dispatchDrawable,
|
|
9
|
+
recordVertices,
|
|
10
|
+
vertexArrayBytes,
|
|
5
11
|
} from '../internal/graphics-state';
|
|
6
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
vertexStorage,
|
|
14
|
+
type ReadonlyValue,
|
|
15
|
+
} from '../internal/value-storage';
|
|
7
16
|
import { Vector2f } from '../system/vector2';
|
|
8
17
|
import { Drawable } from './drawable';
|
|
9
18
|
import { FloatRect } from './rect';
|
|
@@ -37,13 +46,14 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
37
46
|
private readonly views = new Map<number, Vertex>();
|
|
38
47
|
|
|
39
48
|
static {
|
|
40
|
-
vertexArrayFromMapping = mapping =>
|
|
41
|
-
Object.create(VertexArray.prototype), {
|
|
49
|
+
vertexArrayFromMapping = mapping =>
|
|
50
|
+
Object.assign(Object.create(VertexArray.prototype), {
|
|
42
51
|
handle: mapping.handle,
|
|
43
52
|
bytes: new Uint8Array(mapping.buffer),
|
|
44
53
|
coordinates: new Float32Array(mapping.buffer),
|
|
45
54
|
metadata: new Uint32Array([
|
|
46
|
-
mapping.buffer.byteLength / 20,
|
|
55
|
+
mapping.buffer.byteLength / 20,
|
|
56
|
+
PrimitiveType.Triangles,
|
|
47
57
|
]),
|
|
48
58
|
views: new Map<number, Vertex>(),
|
|
49
59
|
});
|
|
@@ -64,11 +74,13 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
64
74
|
* @ko 꼭짓점 데이터와 프리미티브 형식을 깊은 복사합니다.
|
|
65
75
|
*/
|
|
66
76
|
constructor(source: VertexArray);
|
|
67
|
-
constructor(
|
|
68
|
-
|
|
77
|
+
constructor(
|
|
78
|
+
source: PrimitiveType | VertexArray = PrimitiveType.Points,
|
|
79
|
+
vertexCount = 0,
|
|
80
|
+
) {
|
|
69
81
|
super();
|
|
70
82
|
const copy = source instanceof VertexArray ? source : undefined;
|
|
71
|
-
const type = copy ? copy.primitiveType : source as PrimitiveType;
|
|
83
|
+
const type = copy ? copy.primitiveType : (source as PrimitiveType);
|
|
72
84
|
const count = copy ? copy.count : vertexCount;
|
|
73
85
|
validatePrimitiveType(type);
|
|
74
86
|
validateCount(count);
|
|
@@ -78,7 +90,9 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
78
90
|
this.coordinates = new Float32Array(mapping.buffer);
|
|
79
91
|
this.count = count;
|
|
80
92
|
this.primitiveType = type;
|
|
81
|
-
if (copy)
|
|
93
|
+
if (copy) {
|
|
94
|
+
this.bytes.set(copy.bytes.subarray(0, count * 20));
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
|
|
84
98
|
/**
|
|
@@ -91,10 +105,18 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
91
105
|
return this.count;
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
private get count(): number {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
private set
|
|
108
|
+
private get count(): number {
|
|
109
|
+
return this.metadata[0];
|
|
110
|
+
}
|
|
111
|
+
private set count(value: number) {
|
|
112
|
+
this.metadata[0] = value;
|
|
113
|
+
}
|
|
114
|
+
private get primitiveType(): PrimitiveType {
|
|
115
|
+
return this.metadata[1];
|
|
116
|
+
}
|
|
117
|
+
private set primitiveType(value: PrimitiveType) {
|
|
118
|
+
this.metadata[1] = value;
|
|
119
|
+
}
|
|
98
120
|
|
|
99
121
|
get [vertexArrayBytes](): Uint8Array {
|
|
100
122
|
return this.bytes.subarray(0, this.count * 20);
|
|
@@ -115,10 +137,12 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
115
137
|
let vertex = this.views.get(index);
|
|
116
138
|
if (!vertex) {
|
|
117
139
|
const handle = this.handle;
|
|
118
|
-
vertex = vertexFromState(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
vertex = vertexFromState(
|
|
141
|
+
new LazyValue(
|
|
142
|
+
this.bytes.subarray(index * 20, (index + 1) * 20),
|
|
143
|
+
() => native.vertexStorageMember(handle, index),
|
|
144
|
+
),
|
|
145
|
+
);
|
|
122
146
|
this.views.set(index, vertex);
|
|
123
147
|
}
|
|
124
148
|
return vertex;
|
|
@@ -132,7 +156,9 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
132
156
|
*/
|
|
133
157
|
setVertex(index: number, value: ReadonlyValue<Vertex>): void {
|
|
134
158
|
this.checkIndex(index);
|
|
135
|
-
if (!(value instanceof Vertex))
|
|
159
|
+
if (!(value instanceof Vertex)) {
|
|
160
|
+
throw new TypeError('Expected a Vertex');
|
|
161
|
+
}
|
|
136
162
|
this.bytes.set(value[vertexStorage], index * 20);
|
|
137
163
|
}
|
|
138
164
|
|
|
@@ -162,7 +188,9 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
162
188
|
}
|
|
163
189
|
if (vertexCount < this.count) {
|
|
164
190
|
for (const index of this.views.keys()) {
|
|
165
|
-
if (index >= vertexCount)
|
|
191
|
+
if (index >= vertexCount) {
|
|
192
|
+
this.views.delete(index);
|
|
193
|
+
}
|
|
166
194
|
}
|
|
167
195
|
}
|
|
168
196
|
this.count = vertexCount;
|
|
@@ -175,7 +203,9 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
175
203
|
* @ko 꼭짓점 복사본을 끝에 추가하며 용량이 부족하면 저장 공간을 재할당합니다.
|
|
176
204
|
*/
|
|
177
205
|
append(vertex: ReadonlyValue<Vertex>): void {
|
|
178
|
-
if (!(vertex instanceof Vertex))
|
|
206
|
+
if (!(vertex instanceof Vertex)) {
|
|
207
|
+
throw new TypeError('Expected a Vertex');
|
|
208
|
+
}
|
|
179
209
|
validateCount(this.count + 1);
|
|
180
210
|
this.ensureCapacity(this.count + 1);
|
|
181
211
|
this.bytes.set(vertex[vertexStorage], this.count * 20);
|
|
@@ -211,7 +241,9 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
211
241
|
* @ko 모든 꼭짓점 위치의 축 정렬 경계 상자를 반환합니다. 빈 배열은 0 사각형을 반환합니다.
|
|
212
242
|
*/
|
|
213
243
|
getBounds(): FloatRect {
|
|
214
|
-
if (this.count === 0)
|
|
244
|
+
if (this.count === 0) {
|
|
245
|
+
return new FloatRect();
|
|
246
|
+
}
|
|
215
247
|
const data = this.coordinates;
|
|
216
248
|
let left = data[0];
|
|
217
249
|
let top = data[1];
|
|
@@ -220,13 +252,21 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
220
252
|
for (let i = 1; i < this.count; i++) {
|
|
221
253
|
const x = data[i * 5];
|
|
222
254
|
const y = data[i * 5 + 1];
|
|
223
|
-
if (x < left)
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
255
|
+
if (x < left) {
|
|
256
|
+
left = x;
|
|
257
|
+
} else if (x > right) {
|
|
258
|
+
right = x;
|
|
259
|
+
}
|
|
260
|
+
if (y < top) {
|
|
261
|
+
top = y;
|
|
262
|
+
} else if (y > bottom) {
|
|
263
|
+
bottom = y;
|
|
264
|
+
}
|
|
227
265
|
}
|
|
228
266
|
return new FloatRect(
|
|
229
|
-
new Vector2f(left, top),
|
|
267
|
+
new Vector2f(left, top),
|
|
268
|
+
new Vector2f(right - left, bottom - top),
|
|
269
|
+
);
|
|
230
270
|
}
|
|
231
271
|
|
|
232
272
|
/**
|
|
@@ -236,17 +276,25 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
236
276
|
* @ko 인덱스 순서로 꼭짓점 공유 뷰를 순회합니다.
|
|
237
277
|
*/
|
|
238
278
|
* [Symbol.iterator](): IterableIterator<Vertex> {
|
|
239
|
-
for (let i = 0; i < this.count; i++)
|
|
279
|
+
for (let i = 0; i < this.count; i++) {
|
|
280
|
+
yield this.getVertex(i);
|
|
281
|
+
}
|
|
240
282
|
}
|
|
241
283
|
|
|
242
284
|
protected draw(target: RenderTarget, states: RenderStates): void {
|
|
243
|
-
target[recordVertices](
|
|
244
|
-
this.
|
|
285
|
+
target[recordVertices](
|
|
286
|
+
this.bytes.subarray(0, this.count * 20),
|
|
287
|
+
this.primitiveType,
|
|
288
|
+
states,
|
|
289
|
+
);
|
|
245
290
|
}
|
|
246
291
|
|
|
247
292
|
[dispatchDrawable](target: RenderTarget, states: RenderStates): void {
|
|
248
|
-
if (this.draw === VertexArray.prototype.draw)
|
|
249
|
-
|
|
293
|
+
if (this.draw === VertexArray.prototype.draw) {
|
|
294
|
+
this.draw(target, states);
|
|
295
|
+
} else {
|
|
296
|
+
super[dispatchDrawable](target, states);
|
|
297
|
+
}
|
|
250
298
|
}
|
|
251
299
|
|
|
252
300
|
private checkIndex(index: number): void {
|
|
@@ -256,9 +304,13 @@ export class VertexArray extends Drawable implements Iterable<Vertex> {
|
|
|
256
304
|
}
|
|
257
305
|
|
|
258
306
|
private ensureCapacity(count: number): void {
|
|
259
|
-
if (count <= this.bytes.byteLength / 20)
|
|
260
|
-
|
|
261
|
-
|
|
307
|
+
if (count <= this.bytes.byteLength / 20) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const capacity = Math.min(
|
|
311
|
+
maxVertices,
|
|
312
|
+
Math.max(count, 4, this.bytes.byteLength / 10),
|
|
313
|
+
);
|
|
262
314
|
const mapping = native.createVertexStorage(capacity);
|
|
263
315
|
const bytes = new Uint8Array(mapping.buffer);
|
|
264
316
|
bytes.set(this.bytes.subarray(0, this.count * 20));
|