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
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Socket as UdpHandle, type RemoteInfo } from 'node:dgram';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
Socket,
|
|
4
|
+
SocketStatus as Status,
|
|
5
|
+
socketEvents,
|
|
6
|
+
SocketType,
|
|
7
|
+
type SocketHandle,
|
|
8
|
+
} from './socket';
|
|
4
9
|
import { IpAddress } from './ip-address';
|
|
5
10
|
import { Packet, packetReceive, packetSend } from './packet';
|
|
6
11
|
import { SerialQueue, bytes, uint, waitFor } from './common';
|
|
@@ -86,7 +91,9 @@ export class UdpSocket extends Socket {
|
|
|
86
91
|
* @ko 바인딩되지 않은 UDP 소켓을 생성하며 기본적으로 비동기 블로킹 동작을
|
|
87
92
|
* 사용합니다.
|
|
88
93
|
*/
|
|
89
|
-
constructor() {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(SocketType.Udp);
|
|
96
|
+
}
|
|
90
97
|
/**
|
|
91
98
|
* Return the bound local port, or 0 when unbound.
|
|
92
99
|
* @zh 返回已绑定的本地端口,未绑定时为 0。
|
|
@@ -105,18 +112,28 @@ export class UdpSocket extends Socket {
|
|
|
105
112
|
* @ko 로컬 포트와 주소를 비동기로 바인딩합니다. port가 0이면 시스템이
|
|
106
113
|
* 할당하며 기본적으로 IPv4를 사용합니다.
|
|
107
114
|
*/
|
|
108
|
-
async bind(
|
|
115
|
+
async bind(
|
|
116
|
+
port: number,
|
|
117
|
+
address: IpAddress = IpAddress.Any,
|
|
118
|
+
): Promise<Status> {
|
|
109
119
|
uint(port, 65535);
|
|
110
|
-
if (!(address instanceof IpAddress))
|
|
120
|
+
if (!(address instanceof IpAddress)) {
|
|
121
|
+
throw new TypeError('Expected IpAddress');
|
|
122
|
+
}
|
|
111
123
|
this.create(address.getType());
|
|
112
124
|
const socket = this.transport!;
|
|
113
125
|
const generation = this.epoch;
|
|
114
|
-
const ready = waitFor(
|
|
115
|
-
|
|
126
|
+
const ready = waitFor(
|
|
127
|
+
this[socketEvents],
|
|
128
|
+
() => this.bound || !!this.failure || this.epoch !== generation,
|
|
129
|
+
);
|
|
116
130
|
socket.bind(port, address.toString());
|
|
117
131
|
await ready;
|
|
118
|
-
return this.epoch !== generation
|
|
119
|
-
|
|
132
|
+
return this.epoch !== generation
|
|
133
|
+
? Status.Disconnected
|
|
134
|
+
: this.bound
|
|
135
|
+
? Status.Done
|
|
136
|
+
: Status.Error;
|
|
120
137
|
}
|
|
121
138
|
/**
|
|
122
139
|
* Reject non-UDP Node transports before adoption.
|
|
@@ -125,7 +142,9 @@ export class UdpSocket extends Socket {
|
|
|
125
142
|
* @ko 인수 전에 UDP가 아닌 Node 전송 객체를 거부합니다.
|
|
126
143
|
*/
|
|
127
144
|
protected validateHandle(handle: SocketHandle): void {
|
|
128
|
-
if (!(handle instanceof UdpHandle))
|
|
145
|
+
if (!(handle instanceof UdpHandle)) {
|
|
146
|
+
throw new TypeError('Expected Node UDP');
|
|
147
|
+
}
|
|
129
148
|
}
|
|
130
149
|
/**
|
|
131
150
|
* Integrate an allocated or adopted UDP handle into the same datagram queue
|
|
@@ -142,41 +161,63 @@ export class UdpSocket extends Socket {
|
|
|
142
161
|
// Node 运行时保存创建地址族,但当前 @types/node 未声明此字段。
|
|
143
162
|
const { type } = socket as UdpHandle & { type: 'udp4' | 'udp6' };
|
|
144
163
|
this.family = type === 'udp4' ? 4 : 6;
|
|
145
|
-
const current = () =>
|
|
164
|
+
const current = () =>
|
|
165
|
+
this.transport === socket && this.epoch === generation;
|
|
146
166
|
const error = (error: Error) => {
|
|
147
|
-
if (!current())
|
|
148
|
-
|
|
167
|
+
if (!current()) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.failure = error;
|
|
171
|
+
this.changed();
|
|
149
172
|
};
|
|
150
173
|
const message = (data: Buffer, peer: RemoteInfo) => {
|
|
151
|
-
if (!current())
|
|
152
|
-
|
|
153
|
-
|
|
174
|
+
if (!current()) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
this.pendingBytes + data.length <= 8 * 1024 * 1024 &&
|
|
179
|
+
this.pending.length < 4096
|
|
180
|
+
) {
|
|
154
181
|
this.pending.push({ data, peer });
|
|
155
182
|
this.pendingBytes += data.length;
|
|
156
183
|
this.changed();
|
|
157
184
|
}
|
|
158
185
|
};
|
|
159
186
|
const listening = () => {
|
|
160
|
-
if (!current())
|
|
187
|
+
if (!current()) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
161
190
|
this.bound = true;
|
|
162
|
-
if (this.family === 4)
|
|
191
|
+
if (this.family === 4) {
|
|
192
|
+
socket.setBroadcast(true);
|
|
193
|
+
}
|
|
163
194
|
this.changed();
|
|
164
195
|
};
|
|
165
196
|
const closed = () => {
|
|
166
|
-
if (!current())
|
|
167
|
-
|
|
197
|
+
if (!current()) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
this.bound = false;
|
|
201
|
+
this.changed();
|
|
168
202
|
};
|
|
169
|
-
socket
|
|
203
|
+
socket
|
|
204
|
+
.on('error', error)
|
|
170
205
|
.on('message', message)
|
|
171
206
|
.on('listening', listening)
|
|
172
207
|
.on('close', closed);
|
|
173
208
|
this.detach = () => {
|
|
174
|
-
socket
|
|
209
|
+
socket
|
|
210
|
+
.off('error', error)
|
|
175
211
|
.off('message', message)
|
|
176
212
|
.off('listening', listening)
|
|
177
213
|
.off('close', closed);
|
|
178
214
|
};
|
|
179
|
-
try {
|
|
215
|
+
try {
|
|
216
|
+
socket.address();
|
|
217
|
+
listening();
|
|
218
|
+
} catch {
|
|
219
|
+
this.bound = false;
|
|
220
|
+
}
|
|
180
221
|
}
|
|
181
222
|
/**
|
|
182
223
|
* Close the UDP transport and clear datagrams pending receipt.
|
|
@@ -184,7 +225,9 @@ export class UdpSocket extends Socket {
|
|
|
184
225
|
* @ja UDP トランスポートを閉じ、受信待ちのデータグラムを消去します。
|
|
185
226
|
* @ko UDP 전송 객체를 닫고 수신 대기 중인 데이터그램을 비웁니다.
|
|
186
227
|
*/
|
|
187
|
-
unbind(): void {
|
|
228
|
+
unbind(): void {
|
|
229
|
+
this.close();
|
|
230
|
+
}
|
|
188
231
|
/**
|
|
189
232
|
* Clear the old transport's binding state and datagrams;
|
|
190
233
|
* the generation change cancels old reads.
|
|
@@ -208,37 +251,66 @@ export class UdpSocket extends Socket {
|
|
|
208
251
|
* @ko 호출 시점의 데이터 스냅샷을 하나의 데이터그램으로 송신합니다.
|
|
209
252
|
* 바인딩되지 않았으면 대상 주소 계열에 맞는 임시 포트에 자동 바인딩합니다.
|
|
210
253
|
*/
|
|
211
|
-
send(
|
|
212
|
-
|
|
254
|
+
send(
|
|
255
|
+
data: Uint8Array | Packet,
|
|
256
|
+
address: IpAddress,
|
|
257
|
+
port: number,
|
|
258
|
+
): Promise<Status> {
|
|
213
259
|
uint(port, 65535);
|
|
214
|
-
if (!(address instanceof IpAddress))
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
260
|
+
if (!(address instanceof IpAddress)) {
|
|
261
|
+
throw new TypeError('Expected IpAddress');
|
|
262
|
+
}
|
|
263
|
+
const input = Buffer.from(
|
|
264
|
+
data instanceof Packet ? data[packetSend]() : bytes(data),
|
|
265
|
+
);
|
|
266
|
+
if (input.length > UdpSocket.MaxDatagramSize) {
|
|
267
|
+
return Promise.resolve(Status.Error);
|
|
268
|
+
}
|
|
269
|
+
if (!this.transport) {
|
|
270
|
+
this.create(address.getType());
|
|
271
|
+
}
|
|
218
272
|
const generation = this.epoch;
|
|
219
|
-
return this.writes.run(() =>
|
|
273
|
+
return this.writes.run(() =>
|
|
274
|
+
this.sendBytes(input, address, port, generation),
|
|
275
|
+
);
|
|
220
276
|
}
|
|
221
277
|
/** 发送字节数据报,未绑定时自动绑定。 */
|
|
222
|
-
private async sendBytes(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
278
|
+
private async sendBytes(
|
|
279
|
+
input: Buffer,
|
|
280
|
+
address: IpAddress,
|
|
281
|
+
port: number,
|
|
282
|
+
generation: number,
|
|
283
|
+
): Promise<Status> {
|
|
284
|
+
if (generation !== this.epoch) {
|
|
285
|
+
return Status.Disconnected;
|
|
286
|
+
}
|
|
287
|
+
if (this.family !== (address.isV4() ? 4 : 6)) {
|
|
288
|
+
return Status.Error;
|
|
289
|
+
}
|
|
226
290
|
const socket = this.transport!;
|
|
227
291
|
let onError!: (error: Error) => void;
|
|
228
292
|
const completion = new Promise<Status>(resolve => {
|
|
229
293
|
const done = (error?: Error | null) => {
|
|
230
|
-
if (generation !== this.epoch)
|
|
231
|
-
|
|
294
|
+
if (generation !== this.epoch) {
|
|
295
|
+
return resolve(Status.Disconnected);
|
|
296
|
+
}
|
|
297
|
+
if (error) {
|
|
298
|
+
this.failure = error;
|
|
299
|
+
}
|
|
232
300
|
resolve(error ? Status.Error : Status.Done);
|
|
233
301
|
};
|
|
234
302
|
// Node 在 bind 失败时丢弃排队的 send 回调,必须监听 error 完成它。
|
|
235
303
|
onError = done;
|
|
236
304
|
socket.once('error', onError);
|
|
237
|
-
try {
|
|
305
|
+
try {
|
|
306
|
+
socket.send(input, port, address.toString(), done);
|
|
307
|
+
} catch (error) {
|
|
238
308
|
done(error instanceof Error ? error : new Error(String(error)));
|
|
239
309
|
}
|
|
240
310
|
});
|
|
241
|
-
try {
|
|
311
|
+
try {
|
|
312
|
+
return await this.awaitWrite(completion, generation);
|
|
313
|
+
} finally {
|
|
242
314
|
socket.off('error', onError);
|
|
243
315
|
}
|
|
244
316
|
}
|
|
@@ -254,23 +326,41 @@ export class UdpSocket extends Socket {
|
|
|
254
326
|
* 폐기하고 Error를 반환합니다. 논블로킹 모드에서 데이터가 없으면 NotReady입니다.
|
|
255
327
|
*/
|
|
256
328
|
receive(destination: Uint8Array | Packet): Promise<DatagramResult> {
|
|
257
|
-
const output =
|
|
329
|
+
const output =
|
|
330
|
+
destination instanceof Packet ? undefined : bytes(destination);
|
|
258
331
|
const generation = this.epoch;
|
|
259
332
|
return this.reads.run(async () => {
|
|
260
|
-
const result = (status: Status): DatagramResult =>
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
333
|
+
const result = (status: Status): DatagramResult => ({
|
|
334
|
+
status,
|
|
335
|
+
received: 0,
|
|
336
|
+
remotePort: 0,
|
|
337
|
+
});
|
|
338
|
+
await this.awaitReady(
|
|
339
|
+
() => this.pending.length > 0 || !this.bound || !!this.failure,
|
|
340
|
+
generation,
|
|
341
|
+
);
|
|
342
|
+
if (generation !== this.epoch || !this.bound) {
|
|
343
|
+
return result(Status.Error);
|
|
344
|
+
}
|
|
265
345
|
const item = this.pending.shift();
|
|
266
|
-
if (!item)
|
|
346
|
+
if (!item) {
|
|
347
|
+
return result(this.failure ? Status.Error : Status.NotReady);
|
|
348
|
+
}
|
|
267
349
|
this.pendingBytes -= item.data.length;
|
|
268
|
-
if (output && output.length < item.data.length)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
350
|
+
if (output && output.length < item.data.length) {
|
|
351
|
+
return result(Status.Error);
|
|
352
|
+
}
|
|
353
|
+
if (destination instanceof Packet) {
|
|
354
|
+
destination[packetReceive](item.data);
|
|
355
|
+
} else {
|
|
356
|
+
item.data.copy(output!);
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
status: Status.Done,
|
|
360
|
+
received: item.data.length,
|
|
272
361
|
remoteAddress: IpAddress.fromString(item.peer.address),
|
|
273
|
-
remotePort: item.peer.port
|
|
362
|
+
remotePort: item.peer.port,
|
|
363
|
+
};
|
|
274
364
|
});
|
|
275
365
|
}
|
|
276
366
|
/**
|
|
@@ -279,7 +369,9 @@ export class UdpSocket extends Socket {
|
|
|
279
369
|
* @ja バインド状態を返します。派生クラスで拡張できます。
|
|
280
370
|
* @ko 바인딩 상태를 반환하며 파생 클래스에서 확장할 수 있습니다.
|
|
281
371
|
*/
|
|
282
|
-
protected isAlive(): boolean {
|
|
372
|
+
protected isAlive(): boolean {
|
|
373
|
+
return this.bound;
|
|
374
|
+
}
|
|
283
375
|
/**
|
|
284
376
|
* Return readiness bits for pending datagrams and the current binding.
|
|
285
377
|
* @zh 返回待接收数据报和当前绑定对应的就绪位。
|
|
@@ -290,5 +382,7 @@ export class UdpSocket extends Socket {
|
|
|
290
382
|
// eslint-disable-next-line no-bitwise
|
|
291
383
|
return ((this.pending.length ? 1 : 0) | (this.bound ? 2 : 0)) & mask;
|
|
292
384
|
}
|
|
293
|
-
protected getNativeHandle(): UdpHandle | undefined {
|
|
385
|
+
protected getNativeHandle(): UdpHandle | undefined {
|
|
386
|
+
return this.transport;
|
|
387
|
+
}
|
|
294
388
|
}
|
package/src/system/angle.ts
CHANGED
|
@@ -14,7 +14,9 @@ const tau = Math.fround(pi * 2);
|
|
|
14
14
|
* @ko SFML의 float32 나머지. 소수부를 버린 몫은 int32 범위 내여야 한다.
|
|
15
15
|
*/
|
|
16
16
|
export function positiveRemainder(a: number, b: number): number {
|
|
17
|
-
if (!(b > 0))
|
|
17
|
+
if (!(b > 0)) {
|
|
18
|
+
throw new RangeError('Angle modulus must be positive');
|
|
19
|
+
}
|
|
18
20
|
// C++ int has no negative zero, unlike Math.trunc().
|
|
19
21
|
const truncated = Math.trunc(Math.fround(a / b));
|
|
20
22
|
const quotient = truncated === 0 ? 0 : truncated;
|
package/src/system/clock.ts
CHANGED
|
@@ -23,7 +23,9 @@ export class Clock {
|
|
|
23
23
|
*/
|
|
24
24
|
constructor(source?: ReadonlyValue<Clock>) {
|
|
25
25
|
if (source !== undefined) {
|
|
26
|
-
if (!(source instanceof Clock))
|
|
26
|
+
if (!(source instanceof Clock)) {
|
|
27
|
+
throw new TypeError('Expected a Clock');
|
|
28
|
+
}
|
|
27
29
|
this.reference = source.reference;
|
|
28
30
|
this.stopped = source.stopped;
|
|
29
31
|
} else {
|
|
@@ -38,7 +40,9 @@ export class Clock {
|
|
|
38
40
|
* @ko stop()으로 일시 정지한 시간을 제외한 누적 실행 시간을 반환한다.
|
|
39
41
|
*/
|
|
40
42
|
getElapsedTime(): Time {
|
|
41
|
-
return new Time(
|
|
43
|
+
return new Time(
|
|
44
|
+
((this.stopped ?? hrtime.bigint()) - this.reference) / 1000n,
|
|
45
|
+
);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/**
|
|
@@ -71,7 +75,9 @@ export class Clock {
|
|
|
71
75
|
* @ko 누적 시간을 유지하며 측정을 일시 정지한다.
|
|
72
76
|
*/
|
|
73
77
|
stop(this: Clock): void {
|
|
74
|
-
if (this.stopped === undefined)
|
|
78
|
+
if (this.stopped === undefined) {
|
|
79
|
+
this.stopped = hrtime.bigint();
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
/**
|
|
@@ -96,7 +102,9 @@ export class Clock {
|
|
|
96
102
|
|
|
97
103
|
private resetAt(running: boolean): Time {
|
|
98
104
|
const now = hrtime.bigint();
|
|
99
|
-
const elapsed = new Time(
|
|
105
|
+
const elapsed = new Time(
|
|
106
|
+
((this.stopped ?? now) - this.reference) / 1000n,
|
|
107
|
+
);
|
|
100
108
|
this.reference = now;
|
|
101
109
|
this.stopped = running ? undefined : now;
|
|
102
110
|
return elapsed;
|
package/src/system/err.ts
CHANGED
|
@@ -46,8 +46,11 @@ export function setErrorOutput(target?: Writable | null): void {
|
|
|
46
46
|
throw new TypeError('Expected an open Writable');
|
|
47
47
|
}
|
|
48
48
|
// Native retains this destination until all bytes captured for it drain.
|
|
49
|
-
// Buffers can split UTF-8 sequences; consumers decode them
|
|
50
|
-
|
|
49
|
+
// Buffers can split UTF-8 sequences; consumers decode them
|
|
50
|
+
// as a byte stream.
|
|
51
|
+
native.setErrorOutput((bytes: Buffer) => {
|
|
52
|
+
target.write(bytes);
|
|
53
|
+
});
|
|
51
54
|
if (!listening) {
|
|
52
55
|
process.on('beforeExit', drainBeforeExit);
|
|
53
56
|
listening = true;
|
|
@@ -52,7 +52,9 @@ export class FileInputStream extends InputStream {
|
|
|
52
52
|
}
|
|
53
53
|
return this.enqueue(() => {
|
|
54
54
|
const file = this.file;
|
|
55
|
-
if (!file)
|
|
55
|
+
if (!file) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
56
58
|
if (!Number.isSafeInteger(this.position + data.byteLength)) {
|
|
57
59
|
throw new RangeError('Read exceeds Node filesystem offset precision');
|
|
58
60
|
}
|
|
@@ -60,7 +62,9 @@ export class FileInputStream extends InputStream {
|
|
|
60
62
|
return new Promise<bigint | undefined>(resolve => {
|
|
61
63
|
read(file.fd, data, 0, data.byteLength, this.position,
|
|
62
64
|
(error, bytesRead) => {
|
|
63
|
-
if (error)
|
|
65
|
+
if (error) {
|
|
66
|
+
return resolve(undefined);
|
|
67
|
+
}
|
|
64
68
|
this.position += bytesRead;
|
|
65
69
|
resolve(BigInt(bytesRead));
|
|
66
70
|
});
|
|
@@ -84,7 +88,9 @@ export class FileInputStream extends InputStream {
|
|
|
84
88
|
throw new RangeError('Expected an offset from 0 to 2^53 - 1');
|
|
85
89
|
}
|
|
86
90
|
return this.enqueue(() => {
|
|
87
|
-
if (!this.file)
|
|
91
|
+
if (!this.file) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
88
94
|
this.position = Number(position);
|
|
89
95
|
return position;
|
|
90
96
|
});
|
|
@@ -113,7 +119,9 @@ export class FileInputStream extends InputStream {
|
|
|
113
119
|
*/
|
|
114
120
|
getSize(): Promise<bigint | undefined> {
|
|
115
121
|
return this.enqueue(async () => {
|
|
116
|
-
if (!this.file)
|
|
122
|
+
if (!this.file) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
117
125
|
try {
|
|
118
126
|
return (await this.file.stat({ bigint: true })).size;
|
|
119
127
|
} catch {
|
|
@@ -71,7 +71,9 @@ export class MemoryInputStream extends InputStream {
|
|
|
71
71
|
*/
|
|
72
72
|
constructor(data?: Uint8Array) {
|
|
73
73
|
super();
|
|
74
|
-
if (data !== undefined)
|
|
74
|
+
if (data !== undefined) {
|
|
75
|
+
this.open(data);
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/**
|
|
@@ -100,7 +102,9 @@ export class MemoryInputStream extends InputStream {
|
|
|
100
102
|
* 스트림 끝에서는 0n, 열리지 않은 경우 undefined를 반환한다.
|
|
101
103
|
*/
|
|
102
104
|
read(destination: Uint8Array): bigint | undefined {
|
|
103
|
-
if (!this.data)
|
|
105
|
+
if (!this.data) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
104
108
|
const count = Math.min(destination.length,
|
|
105
109
|
this.data.length - this.position);
|
|
106
110
|
destination.set(this.data.subarray(this.position, this.position + count));
|
|
@@ -122,7 +126,9 @@ export class MemoryInputStream extends InputStream {
|
|
|
122
126
|
if (typeof position !== 'bigint' || position < 0n) {
|
|
123
127
|
throw new RangeError('Expected a non-negative bigint position');
|
|
124
128
|
}
|
|
125
|
-
if (!this.data)
|
|
129
|
+
if (!this.data) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
126
132
|
this.position = Number(position > BigInt(this.data.length)
|
|
127
133
|
? BigInt(this.data.length) : position);
|
|
128
134
|
return BigInt(this.position);
|