sfml.js 1.0.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/native/stream-binding.cc
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
#include "image-state.h"
|
|
2
|
-
#include "exception-boundary.h"
|
|
3
|
-
|
|
4
|
-
#include <SFML/System/InputStream.hpp>
|
|
5
|
-
|
|
6
|
-
#include <condition_variable>
|
|
7
1
|
#include <atomic>
|
|
2
|
+
#include <condition_variable> // NOLINT(build/c++11)
|
|
8
3
|
#include <cstring>
|
|
9
|
-
#include <mutex>
|
|
10
|
-
#include <thread>
|
|
4
|
+
#include <mutex> // NOLINT(build/c++11)
|
|
5
|
+
#include <thread> // NOLINT(build/c++11)
|
|
11
6
|
#include <vector>
|
|
12
7
|
|
|
8
|
+
#include "exception-boundary.h"
|
|
9
|
+
#include "image-state.h"
|
|
10
|
+
#include <SFML/System/InputStream.hpp>
|
|
11
|
+
|
|
13
12
|
namespace {
|
|
14
13
|
|
|
15
14
|
enum class Operation { Read, Seek, Tell, Size };
|
|
@@ -35,31 +34,37 @@ NAN_METHOD(CompleteRequest) {
|
|
|
35
34
|
auto request = handle->owner();
|
|
36
35
|
std::lock_guard lock(request->mutex);
|
|
37
36
|
if (request->complete) return;
|
|
38
|
-
sfmljs::GuardExceptions(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
sfmljs::GuardExceptions(
|
|
38
|
+
[&] {
|
|
39
|
+
if (!info[0]->IsNullOrUndefined()) {
|
|
40
|
+
Nan::Utf8String error(info[0]);
|
|
41
|
+
request->error.assign(*error, error.length());
|
|
42
|
+
if (request->error.empty())
|
|
43
|
+
request->error = "InputStream operation failed";
|
|
44
|
+
} else if (!info[1]->IsUndefined()) {
|
|
45
|
+
bool lossless = false;
|
|
46
|
+
const auto value =
|
|
47
|
+
info[1]->IsBigInt()
|
|
48
|
+
? info[1].As<v8::BigInt>()->Uint64Value(&lossless)
|
|
49
|
+
: 0;
|
|
50
|
+
if (!lossless || value > std::numeric_limits<std::size_t>::max() ||
|
|
51
|
+
(request->operation == Operation::Read &&
|
|
52
|
+
value > request->bytes.size())) {
|
|
53
|
+
request->error =
|
|
54
|
+
"Stream result must be a non-negative bigint within range";
|
|
55
|
+
} else {
|
|
56
|
+
request->result = static_cast<std::size_t>(value);
|
|
57
|
+
if (request->operation == Operation::Read) {
|
|
58
|
+
request->snapshot.assign(request->bytes.begin(),
|
|
59
|
+
request->bytes.begin() + value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
+
},
|
|
64
|
+
[&](const char* message) {
|
|
65
|
+
request->result.reset();
|
|
66
|
+
request->error = message;
|
|
67
|
+
});
|
|
63
68
|
request->complete = true;
|
|
64
69
|
request->ready.notify_one();
|
|
65
70
|
}
|
|
@@ -71,52 +76,58 @@ class StreamLoader final : public sf::InputStream {
|
|
|
71
76
|
StreamLoader(std::shared_ptr<sfmljs::ImageState> state,
|
|
72
77
|
v8::Local<v8::Function> dispatch,
|
|
73
78
|
v8::Local<v8::Function> callback)
|
|
74
|
-
: state_(std::move(state)),
|
|
79
|
+
: state_(std::move(state)),
|
|
80
|
+
dispatch_(dispatch),
|
|
81
|
+
callback_(callback),
|
|
75
82
|
resource_("sfml:ImageStream") {}
|
|
76
83
|
|
|
77
84
|
void Start() {
|
|
78
|
-
const int status = uv_async_init(
|
|
79
|
-
v8::Isolate::GetCurrent()), &async_, OnAsync);
|
|
85
|
+
const int status = uv_async_init(
|
|
86
|
+
node::GetCurrentEventLoop(v8::Isolate::GetCurrent()), &async_, OnAsync);
|
|
80
87
|
if (status != 0) throw std::runtime_error(uv_strerror(status));
|
|
81
88
|
async_.data = this;
|
|
82
|
-
sfmljs::GuardExceptions(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
sfmljs::GuardExceptions(
|
|
90
|
+
[&] {
|
|
91
|
+
cleanup_ = node::AddEnvironmentCleanupHook(
|
|
92
|
+
v8::Isolate::GetCurrent(),
|
|
93
|
+
[](void* data, void (*done)(void*), void* argument) {
|
|
94
|
+
auto* self = static_cast<StreamLoader*>(data);
|
|
95
|
+
self->cleanupDone_ = done;
|
|
96
|
+
self->cleanupArgument_ = argument;
|
|
97
|
+
self->cancelled_ = true;
|
|
98
|
+
std::shared_ptr<Request> request;
|
|
99
|
+
{
|
|
100
|
+
std::lock_guard lock(self->mutex_);
|
|
101
|
+
request = self->request_;
|
|
102
|
+
}
|
|
103
|
+
if (request) {
|
|
104
|
+
std::lock_guard lock(request->mutex);
|
|
105
|
+
request->complete = true;
|
|
106
|
+
request->ready.notify_one();
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
this);
|
|
110
|
+
thread_ = std::thread([this] {
|
|
111
|
+
try {
|
|
112
|
+
image_ = std::make_shared<sf::Image>();
|
|
113
|
+
ok_ = image_->loadFromStream(*this);
|
|
114
|
+
} catch (const std::exception& error) {
|
|
115
|
+
error_ = error.what();
|
|
116
|
+
} catch (...) {
|
|
117
|
+
error_ = "Unknown SFML stream error";
|
|
93
118
|
}
|
|
94
|
-
|
|
95
|
-
std::lock_guard lock(
|
|
96
|
-
|
|
97
|
-
request->ready.notify_one();
|
|
119
|
+
{
|
|
120
|
+
std::lock_guard lock(mutex_);
|
|
121
|
+
finished_ = true;
|
|
98
122
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} catch (const std::exception& error) {
|
|
105
|
-
error_ = error.what();
|
|
106
|
-
} catch (...) {
|
|
107
|
-
error_ = "Unknown SFML stream error";
|
|
108
|
-
}
|
|
109
|
-
{
|
|
110
|
-
std::lock_guard lock(mutex_);
|
|
123
|
+
uv_async_send(&async_);
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
[&](const char* message) {
|
|
127
|
+
error_ = message;
|
|
111
128
|
finished_ = true;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
}, [&](const char* message) {
|
|
116
|
-
error_ = message;
|
|
117
|
-
finished_ = true;
|
|
118
|
-
uv_async_send(&async_);
|
|
119
|
-
});
|
|
129
|
+
uv_async_send(&async_);
|
|
130
|
+
});
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
std::optional<std::size_t> read(void* data, std::size_t size) override {
|
|
@@ -137,7 +148,8 @@ class StreamLoader final : public sf::InputStream {
|
|
|
137
148
|
}
|
|
138
149
|
|
|
139
150
|
private:
|
|
140
|
-
std::shared_ptr<Request> Exchange(Operation operation,
|
|
151
|
+
std::shared_ptr<Request> Exchange(Operation operation,
|
|
152
|
+
std::size_t value = 0) {
|
|
141
153
|
if (cancelled_) throw std::runtime_error("Stream loading cancelled");
|
|
142
154
|
auto request = std::make_shared<Request>();
|
|
143
155
|
request->operation = operation;
|
|
@@ -192,55 +204,68 @@ class StreamLoader final : public sf::InputStream {
|
|
|
192
204
|
if (!request || request->dispatched || self->cancelled_) return;
|
|
193
205
|
request->dispatched = true;
|
|
194
206
|
Nan::HandleScope scope;
|
|
195
|
-
sfmljs::GuardExceptions(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
sfmljs::GuardExceptions(
|
|
208
|
+
[&] {
|
|
209
|
+
auto complete = Nan::GetFunction(Nan::New<v8::FunctionTemplate>(
|
|
210
|
+
CompleteRequest,
|
|
211
|
+
RequestHandle::Create(request)))
|
|
212
|
+
.ToLocalChecked();
|
|
213
|
+
v8::Local<v8::Value> data = Nan::Undefined();
|
|
214
|
+
if (request->operation == Operation::Read) {
|
|
215
|
+
auto buffer =
|
|
216
|
+
request->bytes.empty()
|
|
217
|
+
? v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), 0)
|
|
218
|
+
: sfmljs::MapShared(v8::Isolate::GetCurrent(),
|
|
219
|
+
request,
|
|
220
|
+
request->bytes.data(),
|
|
221
|
+
request->bytes.size());
|
|
222
|
+
data = v8::Uint8Array::New(buffer, 0, request->bytes.size());
|
|
223
|
+
}
|
|
224
|
+
v8::Local<v8::Value> args[] = {
|
|
225
|
+
Nan::New(static_cast<int>(request->operation)),
|
|
226
|
+
data,
|
|
227
|
+
v8::BigInt::NewFromUnsigned(v8::Isolate::GetCurrent(),
|
|
228
|
+
request->position),
|
|
229
|
+
complete};
|
|
230
|
+
Nan::TryCatch caught;
|
|
231
|
+
self->dispatch_.Call(4, args, &self->resource_);
|
|
232
|
+
if (caught.HasCaught()) {
|
|
233
|
+
std::lock_guard lock(request->mutex);
|
|
234
|
+
if (!request->complete) {
|
|
235
|
+
Nan::Utf8String error(caught.Exception());
|
|
236
|
+
request->error.assign(*error, error.length());
|
|
237
|
+
request->complete = true;
|
|
238
|
+
request->ready.notify_one();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
[&](const char* message) {
|
|
243
|
+
std::lock_guard lock(request->mutex);
|
|
244
|
+
if (request->complete) return;
|
|
245
|
+
request->result.reset();
|
|
246
|
+
request->error = message;
|
|
217
247
|
request->complete = true;
|
|
218
248
|
request->ready.notify_one();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}, [&](const char* message) {
|
|
222
|
-
std::lock_guard lock(request->mutex);
|
|
223
|
-
if (request->complete) return;
|
|
224
|
-
request->result.reset();
|
|
225
|
-
request->error = message;
|
|
226
|
-
request->complete = true;
|
|
227
|
-
request->ready.notify_one();
|
|
228
|
-
});
|
|
249
|
+
});
|
|
229
250
|
}
|
|
230
251
|
|
|
231
252
|
void Finish() {
|
|
232
253
|
v8::Local<v8::Value> result = Nan::Undefined();
|
|
233
|
-
sfmljs::GuardExceptions(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
254
|
+
sfmljs::GuardExceptions(
|
|
255
|
+
[&] {
|
|
256
|
+
if (ok_ && error_.empty()) {
|
|
257
|
+
if (sfmljs::ImageBytes(*image_) > node::Buffer::kMaxLength) {
|
|
258
|
+
throw std::length_error(
|
|
259
|
+
"Decoded image exceeds the pixel buffer limit");
|
|
260
|
+
}
|
|
261
|
+
result = sfmljs::MapImage(v8::Isolate::GetCurrent(), image_);
|
|
262
|
+
state_->current = image_;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
[&](const char* message) { error_ = message; });
|
|
242
266
|
v8::Local<v8::Value> error = error_.empty()
|
|
243
|
-
|
|
267
|
+
? v8::Local<v8::Value>(Nan::Null())
|
|
268
|
+
: sfmljs::Error(error_.c_str());
|
|
244
269
|
v8::Local<v8::Value> args[] = {error, result};
|
|
245
270
|
callback_.Call(2, args, &resource_);
|
|
246
271
|
}
|
|
@@ -252,7 +277,7 @@ class StreamLoader final : public sf::InputStream {
|
|
|
252
277
|
bool finished_{};
|
|
253
278
|
std::atomic<bool> cancelled_{false};
|
|
254
279
|
node::AsyncCleanupHookHandle cleanup_;
|
|
255
|
-
void (*cleanupDone_)(void*)
|
|
280
|
+
void (*cleanupDone_)(void*) = nullptr;
|
|
256
281
|
void* cleanupArgument_{};
|
|
257
282
|
std::shared_ptr<sfmljs::ImageState> state_;
|
|
258
283
|
std::shared_ptr<sf::Image> image_;
|
|
@@ -267,11 +292,12 @@ NAN_METHOD(LoadImageStream) {
|
|
|
267
292
|
auto* image = sfmljs::ImageHandle::From(info[0]);
|
|
268
293
|
if (!image) return;
|
|
269
294
|
if (!info[1]->IsFunction() || !info[2]->IsFunction()) {
|
|
270
|
-
return Nan::ThrowTypeError(
|
|
295
|
+
return Nan::ThrowTypeError(
|
|
296
|
+
"Expected stream dispatch and completion callbacks");
|
|
271
297
|
}
|
|
272
298
|
try {
|
|
273
|
-
auto loader = std::make_unique<StreamLoader>(
|
|
274
|
-
info[1].As<v8::Function>(), info[2].As<v8::Function>());
|
|
299
|
+
auto loader = std::make_unique<StreamLoader>(
|
|
300
|
+
image->owner(), info[1].As<v8::Function>(), info[2].As<v8::Function>());
|
|
275
301
|
loader->Start();
|
|
276
302
|
loader.release();
|
|
277
303
|
} catch (const std::exception& error) {
|
package/native/system-binding.cc
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include "exception-boundary.h"
|
|
2
2
|
#include "shared-handle.h"
|
|
3
|
-
|
|
4
3
|
#include <SFML/Config.hpp>
|
|
5
4
|
#include <SFML/System/String.hpp>
|
|
6
5
|
#include <SFML/System/Version.hpp>
|
|
@@ -51,8 +50,9 @@ NAN_METHOD(IsUnicodeBoundary) {
|
|
|
51
50
|
}
|
|
52
51
|
const auto text = sf::String::fromUtf32(points.begin(), points.end());
|
|
53
52
|
const auto kind = Nan::To<std::uint32_t>(info[2]).FromJust();
|
|
54
|
-
info.GetReturnValue().Set(kind == 0
|
|
55
|
-
|
|
53
|
+
info.GetReturnValue().Set(kind == 0 ? text.isGraphemeBoundary(offset)
|
|
54
|
+
: kind == 1 ? text.isWordBoundary(offset)
|
|
55
|
+
: text.isSentenceBoundary(offset));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
NAN_METHOD(GetVersion) {
|
|
@@ -64,21 +64,26 @@ NAN_METHOD(GetVersion) {
|
|
|
64
64
|
static_assert(offsetof(sf::Version, isRelease) == 3);
|
|
65
65
|
static_assert(sizeof(bool) == 1);
|
|
66
66
|
auto result = Nan::New<v8::Object>();
|
|
67
|
-
Nan::Set(result,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
Nan::Set(result,
|
|
68
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
69
|
+
sfmljs::MapShared(info.GetIsolate(), value, value.get(), 4))
|
|
70
|
+
.FromJust();
|
|
71
|
+
Nan::Set(
|
|
72
|
+
result,
|
|
73
|
+
Nan::New("string").ToLocalChecked(),
|
|
74
|
+
Nan::New(value->string.data(), static_cast<int>(value->string.size()))
|
|
75
|
+
.ToLocalChecked())
|
|
76
|
+
.FromJust();
|
|
72
77
|
info.GetReturnValue().Set(result);
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
NAN_METHOD(SuspendAwareClockNow) {
|
|
76
81
|
#ifdef SFML_SYSTEM_ANDROID
|
|
77
|
-
info.GetReturnValue().Set(
|
|
78
|
-
|
|
82
|
+
info.GetReturnValue().Set(
|
|
83
|
+
v8::BigInt::New(info.GetIsolate(),
|
|
84
|
+
sf::SuspendAwareClock::now().time_since_epoch().count()));
|
|
79
85
|
#else
|
|
80
|
-
sfmljs::ThrowError(
|
|
81
|
-
"SuspendAwareClock is only supported by SFML on Android");
|
|
86
|
+
sfmljs::ThrowError("SuspendAwareClock is only supported by SFML on Android");
|
|
82
87
|
#endif
|
|
83
88
|
}
|
|
84
89
|
|
package/native/text-binding.cc
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#include "text-state.h"
|
|
2
1
|
#include "exception-boundary.h"
|
|
2
|
+
#include "text-state.h"
|
|
3
3
|
#include "value-binding.h"
|
|
4
|
-
|
|
5
4
|
#include <SFML/Graphics/Text.hpp>
|
|
6
5
|
|
|
7
6
|
namespace {
|
|
@@ -19,22 +18,34 @@ void Set(v8::Local<v8::Object> object, const char* name, T value) {
|
|
|
19
18
|
v8::Local<v8::Object> MapGlyphs(const std::shared_ptr<GlyphStorage>& storage) {
|
|
20
19
|
auto result = Nan::New<v8::Object>();
|
|
21
20
|
Set(result, "handle", GlyphStorageHandle::Create(storage));
|
|
22
|
-
Set(result,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
Set(result,
|
|
22
|
+
"buffer",
|
|
23
|
+
storage->empty()
|
|
24
|
+
? v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), 0)
|
|
25
|
+
: sfmljs::MapShared(
|
|
26
|
+
v8::Isolate::GetCurrent(),
|
|
27
|
+
storage,
|
|
28
|
+
storage->data(),
|
|
29
|
+
storage->size() * sizeof(sfmljs::ShapedGlyphData)));
|
|
26
30
|
return result;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
v8::Local<v8::Object> Vertices(const sf::VertexArray& input) {
|
|
30
|
-
auto storage =
|
|
34
|
+
auto storage =
|
|
35
|
+
std::make_shared<sfmljs::VertexStorage>(input.getVertexCount());
|
|
31
36
|
for (std::size_t i = 0; i < storage->size(); ++i) (*storage)[i] = input[i];
|
|
32
37
|
auto result = Nan::New<v8::Object>();
|
|
33
|
-
Set(result,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
Set(result,
|
|
39
|
+
"handle",
|
|
40
|
+
sfmljs::SharedHandle<sfmljs::VertexStorage>::Create(storage));
|
|
41
|
+
Set(result,
|
|
42
|
+
"buffer",
|
|
43
|
+
storage->empty()
|
|
44
|
+
? v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), 0)
|
|
45
|
+
: sfmljs::MapShared(v8::Isolate::GetCurrent(),
|
|
46
|
+
storage,
|
|
47
|
+
storage->data(),
|
|
48
|
+
storage->size() * sizeof(sf::Vertex)));
|
|
38
49
|
return result;
|
|
39
50
|
}
|
|
40
51
|
|
|
@@ -54,14 +65,28 @@ NAN_METHOD(CreateText) {
|
|
|
54
65
|
const auto transformable =
|
|
55
66
|
std::shared_ptr<sfmljs::TransformableState>(state, state.get());
|
|
56
67
|
Set(result, "transformable", sfmljs::TransformableHandle(transformable));
|
|
57
|
-
Set(result,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Set(result,
|
|
64
|
-
|
|
68
|
+
Set(result,
|
|
69
|
+
"transform",
|
|
70
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
71
|
+
state,
|
|
72
|
+
state->values.data(),
|
|
73
|
+
sizeof(state->values)));
|
|
74
|
+
Set(result,
|
|
75
|
+
"buffer",
|
|
76
|
+
sfmljs::MapShared(
|
|
77
|
+
info.GetIsolate(), state, members::Properties(state->text), 40));
|
|
78
|
+
Set(result,
|
|
79
|
+
"geometry",
|
|
80
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
81
|
+
state,
|
|
82
|
+
&members::Get<members::GeometryNeedUpdate>(state->text),
|
|
83
|
+
sizeof(bool)));
|
|
84
|
+
Set(result,
|
|
85
|
+
"bounds",
|
|
86
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
87
|
+
state,
|
|
88
|
+
&members::Get<members::Bounds>(state->text),
|
|
89
|
+
sizeof(sf::FloatRect)));
|
|
65
90
|
info.GetReturnValue().Set(result);
|
|
66
91
|
}
|
|
67
92
|
|
|
@@ -85,8 +110,7 @@ NAN_METHOD(PrepareText) {
|
|
|
85
110
|
if (!handle) return;
|
|
86
111
|
auto* font = sfmljs::FontHandle::From(info[1]);
|
|
87
112
|
if (!font) return;
|
|
88
|
-
if (!info[2]->IsString() ||
|
|
89
|
-
(!info[3]->IsNull() && !info[3]->IsFunction())) {
|
|
113
|
+
if (!info[2]->IsString() || (!info[3]->IsNull() && !info[3]->IsFunction())) {
|
|
90
114
|
return Nan::ThrowTypeError("Expected text and pre-processor");
|
|
91
115
|
}
|
|
92
116
|
auto state = handle->owner();
|
|
@@ -106,19 +130,25 @@ NAN_METHOD(PrepareText) {
|
|
|
106
130
|
try {
|
|
107
131
|
if (info[3]->IsFunction()) {
|
|
108
132
|
auto callback = info[3].As<v8::Function>();
|
|
109
|
-
members::Get<members::PreProcessor>(
|
|
110
|
-
const sf::Text::ShapedGlyph& glyph,
|
|
111
|
-
|
|
133
|
+
members::Get<members::PreProcessor>(
|
|
134
|
+
text) = [callback](const sf::Text::ShapedGlyph& glyph,
|
|
135
|
+
std::uint32_t& style,
|
|
136
|
+
sf::Color& fill,
|
|
137
|
+
sf::Color& outline,
|
|
138
|
+
float& thickness) {
|
|
112
139
|
Nan::HandleScope scope;
|
|
113
140
|
// Each callback gets a stable snapshot, even if JS retains it.
|
|
114
141
|
auto snapshot = std::make_shared<GlyphStorage>();
|
|
115
142
|
snapshot->emplace_back(glyph);
|
|
116
|
-
v8::Local<v8::Value> args[] = {MapGlyphs(snapshot),
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
v8::Local<v8::Value> args[] = {MapGlyphs(snapshot),
|
|
144
|
+
Nan::New(style),
|
|
145
|
+
Nan::New(fill.toInteger()),
|
|
146
|
+
Nan::New(outline.toInteger()),
|
|
147
|
+
Nan::New(thickness)};
|
|
119
148
|
v8::Local<v8::Value> result;
|
|
120
149
|
if (!Nan::Call(callback, Nan::GetCurrentContext()->Global(), 5, args)
|
|
121
|
-
.ToLocal(&result))
|
|
150
|
+
.ToLocal(&result))
|
|
151
|
+
throw CallbackFailed{};
|
|
122
152
|
if (!result->IsFloat64Array() ||
|
|
123
153
|
result.As<v8::Float64Array>()->Length() != 4) {
|
|
124
154
|
Nan::ThrowTypeError("Invalid glyph pre-processor result");
|
|
@@ -149,10 +179,13 @@ NAN_METHOD(PrepareText) {
|
|
|
149
179
|
NAN_METHOD(GetTextGlyphs) {
|
|
150
180
|
auto* handle = Handle::From(info[0]);
|
|
151
181
|
if (!handle) return;
|
|
152
|
-
if (!handle->owner()->glyphs)
|
|
182
|
+
if (!handle->owner()->glyphs)
|
|
183
|
+
return sfmljs::ThrowError("Text is not prepared");
|
|
153
184
|
try {
|
|
154
185
|
info.GetReturnValue().Set(MapGlyphs(handle->owner()->glyphs));
|
|
155
|
-
} catch (const std::exception& error) {
|
|
186
|
+
} catch (const std::exception& error) {
|
|
187
|
+
sfmljs::ThrowError(error.what());
|
|
188
|
+
}
|
|
156
189
|
}
|
|
157
190
|
|
|
158
191
|
NAN_METHOD(ShapedGlyphMember) {
|
|
@@ -169,11 +202,11 @@ NAN_METHOD(ShapedGlyphMember) {
|
|
|
169
202
|
}
|
|
170
203
|
auto& glyph = (*storage)[index];
|
|
171
204
|
if (member == 0) {
|
|
172
|
-
sfmljs::values::ReturnMapped(
|
|
173
|
-
std::shared_ptr<sf::Glyph>(storage, &glyph.glyph));
|
|
205
|
+
sfmljs::values::ReturnMapped(
|
|
206
|
+
info, std::shared_ptr<sf::Glyph>(storage, &glyph.glyph));
|
|
174
207
|
} else {
|
|
175
|
-
sfmljs::values::ReturnMapped(
|
|
176
|
-
std::shared_ptr<sf::Vector2f>(storage, &glyph.position));
|
|
208
|
+
sfmljs::values::ReturnMapped(
|
|
209
|
+
info, std::shared_ptr<sf::Vector2f>(storage, &glyph.position));
|
|
177
210
|
}
|
|
178
211
|
}
|
|
179
212
|
|
package/native/text-state.h
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
|
|
3
7
|
#include "font-state.h"
|
|
4
8
|
#include "shaped-glyph-storage.h"
|
|
5
9
|
#include "vertex-storage.h"
|
|
6
|
-
|
|
7
10
|
#include <SFML/Graphics/Text.hpp>
|
|
8
11
|
|
|
9
|
-
#include <array>
|
|
10
|
-
#include <memory>
|
|
11
|
-
#include <stdexcept>
|
|
12
|
-
|
|
13
12
|
namespace sfmljs {
|
|
14
13
|
namespace text_members {
|
|
15
14
|
|
|
@@ -21,11 +20,11 @@ struct Access {
|
|
|
21
20
|
friend typename Tag::Type Member(Tag) { return Pointer; }
|
|
22
21
|
};
|
|
23
22
|
|
|
24
|
-
#define SFMLJS_TEXT_MEMBER(Tag, Value, Name)
|
|
25
|
-
struct Tag {
|
|
26
|
-
using Type = Value sf::Text::*;
|
|
27
|
-
friend Type Member(Tag);
|
|
28
|
-
};
|
|
23
|
+
#define SFMLJS_TEXT_MEMBER(Tag, Value, Name) \
|
|
24
|
+
struct Tag { \
|
|
25
|
+
using Type = Value sf::Text::*; \
|
|
26
|
+
friend Type Member(Tag); \
|
|
27
|
+
}; \
|
|
29
28
|
template struct Access<Tag, &sf::Text::Name>
|
|
30
29
|
|
|
31
30
|
SFMLJS_TEXT_MEMBER(CharacterSize, unsigned int, m_characterSize);
|
|
@@ -40,28 +39,36 @@ SFMLJS_TEXT_MEMBER(Orientation, sf::Text::TextOrientation, m_textOrientation);
|
|
|
40
39
|
SFMLJS_TEXT_MEMBER(Grouping, sf::Text::ClusterGrouping, m_clusterGrouping);
|
|
41
40
|
SFMLJS_TEXT_MEMBER(GeometryNeedUpdate, bool, m_geometryNeedUpdate);
|
|
42
41
|
SFMLJS_TEXT_MEMBER(Bounds, sf::FloatRect, m_bounds);
|
|
43
|
-
SFMLJS_TEXT_MEMBER(PreProcessor,
|
|
42
|
+
SFMLJS_TEXT_MEMBER(PreProcessor,
|
|
43
|
+
sf::Text::GlyphPreProcessor,
|
|
44
|
+
m_glyphPreProcessor);
|
|
44
45
|
|
|
45
46
|
#undef SFMLJS_TEXT_MEMBER
|
|
46
47
|
|
|
47
48
|
template <typename Tag>
|
|
48
|
-
decltype(auto) Get(sf::Text& text,
|
|
49
|
+
decltype(auto) Get(sf::Text& text, // NOLINT(runtime/references)
|
|
50
|
+
Tag tag = {}) {
|
|
49
51
|
return text.*Member(tag);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
// These ten real SFML fields form the exposed 40-byte numeric region.
|
|
53
55
|
// Check every member address before creating any view.
|
|
54
|
-
inline void* Properties(sf::Text& text) {
|
|
56
|
+
inline void* Properties(sf::Text& text) { // NOLINT(runtime/references)
|
|
55
57
|
static_assert(sizeof(unsigned int) == 4 && sizeof(float) == 4);
|
|
56
58
|
static_assert(sizeof(sf::Color) == 4 && sizeof(bool) == 1);
|
|
57
59
|
static_assert(sizeof(sf::Text::LineAlignment) == 4);
|
|
58
60
|
static_assert(sizeof(sf::Text::TextOrientation) == 4);
|
|
59
61
|
static_assert(sizeof(sf::Text::ClusterGrouping) == 4);
|
|
60
|
-
const std::array<const void*, 10> fields{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const std::array<const void*, 10> fields{&Get<CharacterSize>(text),
|
|
63
|
+
&Get<LetterSpacing>(text),
|
|
64
|
+
&Get<LineSpacing>(text),
|
|
65
|
+
&Get<Style>(text),
|
|
66
|
+
&Get<FillColor>(text),
|
|
67
|
+
&Get<OutlineColor>(text),
|
|
68
|
+
&Get<OutlineThickness>(text),
|
|
69
|
+
&Get<LineAlignment>(text),
|
|
70
|
+
&Get<Orientation>(text),
|
|
71
|
+
&Get<Grouping>(text)};
|
|
65
72
|
const auto start = reinterpret_cast<std::uintptr_t>(fields[0]);
|
|
66
73
|
for (std::size_t i = 0; i < fields.size(); ++i) {
|
|
67
74
|
if (reinterpret_cast<std::uintptr_t>(fields[i]) != start + i * 4) {
|