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/native/batch-drawable.cc
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#include "batch-drawable.h"
|
|
2
|
-
#include "graphics-state.h"
|
|
3
|
-
#include "view-data.h"
|
|
4
|
-
#include "shape-state.h"
|
|
5
2
|
|
|
6
3
|
#include <bit>
|
|
7
4
|
#include <stdexcept>
|
|
8
5
|
#include <utility>
|
|
9
6
|
|
|
7
|
+
#include "graphics-state.h"
|
|
8
|
+
#include "shape-state.h"
|
|
9
|
+
#include "view-data.h"
|
|
10
|
+
|
|
10
11
|
namespace sfmljs {
|
|
11
12
|
|
|
12
13
|
BatchDrawable::BatchDrawable(std::shared_ptr<GraphicsContext> context,
|
|
@@ -27,12 +28,14 @@ std::span<DrawCommand> BatchDrawable::Commands() noexcept {
|
|
|
27
28
|
|
|
28
29
|
std::shared_ptr<VertexStorage> BatchDrawable::AllocateVertices(
|
|
29
30
|
std::size_t capacity) {
|
|
30
|
-
if (capacity > kMaxVertices)
|
|
31
|
+
if (capacity > kMaxVertices)
|
|
32
|
+
throw std::length_error("Vertex buffer too large");
|
|
31
33
|
vertices_ = std::make_shared<VertexStorage>(capacity);
|
|
32
34
|
return vertices_;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
bool BatchDrawable::Submit(sf::RenderTarget& target,
|
|
37
|
+
bool BatchDrawable::Submit(sf::RenderTarget& target,
|
|
38
|
+
std::size_t count,
|
|
36
39
|
const sf::Texture* output) {
|
|
37
40
|
if (count > commands_.size()) return false;
|
|
38
41
|
// Reuse capacity, but release resource ownership on success, rejection, or
|
|
@@ -63,7 +66,8 @@ bool BatchDrawable::Submit(sf::RenderTarget& target, std::size_t count,
|
|
|
63
66
|
const auto& command = commands_[index];
|
|
64
67
|
if (command.type == 0 || command.type == 2 || command.type == 3) continue;
|
|
65
68
|
if (command.type == 5) {
|
|
66
|
-
if (!ValidView(std::span(command.states.matrix).first<13>()))
|
|
69
|
+
if (!ValidView(std::span(command.states.matrix).first<13>()))
|
|
70
|
+
return false;
|
|
67
71
|
continue;
|
|
68
72
|
}
|
|
69
73
|
if (!command.states.Valid()) return false;
|
|
@@ -110,7 +114,8 @@ bool BatchDrawable::Submit(sf::RenderTarget& target, std::size_t count,
|
|
|
110
114
|
size = buffers_[index]->getVertexCount();
|
|
111
115
|
}
|
|
112
116
|
if (first > size || command.argument > size - first ||
|
|
113
|
-
command.payload[1] > 5 || command.payload[3] > 1)
|
|
117
|
+
command.payload[1] > 5 || command.payload[3] > 1)
|
|
118
|
+
return false;
|
|
114
119
|
if (const auto id = command.payload[2]) {
|
|
115
120
|
const auto found = context_->textures.find(id);
|
|
116
121
|
if (found == context_->textures.end()) return false;
|
|
@@ -146,20 +151,26 @@ void BatchDrawable::draw(sf::RenderTarget& target, sf::RenderStates) const {
|
|
|
146
151
|
~Restore() { object.SyncShape(); }
|
|
147
152
|
} restore{object};
|
|
148
153
|
ApplyTransform(*object.shape, {0, 0, 0, 1, 1, 0, 0});
|
|
149
|
-
ApplyShapeAppearance(*object.shape,
|
|
150
|
-
|
|
154
|
+
ApplyShapeAppearance(*object.shape,
|
|
155
|
+
textures_[index].get(),
|
|
156
|
+
std::bit_cast<ShapeAppearance>(command.payload));
|
|
151
157
|
auto states = command.states.Make();
|
|
152
|
-
states.shader =
|
|
158
|
+
states.shader =
|
|
159
|
+
shaders_[index] ? shaders_[index]->current.get() : nullptr;
|
|
153
160
|
target.draw(*object.shape, states);
|
|
154
161
|
} else if (command.type == 4 || command.type == 6) {
|
|
155
162
|
if (command.argument == 0) continue;
|
|
156
163
|
auto states = command.states.Make();
|
|
157
|
-
states.shader =
|
|
164
|
+
states.shader =
|
|
165
|
+
shaders_[index] ? shaders_[index]->current.get() : nullptr;
|
|
158
166
|
states.texture = textures_[index].get();
|
|
159
|
-
states.coordinateType =
|
|
167
|
+
states.coordinateType =
|
|
168
|
+
static_cast<sf::CoordinateType>(command.payload[3]);
|
|
160
169
|
if (command.type == 4) {
|
|
161
|
-
target.draw(vertices_->data() + command.payload[0],
|
|
162
|
-
|
|
170
|
+
target.draw(vertices_->data() + command.payload[0],
|
|
171
|
+
command.argument,
|
|
172
|
+
static_cast<sf::PrimitiveType>(command.payload[1]),
|
|
173
|
+
states);
|
|
163
174
|
} else {
|
|
164
175
|
auto& buffer = *buffers_[index];
|
|
165
176
|
struct Restore {
|
|
@@ -167,7 +178,8 @@ void BatchDrawable::draw(sf::RenderTarget& target, sf::RenderStates) const {
|
|
|
167
178
|
sf::PrimitiveType type;
|
|
168
179
|
~Restore() { buffer.setPrimitiveType(type); }
|
|
169
180
|
} restore{buffer, buffer.getPrimitiveType()};
|
|
170
|
-
buffer.setPrimitiveType(
|
|
181
|
+
buffer.setPrimitiveType(
|
|
182
|
+
static_cast<sf::PrimitiveType>(command.payload[1]));
|
|
171
183
|
target.draw(buffer, command.payload[0], command.argument, states);
|
|
172
184
|
}
|
|
173
185
|
} else {
|
|
@@ -180,7 +192,8 @@ void BatchDrawable::draw(sf::RenderTarget& target, sf::RenderStates) const {
|
|
|
180
192
|
ApplyTransform(object, std::bit_cast<TransformableData>(command.payload));
|
|
181
193
|
ApplyAppearance(object, *textures_[index], command.sprite);
|
|
182
194
|
auto states = command.states.Make();
|
|
183
|
-
states.shader =
|
|
195
|
+
states.shader =
|
|
196
|
+
shaders_[index] ? shaders_[index]->current.get() : nullptr;
|
|
184
197
|
target.draw(static_cast<const sf::Drawable&>(object), states);
|
|
185
198
|
}
|
|
186
199
|
}
|
package/native/batch-drawable.h
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "vertex-storage.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/Graphics/Drawable.hpp>
|
|
6
|
-
|
|
7
3
|
#include <cstddef>
|
|
8
4
|
#include <memory>
|
|
9
|
-
#include <span>
|
|
5
|
+
#include <span> // NOLINT(build/include_order): cpplint lacks C++20 headers
|
|
10
6
|
#include <vector>
|
|
11
7
|
|
|
12
|
-
|
|
8
|
+
#include "vertex-storage.h"
|
|
9
|
+
#include <SFML/Graphics/Drawable.hpp>
|
|
10
|
+
|
|
11
|
+
namespace sf {
|
|
12
|
+
class Texture;
|
|
13
|
+
}
|
|
13
14
|
|
|
14
15
|
namespace sfmljs {
|
|
15
16
|
|
|
@@ -27,7 +28,8 @@ class BatchDrawable final : public sf::Drawable {
|
|
|
27
28
|
BatchDrawable(std::shared_ptr<GraphicsContext> context, std::size_t capacity);
|
|
28
29
|
~BatchDrawable() override;
|
|
29
30
|
|
|
30
|
-
// The mapped command storage and owning batch must remain at stable
|
|
31
|
+
// The mapped command storage and owning batch must remain at stable
|
|
32
|
+
// addresses.
|
|
31
33
|
BatchDrawable(const BatchDrawable&) = delete;
|
|
32
34
|
BatchDrawable& operator=(const BatchDrawable&) = delete;
|
|
33
35
|
BatchDrawable(BatchDrawable&&) = delete;
|
|
@@ -35,7 +37,8 @@ class BatchDrawable final : public sf::Drawable {
|
|
|
35
37
|
|
|
36
38
|
std::span<DrawCommand> Commands() noexcept;
|
|
37
39
|
std::shared_ptr<VertexStorage> AllocateVertices(std::size_t capacity);
|
|
38
|
-
bool Submit(sf::RenderTarget& target,
|
|
40
|
+
bool Submit(sf::RenderTarget& target, // NOLINT(runtime/references)
|
|
41
|
+
std::size_t count,
|
|
39
42
|
const sf::Texture* output);
|
|
40
43
|
|
|
41
44
|
private:
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
#include <string>
|
|
2
|
+
#include <unordered_map>
|
|
3
|
+
|
|
1
4
|
#include "context-settings.h"
|
|
2
5
|
#include "deferred-delete.h"
|
|
3
6
|
#include "exception-boundary.h"
|
|
4
7
|
#include "shared-handle.h"
|
|
5
|
-
|
|
6
8
|
#include <SFML/Window/Context.hpp>
|
|
7
9
|
#include <SFML/Window/Vulkan.hpp>
|
|
8
10
|
|
|
9
|
-
#include <string>
|
|
10
|
-
#include <unordered_map>
|
|
11
|
-
|
|
12
11
|
namespace {
|
|
13
12
|
|
|
14
13
|
struct ContextState;
|
|
15
|
-
using Registry =
|
|
14
|
+
using Registry =
|
|
15
|
+
std::unordered_map<const sf::Context*, std::weak_ptr<ContextState>>;
|
|
16
16
|
using Handle = sfmljs::SharedHandle<ContextState>;
|
|
17
17
|
|
|
18
18
|
struct ContextState {
|
|
19
19
|
explicit ContextState(std::shared_ptr<Registry> registry)
|
|
20
|
-
: registry(std::move(registry)),
|
|
20
|
+
: registry(std::move(registry)),
|
|
21
|
+
context(std::make_unique<sf::Context>()) {}
|
|
21
22
|
ContextState(std::shared_ptr<Registry> registry,
|
|
22
|
-
const sf::ContextSettings& settings,
|
|
23
|
+
const sf::ContextSettings& settings,
|
|
24
|
+
sf::Vector2u size)
|
|
23
25
|
: registry(std::move(registry)),
|
|
24
26
|
context(std::make_unique<sf::Context>(settings, size)) {}
|
|
25
27
|
~ContextState() { registry->erase(context.get()); }
|
|
@@ -32,25 +34,28 @@ v8::Local<v8::String> RegistryKey() {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
std::shared_ptr<Registry> CurrentRegistry() {
|
|
35
|
-
auto value =
|
|
36
|
-
|
|
37
|
+
auto value =
|
|
38
|
+
Nan::GetPrivate(Nan::GetCurrentContext()->Global(), RegistryKey())
|
|
39
|
+
.ToLocalChecked();
|
|
37
40
|
return sfmljs::SharedHandle<Registry>::From(value)->owner();
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
v8::Local<v8::BigInt> Key(const sf::Context* context) {
|
|
41
44
|
return v8::BigInt::NewFromUnsigned(v8::Isolate::GetCurrent(),
|
|
42
|
-
|
|
45
|
+
reinterpret_cast<std::uintptr_t>(context));
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
v8::Local<v8::Object> MapContext(const std::shared_ptr<ContextState>& state) {
|
|
46
49
|
auto result = Nan::New<v8::Object>();
|
|
47
|
-
Nan::Set(result, Nan::New("handle").ToLocalChecked(),
|
|
48
|
-
|
|
50
|
+
Nan::Set(result, Nan::New("handle").ToLocalChecked(), Handle::Create(state))
|
|
51
|
+
.FromJust();
|
|
49
52
|
Nan::Set(result, Nan::New("key").ToLocalChecked(), Key(state->context.get()))
|
|
50
53
|
.FromJust();
|
|
51
|
-
Nan::Set(result,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
Nan::Set(result,
|
|
55
|
+
Nan::New("settings").ToLocalChecked(),
|
|
56
|
+
sfmljs::MapContextSettings(
|
|
57
|
+
v8::Isolate::GetCurrent(), state, state->context->getSettings()))
|
|
58
|
+
.FromJust();
|
|
54
59
|
return result;
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -65,7 +70,9 @@ NAN_METHOD(CreateContext) {
|
|
|
65
70
|
if (!info[1]->IsUint32() || !info[2]->IsUint32()) {
|
|
66
71
|
return Nan::ThrowRangeError("Expected unsigned context dimensions");
|
|
67
72
|
}
|
|
68
|
-
state = sfmljs::MakeThreadOwned<ContextState>(
|
|
73
|
+
state = sfmljs::MakeThreadOwned<ContextState>(
|
|
74
|
+
registry,
|
|
75
|
+
settings,
|
|
69
76
|
sf::Vector2u{Nan::To<std::uint32_t>(info[1]).FromJust(),
|
|
70
77
|
Nan::To<std::uint32_t>(info[2]).FromJust()});
|
|
71
78
|
}
|
|
@@ -77,7 +84,8 @@ NAN_METHOD(SetContextActive) {
|
|
|
77
84
|
auto* handle = Handle::From(info[0]);
|
|
78
85
|
if (!handle) return;
|
|
79
86
|
if (!info[1]->IsBoolean()) return Nan::ThrowTypeError("Expected a boolean");
|
|
80
|
-
info.GetReturnValue().Set(
|
|
87
|
+
info.GetReturnValue().Set(
|
|
88
|
+
handle->owner()->context->setActive(info[1]->IsTrue()));
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
NAN_METHOD(GetActiveContextKey) {
|
|
@@ -101,11 +109,12 @@ NAN_METHOD(ReferenceActiveContext) {
|
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
NAN_METHOD(GetActiveContextId) {
|
|
104
|
-
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
105
|
-
sf::Context::getActiveContextId()));
|
|
112
|
+
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
113
|
+
info.GetIsolate(), sf::Context::getActiveContextId()));
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
bool Name(v8::Local<v8::Value> input,
|
|
116
|
+
bool Name(v8::Local<v8::Value> input,
|
|
117
|
+
std::string& output) { // NOLINT(runtime/references)
|
|
109
118
|
if (!input->IsString()) {
|
|
110
119
|
Nan::ThrowTypeError("Expected a name");
|
|
111
120
|
return false;
|
|
@@ -130,8 +139,8 @@ NAN_METHOD(GetContextFunction) {
|
|
|
130
139
|
std::string name;
|
|
131
140
|
if (!Name(info[0], name)) return;
|
|
132
141
|
if (const auto function = sf::Context::getFunction(name.c_str())) {
|
|
133
|
-
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
134
|
-
reinterpret_cast<std::uintptr_t>(function)));
|
|
142
|
+
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
143
|
+
info.GetIsolate(), reinterpret_cast<std::uintptr_t>(function)));
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
|
|
@@ -146,8 +155,8 @@ NAN_METHOD(GetVulkanFunction) {
|
|
|
146
155
|
std::string name;
|
|
147
156
|
if (!Name(info[0], name)) return;
|
|
148
157
|
if (const auto function = sf::Vulkan::getFunction(name.c_str())) {
|
|
149
|
-
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
150
|
-
reinterpret_cast<std::uintptr_t>(function)));
|
|
158
|
+
info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(
|
|
159
|
+
info.GetIsolate(), reinterpret_cast<std::uintptr_t>(function)));
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
|
|
@@ -164,14 +173,18 @@ NAN_METHOD(GetVulkanGraphicsRequiredInstanceExtensions) {
|
|
|
164
173
|
} // namespace
|
|
165
174
|
|
|
166
175
|
NAN_MODULE_INIT(InitializeContext) {
|
|
167
|
-
Nan::SetPrivate(
|
|
168
|
-
|
|
176
|
+
Nan::SetPrivate(
|
|
177
|
+
Nan::GetCurrentContext()->Global(),
|
|
178
|
+
RegistryKey(),
|
|
179
|
+
sfmljs::SharedHandle<Registry>::Create(std::make_shared<Registry>()))
|
|
180
|
+
.FromJust();
|
|
169
181
|
sfmljs::SetMethod<CreateContext>(target, "createContext");
|
|
170
182
|
sfmljs::SetMethod<SetContextActive>(target, "setContextActive");
|
|
171
183
|
sfmljs::SetMethod<GetActiveContextKey>(target, "getActiveContextKey");
|
|
172
184
|
sfmljs::SetMethod<ReferenceActiveContext>(target, "referenceActiveContext");
|
|
173
185
|
sfmljs::SetMethod<GetActiveContextId>(target, "getActiveContextId");
|
|
174
|
-
sfmljs::SetMethod<IsContextExtensionAvailable>(target,
|
|
186
|
+
sfmljs::SetMethod<IsContextExtensionAvailable>(target,
|
|
187
|
+
"isContextExtensionAvailable");
|
|
175
188
|
sfmljs::SetMethod<GetContextFunction>(target, "getContextFunction");
|
|
176
189
|
sfmljs::SetMethod<IsVulkanAvailable>(target, "isVulkanAvailable");
|
|
177
190
|
sfmljs::SetMethod<GetVulkanFunction>(target, "getVulkanFunction");
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#include <nan.h>
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
#include "shared-handle.h"
|
|
6
|
+
#include <SFML/Window/ContextSettings.hpp>
|
|
6
7
|
|
|
7
8
|
namespace sfmljs {
|
|
8
9
|
|
|
9
10
|
template <typename Owner>
|
|
10
11
|
v8::Local<v8::ArrayBuffer> MapContextSettings(
|
|
11
|
-
v8::Isolate* isolate,
|
|
12
|
+
v8::Isolate* isolate,
|
|
13
|
+
const std::shared_ptr<Owner>& owner,
|
|
12
14
|
const sf::ContextSettings& settings) {
|
|
13
15
|
static_assert(offsetof(sf::ContextSettings, depthBits) == 0);
|
|
14
16
|
static_assert(offsetof(sf::ContextSettings, stencilBits) == 4);
|
|
@@ -18,12 +20,14 @@ v8::Local<v8::ArrayBuffer> MapContextSettings(
|
|
|
18
20
|
static_assert(offsetof(sf::ContextSettings, attributeFlags) == 20);
|
|
19
21
|
static_assert(offsetof(sf::ContextSettings, sRgbCapable) == 24);
|
|
20
22
|
static_assert(sizeof(bool) == 1);
|
|
21
|
-
return MapShared(isolate,
|
|
23
|
+
return MapShared(isolate,
|
|
24
|
+
owner,
|
|
25
|
+
const_cast<sf::ContextSettings*>(&settings),
|
|
22
26
|
sizeof(settings));
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
inline bool ReadContextSettings(v8::Local<v8::Value> value,
|
|
26
|
-
sf::ContextSettings& settings) {
|
|
30
|
+
sf::ContextSettings& settings) { // NOLINT
|
|
27
31
|
if (value->IsUndefined()) return true;
|
|
28
32
|
// Existing internal probes can still supply the stencil size alone.
|
|
29
33
|
if (value->IsUint32()) {
|
|
@@ -41,7 +45,8 @@ inline bool ReadContextSettings(v8::Local<v8::Value> value,
|
|
|
41
45
|
}
|
|
42
46
|
if (field->IsUndefined()) return true;
|
|
43
47
|
if (!field->IsUint32()) {
|
|
44
|
-
Nan::ThrowRangeError(
|
|
48
|
+
Nan::ThrowRangeError(
|
|
49
|
+
"Context settings require unsigned 32-bit integers");
|
|
45
50
|
return false;
|
|
46
51
|
}
|
|
47
52
|
output = Nan::To<std::uint32_t>(field).FromJust();
|
|
@@ -52,10 +57,12 @@ inline bool ReadContextSettings(v8::Local<v8::Value> value,
|
|
|
52
57
|
!integer("antiAliasingLevel", settings.antiAliasingLevel) ||
|
|
53
58
|
!integer("majorVersion", settings.majorVersion) ||
|
|
54
59
|
!integer("minorVersion", settings.minorVersion) ||
|
|
55
|
-
!integer("attributeFlags", settings.attributeFlags))
|
|
60
|
+
!integer("attributeFlags", settings.attributeFlags))
|
|
61
|
+
return false;
|
|
56
62
|
v8::Local<v8::Value> srgb;
|
|
57
|
-
if (!Nan::Get(object, Nan::New("sRgbCapable").ToLocalChecked())
|
|
58
|
-
|
|
63
|
+
if (!Nan::Get(object, Nan::New("sRgbCapable").ToLocalChecked())
|
|
64
|
+
.ToLocal(&srgb))
|
|
65
|
+
return false;
|
|
59
66
|
if (!srgb->IsUndefined()) {
|
|
60
67
|
if (!srgb->IsBoolean()) {
|
|
61
68
|
Nan::ThrowTypeError("sRgbCapable must be a boolean");
|
|
@@ -15,9 +15,12 @@ std::shared_ptr<DeferredDelete> DeferredDelete::Current() {
|
|
|
15
15
|
|
|
16
16
|
void DeferredDelete::Initialize(v8::Isolate* isolate) {
|
|
17
17
|
auto queue = std::make_shared<DeferredDelete>();
|
|
18
|
-
const int status = uv_async_init(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const int status = uv_async_init(
|
|
19
|
+
node::GetCurrentEventLoop(isolate),
|
|
20
|
+
&queue->async_,
|
|
21
|
+
[](uv_async_t* handle) {
|
|
22
|
+
auto& owner =
|
|
23
|
+
*static_cast<std::shared_ptr<DeferredDelete>*>(handle->data);
|
|
21
24
|
owner->Drain();
|
|
22
25
|
});
|
|
23
26
|
if (status != 0) throw std::runtime_error(uv_strerror(status));
|
|
@@ -41,9 +44,9 @@ void DeferredDelete::Cleanup(void* data) {
|
|
|
41
44
|
}
|
|
42
45
|
current.reset();
|
|
43
46
|
uv_close(reinterpret_cast<uv_handle_t*>(&queue->async_),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
[](uv_handle_t* handle) {
|
|
48
|
+
delete static_cast<std::shared_ptr<DeferredDelete>*>(handle->data);
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
} // namespace sfmljs
|
package/native/deferred-delete.h
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
#include <uv.h>
|
|
5
5
|
|
|
6
6
|
#include <memory>
|
|
7
|
-
#include <mutex>
|
|
8
|
-
#include <thread>
|
|
7
|
+
#include <mutex> // NOLINT(build/c++11)
|
|
8
|
+
#include <thread> // NOLINT(build/c++11)
|
|
9
9
|
#include <unordered_map>
|
|
10
10
|
#include <utility>
|
|
11
11
|
#include <vector>
|
|
@@ -67,13 +67,12 @@ class DeferredDelete {
|
|
|
67
67
|
template <typename T, typename... Args>
|
|
68
68
|
std::shared_ptr<T> MakeThreadOwned(Args&&... args) {
|
|
69
69
|
auto queue = DeferredDelete::Current();
|
|
70
|
-
auto object =
|
|
71
|
-
[queue](T* value) {
|
|
72
|
-
queue->Dispose(
|
|
73
|
-
|
|
74
|
-
}});
|
|
70
|
+
auto object =
|
|
71
|
+
std::shared_ptr<T>(new T(std::forward<Args>(args)...), [queue](T* value) {
|
|
72
|
+
queue->Dispose(
|
|
73
|
+
{value, [](void* pointer) { delete static_cast<T*>(pointer); }});
|
|
75
74
|
});
|
|
76
|
-
if constexpr (requires(T& value) { value.CloseBeforeThreadExit(); }) {
|
|
75
|
+
if constexpr (requires(T & value) { value.CloseBeforeThreadExit(); }) {
|
|
77
76
|
queue->BeforeExit(object.get(), [](void* pointer) {
|
|
78
77
|
static_cast<T*>(pointer)->CloseBeforeThreadExit();
|
|
79
78
|
});
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
#include "exception-boundary.h"
|
|
2
|
-
#include "image-state.h"
|
|
3
|
-
#include "shared-handle.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/System/Err.hpp>
|
|
6
|
-
|
|
7
1
|
#include <algorithm>
|
|
8
2
|
#include <deque>
|
|
9
3
|
#include <memory>
|
|
10
|
-
#include <mutex>
|
|
4
|
+
#include <mutex> // NOLINT(build/c++11)
|
|
11
5
|
#include <ostream>
|
|
12
6
|
#include <streambuf>
|
|
13
7
|
#include <string>
|
|
14
8
|
#include <vector>
|
|
15
9
|
|
|
10
|
+
#include "exception-boundary.h"
|
|
11
|
+
#include "image-state.h"
|
|
12
|
+
#include "shared-handle.h"
|
|
13
|
+
#include <SFML/System/Err.hpp>
|
|
14
|
+
|
|
16
15
|
namespace {
|
|
17
16
|
|
|
18
17
|
struct Environment;
|
|
@@ -60,9 +59,9 @@ struct Sink {
|
|
|
60
59
|
std::unique_ptr<Nan::AsyncResource> resource;
|
|
61
60
|
std::deque<std::string> chunks; // protected by Router::mutex
|
|
62
61
|
std::weak_ptr<Environment> environment;
|
|
63
|
-
bool active{true};
|
|
64
|
-
bool closing{};
|
|
65
|
-
bool dispatching{};
|
|
62
|
+
bool active{true}; // protected by Router::mutex
|
|
63
|
+
bool closing{}; // JS thread only
|
|
64
|
+
bool dispatching{}; // JS thread only
|
|
66
65
|
|
|
67
66
|
bool Dispatch();
|
|
68
67
|
void Close();
|
|
@@ -115,7 +114,8 @@ void Sink::Close() {
|
|
|
115
114
|
|
|
116
115
|
bool Sink::Dispatch() {
|
|
117
116
|
if (closing || dispatching ||
|
|
118
|
-
v8::Isolate::GetCurrent()->IsExecutionTerminating())
|
|
117
|
+
v8::Isolate::GetCurrent()->IsExecutionTerminating())
|
|
118
|
+
return true;
|
|
119
119
|
dispatching = true;
|
|
120
120
|
struct Reset {
|
|
121
121
|
bool& flag;
|
|
@@ -130,10 +130,13 @@ bool Sink::Dispatch() {
|
|
|
130
130
|
Nan::HandleScope scope;
|
|
131
131
|
for (auto& chunk : pending) {
|
|
132
132
|
auto bytes = std::make_unique<std::string>(std::move(chunk));
|
|
133
|
-
auto buffer =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
auto buffer =
|
|
134
|
+
Nan::NewBuffer(
|
|
135
|
+
bytes->data(),
|
|
136
|
+
static_cast<std::uint32_t>(bytes->size()),
|
|
137
|
+
[](char*, void* data) { delete static_cast<std::string*>(data); },
|
|
138
|
+
bytes.get())
|
|
139
|
+
.ToLocalChecked();
|
|
137
140
|
bytes.release();
|
|
138
141
|
v8::Local<v8::Value> args[]{buffer};
|
|
139
142
|
Nan::TryCatch caught;
|
|
@@ -161,31 +164,39 @@ v8::Local<v8::String> EnvironmentKey() {
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
std::shared_ptr<Environment> CurrentEnvironment() {
|
|
164
|
-
auto value =
|
|
165
|
-
|
|
167
|
+
auto value =
|
|
168
|
+
Nan::GetPrivate(Nan::GetCurrentContext()->Global(), EnvironmentKey())
|
|
169
|
+
.ToLocalChecked();
|
|
166
170
|
return sfmljs::SharedHandle<Environment>::From(value)->owner();
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
NAN_METHOD(SetErrorOutput) {
|
|
170
174
|
if (!info[0]->IsFunction() && !info[0]->IsNullOrUndefined()) {
|
|
171
|
-
return Nan::ThrowTypeError(
|
|
175
|
+
return Nan::ThrowTypeError(
|
|
176
|
+
"Expected an output callback, null or undefined");
|
|
172
177
|
}
|
|
173
178
|
const auto env = CurrentEnvironment();
|
|
174
179
|
std::shared_ptr<Sink> next;
|
|
175
180
|
if (info[0]->IsFunction()) {
|
|
176
181
|
next = std::make_shared<Sink>();
|
|
177
182
|
next->environment = env;
|
|
178
|
-
next->callback =
|
|
183
|
+
next->callback =
|
|
184
|
+
std::make_unique<Nan::Callback>(info[0].As<v8::Function>());
|
|
179
185
|
next->resource = std::make_unique<Nan::AsyncResource>("sfml:ErrorOutput");
|
|
180
186
|
env->sinks.push_back(next);
|
|
181
187
|
auto retained = std::make_unique<std::shared_ptr<Sink>>(next);
|
|
182
|
-
const int status = uv_async_init(
|
|
183
|
-
|
|
188
|
+
const int status = uv_async_init(
|
|
189
|
+
node::GetCurrentEventLoop(info.GetIsolate()),
|
|
190
|
+
&next->async,
|
|
191
|
+
[](uv_async_t* handle) {
|
|
184
192
|
Nan::HandleScope scope;
|
|
185
193
|
Nan::TryCatch caught;
|
|
186
|
-
sfmljs::GuardExceptions(
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
sfmljs::GuardExceptions(
|
|
195
|
+
[&] {
|
|
196
|
+
(*static_cast<std::shared_ptr<Sink>*>(handle->data))
|
|
197
|
+
->Dispatch();
|
|
198
|
+
},
|
|
199
|
+
[](const char* message) { sfmljs::ThrowError(message); });
|
|
189
200
|
if (caught.HasCaught() && caught.CanContinue()) {
|
|
190
201
|
Nan::FatalException(caught);
|
|
191
202
|
}
|
|
@@ -260,10 +271,13 @@ void Cleanup(void* data) {
|
|
|
260
271
|
NAN_MODULE_INIT(InitializeErrorStream) {
|
|
261
272
|
Router::Get();
|
|
262
273
|
auto env = std::make_shared<Environment>();
|
|
263
|
-
Nan::SetPrivate(Nan::GetCurrentContext()->Global(),
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
274
|
+
Nan::SetPrivate(Nan::GetCurrentContext()->Global(),
|
|
275
|
+
EnvironmentKey(),
|
|
276
|
+
sfmljs::SharedHandle<Environment>::Create(env))
|
|
277
|
+
.FromJust();
|
|
278
|
+
node::AddEnvironmentCleanupHook(v8::Isolate::GetCurrent(),
|
|
279
|
+
Cleanup,
|
|
280
|
+
new std::shared_ptr<Environment>(env));
|
|
267
281
|
sfmljs::SetMethod<WriteError>(target, "writeError");
|
|
268
282
|
sfmljs::SetMethod<SetErrorOutput>(target, "setErrorOutput");
|
|
269
283
|
sfmljs::SetMethod<FlushErrorOutput>(target, "flushErrorOutput");
|