sfml.js 1.0.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <cmath>
|
|
2
2
|
|
|
3
|
+
#include "../../native/graphics-state.h"
|
|
3
4
|
#include <SFML/Graphics/Image.hpp>
|
|
4
5
|
|
|
5
|
-
#include <cmath>
|
|
6
|
-
|
|
7
6
|
namespace {
|
|
8
7
|
|
|
9
8
|
using sfmljs::SharedHandle;
|
|
@@ -27,20 +26,27 @@ v8::Local<v8::Array> Rect(const sf::Rect<T>& rectangle) {
|
|
|
27
26
|
|
|
28
27
|
v8::Local<v8::Object> Describe(const sf::Sprite& sprite) {
|
|
29
28
|
auto result = Nan::New<v8::Object>();
|
|
30
|
-
Nan::Set(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Nan::Set(result,
|
|
37
|
-
Nan::New(
|
|
29
|
+
Nan::Set(
|
|
30
|
+
result, Nan::New("rect").ToLocalChecked(), Rect(sprite.getTextureRect()))
|
|
31
|
+
.FromJust();
|
|
32
|
+
Nan::Set(
|
|
33
|
+
result, Nan::New("local").ToLocalChecked(), Rect(sprite.getLocalBounds()))
|
|
34
|
+
.FromJust();
|
|
35
|
+
Nan::Set(result,
|
|
36
|
+
Nan::New("global").ToLocalChecked(),
|
|
37
|
+
Rect(sprite.getGlobalBounds()))
|
|
38
|
+
.FromJust();
|
|
39
|
+
Nan::Set(result,
|
|
40
|
+
Nan::New("color").ToLocalChecked(),
|
|
41
|
+
Nan::New(sprite.getColor().toInteger()))
|
|
42
|
+
.FromJust();
|
|
38
43
|
return result;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
// Independently build immediate SFML state, without ApplyTransform/Appearance.
|
|
42
|
-
bool Configure(sf::Sprite& sprite,
|
|
43
|
-
|
|
47
|
+
bool Configure(sf::Sprite& sprite, // NOLINT(runtime/references)
|
|
48
|
+
v8::Local<v8::Object> input,
|
|
49
|
+
sf::RenderStates& states) { // NOLINT(runtime/references)
|
|
44
50
|
const auto rectangle = Get(input, "rect");
|
|
45
51
|
const auto transform = Get(input, "transform");
|
|
46
52
|
const auto color = Get(input, "color");
|
|
@@ -75,10 +81,15 @@ bool Configure(sf::Sprite& sprite, v8::Local<v8::Object> input,
|
|
|
75
81
|
}
|
|
76
82
|
std::array<float, 16> matrix{};
|
|
77
83
|
parent.As<v8::Float32Array>()->CopyContents(matrix.data(), sizeof(matrix));
|
|
78
|
-
states.transform = sf::Transform(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
states.transform = sf::Transform(matrix[0],
|
|
85
|
+
matrix[4],
|
|
86
|
+
matrix[12],
|
|
87
|
+
matrix[1],
|
|
88
|
+
matrix[5],
|
|
89
|
+
matrix[13],
|
|
90
|
+
matrix[3],
|
|
91
|
+
matrix[7],
|
|
92
|
+
matrix[15]);
|
|
82
93
|
}
|
|
83
94
|
return true;
|
|
84
95
|
}
|
|
@@ -112,9 +123,10 @@ NAN_METHOD(RenderSpriteAppearanceOracle) {
|
|
|
112
123
|
}
|
|
113
124
|
target.display();
|
|
114
125
|
const auto image = target.getTexture().copyToImage();
|
|
115
|
-
info.GetReturnValue().Set(
|
|
116
|
-
reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
117
|
-
|
|
126
|
+
info.GetReturnValue().Set(
|
|
127
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
128
|
+
64 * 64 * 4)
|
|
129
|
+
.ToLocalChecked());
|
|
118
130
|
}
|
|
119
131
|
|
|
120
132
|
NAN_METHOD(ReadSpriteAppearance) {
|
|
@@ -122,9 +134,11 @@ NAN_METHOD(ReadSpriteAppearance) {
|
|
|
122
134
|
if (!handle) return;
|
|
123
135
|
if (info[1]->IsTrue()) handle->owner()->SyncSprite();
|
|
124
136
|
auto result = Describe(*handle->owner());
|
|
125
|
-
Nan::Set(result,
|
|
137
|
+
Nan::Set(result,
|
|
138
|
+
Nan::New("currentTexture").ToLocalChecked(),
|
|
126
139
|
Nan::New(&handle->owner()->getTexture() ==
|
|
127
|
-
handle->owner()->texture.get()))
|
|
140
|
+
handle->owner()->texture.get()))
|
|
141
|
+
.FromJust();
|
|
128
142
|
info.GetReturnValue().Set(result);
|
|
129
143
|
}
|
|
130
144
|
|
|
@@ -132,15 +146,17 @@ NAN_METHOD(SpriteRectSharesStorage) {
|
|
|
132
146
|
auto* sprite = SharedHandle<sfmljs::SpriteState>::From(info[0]);
|
|
133
147
|
if (!sprite) return;
|
|
134
148
|
auto* rectangle = SharedHandle<sf::IntRect>::From(info[1]);
|
|
135
|
-
if (rectangle)
|
|
136
|
-
|
|
149
|
+
if (rectangle)
|
|
150
|
+
info.GetReturnValue().Set(rectangle->owner().get() ==
|
|
151
|
+
&sprite->owner()->appearance.rectangle);
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
} // namespace
|
|
140
155
|
|
|
141
156
|
NAN_MODULE_INIT(InitializeSpriteProbes) {
|
|
142
157
|
Nan::SetMethod(target, "evaluateSprite", EvaluateSprite);
|
|
143
|
-
Nan::SetMethod(
|
|
158
|
+
Nan::SetMethod(
|
|
159
|
+
target, "renderSpriteAppearanceOracle", RenderSpriteAppearanceOracle);
|
|
144
160
|
Nan::SetMethod(target, "readSpriteAppearance", ReadSpriteAppearance);
|
|
145
161
|
Nan::SetMethod(target, "spriteRectSharesStorage", SpriteRectSharesStorage);
|
|
146
162
|
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
#include
|
|
2
|
-
#include "../../native/time-value.h"
|
|
1
|
+
#include <functional>
|
|
3
2
|
|
|
3
|
+
#include "../../native/time-value.h"
|
|
4
|
+
#include "exception-boundary.h"
|
|
4
5
|
#include <SFML/Config.hpp>
|
|
5
6
|
#include <SFML/System/SuspendAwareClock.hpp>
|
|
6
7
|
#include <SFML/System/TimeoutWithPredicate.hpp>
|
|
7
8
|
#include <SFML/System/Version.hpp>
|
|
8
9
|
|
|
9
|
-
#include <functional>
|
|
10
|
-
|
|
11
10
|
namespace {
|
|
12
11
|
|
|
13
12
|
NAN_METHOD(InspectVersion) {
|
|
14
13
|
const auto& version = sf::version();
|
|
15
14
|
auto result = Nan::New<v8::Object>();
|
|
16
|
-
Nan::Set(result,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Nan::Set(result,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Nan::Set(result,
|
|
15
|
+
Nan::Set(result,
|
|
16
|
+
Nan::New("major").ToLocalChecked(),
|
|
17
|
+
Nan::New(static_cast<int>(version.major)))
|
|
18
|
+
.FromJust();
|
|
19
|
+
Nan::Set(result,
|
|
20
|
+
Nan::New("minor").ToLocalChecked(),
|
|
21
|
+
Nan::New(static_cast<int>(version.minor)))
|
|
22
|
+
.FromJust();
|
|
23
|
+
Nan::Set(result,
|
|
24
|
+
Nan::New("patch").ToLocalChecked(),
|
|
25
|
+
Nan::New(static_cast<int>(version.patch)))
|
|
26
|
+
.FromJust();
|
|
27
|
+
Nan::Set(result,
|
|
28
|
+
Nan::New("isRelease").ToLocalChecked(),
|
|
29
|
+
Nan::New(version.isRelease))
|
|
30
|
+
.FromJust();
|
|
31
|
+
Nan::Set(
|
|
32
|
+
result,
|
|
33
|
+
Nan::New("string").ToLocalChecked(),
|
|
25
34
|
Nan::New(version.string.data(), static_cast<int>(version.string.size()))
|
|
26
|
-
.ToLocalChecked())
|
|
35
|
+
.ToLocalChecked())
|
|
36
|
+
.FromJust();
|
|
27
37
|
info.GetReturnValue().Set(result);
|
|
28
38
|
}
|
|
29
39
|
|
|
@@ -43,8 +53,9 @@ NAN_METHOD(InspectTimeoutWithPredicate) {
|
|
|
43
53
|
predicate = [&] {
|
|
44
54
|
++calls;
|
|
45
55
|
v8::Local<v8::Value> value;
|
|
46
|
-
if (!info[0]
|
|
47
|
-
|
|
56
|
+
if (!info[0]
|
|
57
|
+
.As<v8::Function>()
|
|
58
|
+
->Call(Nan::GetCurrentContext(), Nan::Undefined(), 0, nullptr)
|
|
48
59
|
.ToLocal(&value)) {
|
|
49
60
|
failed = true;
|
|
50
61
|
return false;
|
|
@@ -62,31 +73,39 @@ NAN_METHOD(InspectTimeoutWithPredicate) {
|
|
|
62
73
|
const auto& storedPredicate = timeout.getPredicate();
|
|
63
74
|
const auto& storedPeriod = timeout.getPeriod();
|
|
64
75
|
auto result = Nan::New<v8::Object>();
|
|
65
|
-
Nan::Set(result,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Nan::Set(result,
|
|
76
|
+
Nan::Set(result,
|
|
77
|
+
Nan::New("period").ToLocalChecked(),
|
|
78
|
+
sfmljs::WriteTime(info.GetIsolate(), storedPeriod))
|
|
79
|
+
.FromJust();
|
|
80
|
+
Nan::Set(result,
|
|
81
|
+
Nan::New("hasPredicate").ToLocalChecked(),
|
|
82
|
+
Nan::New(static_cast<bool>(storedPredicate)))
|
|
83
|
+
.FromJust();
|
|
84
|
+
Nan::Set(result,
|
|
85
|
+
Nan::New("stableGetters").ToLocalChecked(),
|
|
70
86
|
Nan::New(&storedPredicate == &timeout.getPredicate() &&
|
|
71
|
-
&storedPeriod == &timeout.getPeriod()))
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
&storedPeriod == &timeout.getPeriod()))
|
|
88
|
+
.FromJust();
|
|
89
|
+
Nan::Set(result, Nan::New("callsBefore").ToLocalChecked(), Nan::New(calls))
|
|
90
|
+
.FromJust();
|
|
74
91
|
auto evaluations = Nan::New<v8::Array>(3);
|
|
75
92
|
for (std::uint32_t i = 0; i < 3; ++i) {
|
|
76
93
|
const bool value = storedPredicate();
|
|
77
94
|
if (failed) return; // Preserve the original pending JS exception.
|
|
78
95
|
Nan::Set(evaluations, i, Nan::New(value)).FromJust();
|
|
79
96
|
}
|
|
80
|
-
Nan::Set(result, Nan::New("results").ToLocalChecked(), evaluations)
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
Nan::Set(result, Nan::New("results").ToLocalChecked(), evaluations)
|
|
98
|
+
.FromJust();
|
|
99
|
+
Nan::Set(result, Nan::New("callsAfter").ToLocalChecked(), Nan::New(calls))
|
|
100
|
+
.FromJust();
|
|
83
101
|
info.GetReturnValue().Set(result);
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
#ifdef SFML_SYSTEM_ANDROID
|
|
87
105
|
NAN_METHOD(SuspendAwareClockOracle) {
|
|
88
|
-
info.GetReturnValue().Set(
|
|
89
|
-
|
|
106
|
+
info.GetReturnValue().Set(
|
|
107
|
+
v8::BigInt::New(info.GetIsolate(),
|
|
108
|
+
sf::SuspendAwareClock::now().time_since_epoch().count()));
|
|
90
109
|
}
|
|
91
110
|
#endif
|
|
92
111
|
|
|
@@ -94,16 +113,20 @@ NAN_METHOD(SuspendAwareClockOracle) {
|
|
|
94
113
|
|
|
95
114
|
NAN_MODULE_INIT(InitializeSystemProbes) {
|
|
96
115
|
sfmljs::SetMethod<InspectVersion>(target, "inspectVersion");
|
|
97
|
-
sfmljs::SetMethod<InspectTimeoutWithPredicate>(
|
|
98
|
-
|
|
99
|
-
Nan::Set(target,
|
|
100
|
-
Nan::New(
|
|
116
|
+
sfmljs::SetMethod<InspectTimeoutWithPredicate>(target,
|
|
117
|
+
"inspectTimeoutWithPredicate");
|
|
118
|
+
Nan::Set(target,
|
|
119
|
+
Nan::New("suspendAwareClockSteady").ToLocalChecked(),
|
|
120
|
+
Nan::New(sf::SuspendAwareClock::is_steady))
|
|
121
|
+
.FromJust();
|
|
101
122
|
#ifdef SFML_SYSTEM_ANDROID
|
|
102
123
|
constexpr bool supported = true;
|
|
103
124
|
sfmljs::SetMethod<SuspendAwareClockOracle>(target, "suspendAwareClockOracle");
|
|
104
125
|
#else
|
|
105
126
|
constexpr bool supported = false;
|
|
106
127
|
#endif
|
|
107
|
-
Nan::Set(target,
|
|
108
|
-
Nan::New(
|
|
128
|
+
Nan::Set(target,
|
|
129
|
+
Nan::New("suspendAwareClockSupported").ToLocalChecked(),
|
|
130
|
+
Nan::New(supported))
|
|
131
|
+
.FromJust();
|
|
109
132
|
}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
#include "../../native/font-state.h"
|
|
2
|
-
#include "../../native/text-state.h"
|
|
3
|
-
#include "../../native/exception-boundary.h"
|
|
4
2
|
#include "../../native/shaped-glyph-storage.h"
|
|
3
|
+
#include "../../native/text-state.h"
|
|
5
4
|
#include "../../native/value-binding.h"
|
|
6
|
-
#include
|
|
5
|
+
#include "exception-boundary.h"
|
|
7
6
|
#include <SFML/Graphics/Image.hpp>
|
|
7
|
+
#include <SFML/Graphics/Text.hpp>
|
|
8
8
|
|
|
9
9
|
namespace {
|
|
10
10
|
v8::Local<v8::Value> Get(v8::Local<v8::Object> object, const char* name) {
|
|
11
11
|
return Nan::Get(object, Nan::New(name).ToLocalChecked()).ToLocalChecked();
|
|
12
12
|
}
|
|
13
|
-
void Set(v8::Local<v8::Object> object,
|
|
13
|
+
void Set(v8::Local<v8::Object> object,
|
|
14
|
+
const char* name,
|
|
15
|
+
v8::Local<v8::Value> value) {
|
|
14
16
|
Nan::Set(object, Nan::New(name).ToLocalChecked(), value).FromJust();
|
|
15
17
|
}
|
|
16
18
|
v8::Local<v8::Array> Box(sf::FloatRect box) {
|
|
17
19
|
auto result = Nan::New<v8::Array>(4);
|
|
18
|
-
const float values[] = {
|
|
19
|
-
|
|
20
|
+
const float values[] = {
|
|
21
|
+
box.position.x, box.position.y, box.size.x, box.size.y};
|
|
22
|
+
for (unsigned i = 0; i < 4; ++i)
|
|
23
|
+
Nan::Set(result, i, Nan::New(values[i])).FromJust();
|
|
20
24
|
return result;
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -33,7 +37,8 @@ NAN_METHOD(TextOracle) {
|
|
|
33
37
|
Nan::TypedArrayContents<double> props(Get(input, "properties"));
|
|
34
38
|
const auto* p = *props;
|
|
35
39
|
sf::Text text(font->owner()->current->font,
|
|
36
|
-
|
|
40
|
+
sf::String::fromUtf8(*string, *string + string.length()),
|
|
41
|
+
p[0]);
|
|
37
42
|
text.setLetterSpacing(p[1]);
|
|
38
43
|
text.setLineSpacing(p[2]);
|
|
39
44
|
text.setStyle(p[3]);
|
|
@@ -45,7 +50,10 @@ NAN_METHOD(TextOracle) {
|
|
|
45
50
|
text.setClusterGrouping(static_cast<sf::Text::ClusterGrouping>(p[9]));
|
|
46
51
|
if (Nan::To<bool>(Get(input, "processor")).FromJust()) {
|
|
47
52
|
text.setGlyphPreProcessor([](const sf::Text::ShapedGlyph& glyph,
|
|
48
|
-
|
|
53
|
+
std::uint32_t& style,
|
|
54
|
+
sf::Color& fill,
|
|
55
|
+
sf::Color& outline,
|
|
56
|
+
float& thickness) {
|
|
49
57
|
if (glyph.cluster % 2 == 0) {
|
|
50
58
|
style |= sf::Text::Bold;
|
|
51
59
|
fill = sf::Color::Red;
|
|
@@ -61,21 +69,32 @@ NAN_METHOD(TextOracle) {
|
|
|
61
69
|
text.setOrigin({(*pose)[5], (*pose)[6]});
|
|
62
70
|
Nan::TypedArrayContents<float> matrix(Get(input, "parent"));
|
|
63
71
|
sf::RenderStates states;
|
|
64
|
-
states.transform = sf::Transform(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
states.transform = sf::Transform((*matrix)[0],
|
|
73
|
+
(*matrix)[4],
|
|
74
|
+
(*matrix)[12],
|
|
75
|
+
(*matrix)[1],
|
|
76
|
+
(*matrix)[5],
|
|
77
|
+
(*matrix)[13],
|
|
78
|
+
(*matrix)[3],
|
|
79
|
+
(*matrix)[7],
|
|
80
|
+
(*matrix)[15]);
|
|
68
81
|
auto description = Nan::New<v8::Object>();
|
|
69
82
|
Set(description, "local", Box(text.getLocalBounds()));
|
|
70
83
|
Set(description, "global", Box(text.getGlobalBounds()));
|
|
71
84
|
auto glyphs = Nan::New<v8::Array>(text.getShapedGlyphs().size());
|
|
72
85
|
unsigned j = 0;
|
|
73
86
|
for (const auto& glyph : text.getShapedGlyphs()) {
|
|
74
|
-
const double data[]
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
const double data[]{glyph.position.x,
|
|
88
|
+
glyph.position.y,
|
|
89
|
+
static_cast<double>(glyph.cluster),
|
|
90
|
+
static_cast<double>(glyph.textDirection),
|
|
91
|
+
glyph.baseline,
|
|
92
|
+
static_cast<double>(glyph.vertexOffset),
|
|
93
|
+
static_cast<double>(glyph.vertexCount),
|
|
94
|
+
glyph.glyph.advance};
|
|
77
95
|
auto value = Nan::New<v8::Array>(8);
|
|
78
|
-
for (unsigned k = 0; k < 8; ++k)
|
|
96
|
+
for (unsigned k = 0; k < 8; ++k)
|
|
97
|
+
Nan::Set(value, k, Nan::New(data[k])).FromJust();
|
|
79
98
|
Nan::Set(glyphs, j++, value).FromJust();
|
|
80
99
|
}
|
|
81
100
|
Set(description, "glyphs", glyphs);
|
|
@@ -96,8 +115,11 @@ NAN_METHOD(TextOracle) {
|
|
|
96
115
|
const auto image = target.getTexture().copyToImage();
|
|
97
116
|
auto result = Nan::New<v8::Object>();
|
|
98
117
|
Set(result, "descriptions", descriptions);
|
|
99
|
-
Set(result,
|
|
100
|
-
|
|
118
|
+
Set(result,
|
|
119
|
+
"pixels",
|
|
120
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
121
|
+
320 * 200 * 4)
|
|
122
|
+
.ToLocalChecked());
|
|
101
123
|
info.GetReturnValue().Set(result);
|
|
102
124
|
}
|
|
103
125
|
|
|
@@ -106,15 +128,16 @@ NAN_METHOD(GlyphAliases) {
|
|
|
106
128
|
auto* bounds = sfmljs::SharedHandle<sf::FloatRect>::From(info[1]);
|
|
107
129
|
auto* texture = sfmljs::SharedHandle<sf::IntRect>::From(info[2]);
|
|
108
130
|
if (!glyph || !bounds || !texture) return;
|
|
109
|
-
info.GetReturnValue().Set(
|
|
110
|
-
|
|
111
|
-
|
|
131
|
+
info.GetReturnValue().Set(&glyph->owner()->bounds == bounds->owner().get() &&
|
|
132
|
+
&glyph->owner()->textureRect ==
|
|
133
|
+
texture->owner().get());
|
|
112
134
|
}
|
|
113
135
|
|
|
114
136
|
NAN_METHOD(ReadGlyph) {
|
|
115
137
|
auto* glyph = sfmljs::SharedHandle<sf::Glyph>::From(info[0]);
|
|
116
138
|
if (!glyph) return;
|
|
117
|
-
const auto* bytes =
|
|
139
|
+
const auto* bytes =
|
|
140
|
+
reinterpret_cast<const unsigned char*>(glyph->owner().get());
|
|
118
141
|
auto result = Nan::New<v8::Array>(sizeof(sf::Glyph));
|
|
119
142
|
for (unsigned i = 0; i < sizeof(sf::Glyph); ++i) {
|
|
120
143
|
Nan::Set(result, i, Nan::New(bytes[i])).FromJust();
|
|
@@ -123,17 +146,18 @@ NAN_METHOD(ReadGlyph) {
|
|
|
123
146
|
}
|
|
124
147
|
|
|
125
148
|
NAN_METHOD(ShapedGlyphAliases) {
|
|
126
|
-
auto* storage =
|
|
149
|
+
auto* storage =
|
|
150
|
+
sfmljs::SharedHandle<sfmljs::ShapedGlyphStorage>::From(info[0]);
|
|
127
151
|
if (!storage || !info[1]->IsUint32()) return;
|
|
128
152
|
const auto index = Nan::To<std::uint32_t>(info[1]).FromJust();
|
|
129
|
-
if (index >= storage->owner()->size())
|
|
153
|
+
if (index >= storage->owner()->size())
|
|
154
|
+
return Nan::ThrowRangeError("Invalid index");
|
|
130
155
|
auto* glyph = sfmljs::SharedHandle<sf::Glyph>::From(info[2]);
|
|
131
156
|
auto* position = sfmljs::SharedHandle<sf::Vector2f>::From(info[3]);
|
|
132
157
|
if (!glyph || !position) return;
|
|
133
158
|
const auto& entry = (*storage->owner())[index];
|
|
134
|
-
info.GetReturnValue().Set(
|
|
135
|
-
|
|
136
|
-
&entry.position == position->owner().get());
|
|
159
|
+
info.GetReturnValue().Set(&entry.glyph == glyph->owner().get() &&
|
|
160
|
+
&entry.position == position->owner().get());
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
NAN_METHOD(InspectTextState) {
|
|
@@ -141,26 +165,33 @@ NAN_METHOD(InspectTextState) {
|
|
|
141
165
|
if (!handle) return;
|
|
142
166
|
auto& state = *handle->owner();
|
|
143
167
|
auto& text = state.text;
|
|
144
|
-
const double values[]
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
const double values[]{static_cast<double>(text.getCharacterSize()),
|
|
169
|
+
text.getLetterSpacing(),
|
|
170
|
+
text.getLineSpacing(),
|
|
171
|
+
static_cast<double>(text.getStyle()),
|
|
172
|
+
static_cast<double>(text.getFillColor().toInteger()),
|
|
173
|
+
static_cast<double>(text.getOutlineColor().toInteger()),
|
|
174
|
+
text.getOutlineThickness(),
|
|
175
|
+
static_cast<double>(text.getLineAlignment()),
|
|
176
|
+
static_cast<double>(text.getTextOrientation()),
|
|
177
|
+
static_cast<double>(text.getClusterGrouping())};
|
|
151
178
|
auto result = Nan::New<v8::Object>();
|
|
152
179
|
auto properties = Nan::New<v8::Array>(10);
|
|
153
180
|
for (unsigned i = 0; i < 10; ++i) {
|
|
154
181
|
Nan::Set(properties, i, Nan::New(values[i])).FromJust();
|
|
155
182
|
}
|
|
156
183
|
Set(result, "properties", properties);
|
|
157
|
-
Set(result,
|
|
158
|
-
|
|
184
|
+
Set(result,
|
|
185
|
+
"address",
|
|
186
|
+
v8::BigInt::NewFromUnsigned(info.GetIsolate(),
|
|
187
|
+
reinterpret_cast<std::uintptr_t>(&text)));
|
|
159
188
|
namespace members = sfmljs::text_members;
|
|
160
|
-
Set(result,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
189
|
+
Set(result,
|
|
190
|
+
"needsUpdate",
|
|
191
|
+
Nan::New(members::Get<members::GeometryNeedUpdate>(text)));
|
|
192
|
+
Set(result,
|
|
193
|
+
"hasProcessor",
|
|
194
|
+
Nan::New(static_cast<bool>(members::Get<members::PreProcessor>(text))));
|
|
164
195
|
Set(result, "bounds", Box(members::Get<members::Bounds>(text)));
|
|
165
196
|
if (!info[1]->IsUndefined()) {
|
|
166
197
|
auto* transform =
|
|
@@ -168,9 +199,10 @@ NAN_METHOD(InspectTextState) {
|
|
|
168
199
|
if (!transform) return;
|
|
169
200
|
const auto& a = handle->owner();
|
|
170
201
|
const auto& b = transform->owner();
|
|
171
|
-
Set(result,
|
|
172
|
-
|
|
173
|
-
b
|
|
202
|
+
Set(result,
|
|
203
|
+
"sharesTransform",
|
|
204
|
+
Nan::New(!a.owner_before(b) && !b.owner_before(a) &&
|
|
205
|
+
b->object == &text && b.get() == &state));
|
|
174
206
|
}
|
|
175
207
|
info.GetReturnValue().Set(result);
|
|
176
208
|
}
|
|
@@ -178,7 +210,8 @@ NAN_METHOD(InspectTextState) {
|
|
|
178
210
|
NAN_METHOD(SetTextCharacterSize) {
|
|
179
211
|
auto* handle = sfmljs::TextHandle::From(info[0]);
|
|
180
212
|
if (!handle || !info[1]->IsUint32()) return;
|
|
181
|
-
handle->owner()->text.setCharacterSize(
|
|
213
|
+
handle->owner()->text.setCharacterSize(
|
|
214
|
+
Nan::To<std::uint32_t>(info[1]).FromJust());
|
|
182
215
|
}
|
|
183
216
|
|
|
184
217
|
struct TextLifetime {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include "../../native/image-state.h"
|
|
2
2
|
#include "../../native/texture-resource.h"
|
|
3
|
-
|
|
4
3
|
#include <SFML/Graphics/RenderTexture.hpp>
|
|
5
4
|
#include <SFML/Graphics/Texture.hpp>
|
|
6
5
|
#include <SFML/Graphics/VertexArray.hpp>
|
|
@@ -19,8 +18,8 @@ NAN_METHOD(PaintWindow) {
|
|
|
19
18
|
if (!window->owner()->setActive()) return Nan::ThrowError("Inactive window");
|
|
20
19
|
const auto clearColor = reinterpret_cast<decltype(&glClearColor)>(
|
|
21
20
|
sf::Context::getFunction("glClearColor"));
|
|
22
|
-
const auto clear =
|
|
23
|
-
sf::Context::getFunction("glClear"));
|
|
21
|
+
const auto clear =
|
|
22
|
+
reinterpret_cast<decltype(&glClear)>(sf::Context::getFunction("glClear"));
|
|
24
23
|
const auto enable = reinterpret_cast<decltype(&glEnable)>(
|
|
25
24
|
sf::Context::getFunction("glEnable"));
|
|
26
25
|
const auto disable = reinterpret_cast<decltype(&glDisable)>(
|
|
@@ -52,12 +51,16 @@ NAN_METHOD(ReadTextureBinding) {
|
|
|
52
51
|
for (std::uint32_t i = 0; i < 16; ++i) {
|
|
53
52
|
Nan::Set(values, i, Nan::New(matrix[i])).FromJust();
|
|
54
53
|
}
|
|
55
|
-
Nan::Set(result,
|
|
56
|
-
Nan::New(
|
|
54
|
+
Nan::Set(result,
|
|
55
|
+
Nan::New("binding").ToLocalChecked(),
|
|
56
|
+
Nan::New(static_cast<std::uint32_t>(binding)))
|
|
57
|
+
.FromJust();
|
|
57
58
|
Nan::Set(result, Nan::New("matrix").ToLocalChecked(), values).FromJust();
|
|
58
|
-
Nan::Set(result,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
Nan::Set(result,
|
|
60
|
+
Nan::New("context").ToLocalChecked(),
|
|
61
|
+
v8::BigInt::NewFromUnsigned(info.GetIsolate(),
|
|
62
|
+
sf::Context::getActiveContextId()))
|
|
63
|
+
.FromJust();
|
|
61
64
|
info.GetReturnValue().Set(result);
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -89,8 +92,8 @@ NAN_METHOD(LoadTextureAreaOracle) {
|
|
|
89
92
|
{Nan::To<int>(info[3]).FromJust(), Nan::To<int>(info[4]).FromJust()}};
|
|
90
93
|
sf::Texture texture;
|
|
91
94
|
if (!texture.loadFromImage(*image->owner()->current, false, area)) return;
|
|
92
|
-
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
93
|
-
std::make_shared<sf::Image>(texture.copyToImage())));
|
|
95
|
+
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
96
|
+
info.GetIsolate(), std::make_shared<sf::Image>(texture.copyToImage())));
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
// Immediate SFML draws, with sampling changed between the two rows.
|
|
@@ -110,12 +113,15 @@ NAN_METHOD(RenderTextureSamplingOracle) {
|
|
|
110
113
|
quad[3] = {{8, 1}, sf::Color::White, {edge, 1}};
|
|
111
114
|
sf::RenderStates states(&texture);
|
|
112
115
|
target.draw(quad, states);
|
|
113
|
-
if (repeat)
|
|
114
|
-
|
|
116
|
+
if (repeat)
|
|
117
|
+
texture.setRepeated(true);
|
|
118
|
+
else
|
|
119
|
+
texture.setSmooth(true);
|
|
115
120
|
states.transform.translate({0, 1});
|
|
116
121
|
target.draw(quad, states);
|
|
117
122
|
target.display();
|
|
118
|
-
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
123
|
+
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
124
|
+
info.GetIsolate(),
|
|
119
125
|
std::make_shared<sf::Image>(target.getTexture().copyToImage())));
|
|
120
126
|
}
|
|
121
127
|
|
|
@@ -129,9 +135,10 @@ NAN_METHOD(RenderTextureMipmapOracle) {
|
|
|
129
135
|
if (!info[2]->IsUint32()) return Nan::ThrowTypeError("Expected update mode");
|
|
130
136
|
const auto mode = Nan::To<std::uint32_t>(info[2]).FromJust();
|
|
131
137
|
if (mode > 4) return Nan::ThrowRangeError("Invalid update mode");
|
|
138
|
+
const sf::Vector2u expectedSize{64, 64};
|
|
132
139
|
const auto& image = *source->owner()->current;
|
|
133
140
|
const auto& replacement = *patch->owner()->current;
|
|
134
|
-
if (image.getSize() !=
|
|
141
|
+
if (image.getSize() != expectedSize ||
|
|
135
142
|
replacement.getSize() != image.getSize()) {
|
|
136
143
|
return Nan::ThrowRangeError("Expected 64 x 64 images");
|
|
137
144
|
}
|
|
@@ -155,16 +162,23 @@ NAN_METHOD(RenderTextureMipmapOracle) {
|
|
|
155
162
|
const sf::Texture copy(texture);
|
|
156
163
|
draw(copy, 16);
|
|
157
164
|
switch (mode) {
|
|
158
|
-
case 0:
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
case 0:
|
|
166
|
+
texture.update(replacement.getPixelsPtr());
|
|
167
|
+
break;
|
|
168
|
+
case 1:
|
|
169
|
+
texture.update(replacement);
|
|
170
|
+
break;
|
|
171
|
+
case 2:
|
|
172
|
+
texture.update(sf::Texture(replacement));
|
|
173
|
+
break;
|
|
161
174
|
case 3:
|
|
162
175
|
if (!texture.loadFromImage(replacement)) {
|
|
163
176
|
return Nan::ThrowError("Oracle load failed");
|
|
164
177
|
}
|
|
165
178
|
break;
|
|
166
179
|
case 4:
|
|
167
|
-
if (!texture.resize({64, 64}))
|
|
180
|
+
if (!texture.resize({64, 64}))
|
|
181
|
+
return Nan::ThrowError("Oracle resize failed");
|
|
168
182
|
texture.update(replacement);
|
|
169
183
|
break;
|
|
170
184
|
}
|
|
@@ -177,12 +191,14 @@ NAN_METHOD(RenderTextureMipmapOracle) {
|
|
|
177
191
|
draw(texture, 40);
|
|
178
192
|
draw(other, 48);
|
|
179
193
|
target.display();
|
|
180
|
-
auto result = sfmljs::MapImage(
|
|
194
|
+
auto result = sfmljs::MapImage(
|
|
195
|
+
info.GetIsolate(),
|
|
181
196
|
std::make_shared<sf::Image>(target.getTexture().copyToImage()));
|
|
182
|
-
Nan::Set(result, Nan::New("generated").ToLocalChecked(),
|
|
183
|
-
|
|
184
|
-
Nan::Set(
|
|
185
|
-
|
|
197
|
+
Nan::Set(result, Nan::New("generated").ToLocalChecked(), Nan::New(generated))
|
|
198
|
+
.FromJust();
|
|
199
|
+
Nan::Set(
|
|
200
|
+
result, Nan::New("regenerated").ToLocalChecked(), Nan::New(regenerated))
|
|
201
|
+
.FromJust();
|
|
186
202
|
info.GetReturnValue().Set(result);
|
|
187
203
|
}
|
|
188
204
|
|
|
@@ -194,7 +210,8 @@ NAN_MODULE_INIT(InitializeTextureProbes) {
|
|
|
194
210
|
Nan::SetMethod(target, "readTexturePixels", ReadTexturePixels);
|
|
195
211
|
Nan::SetMethod(target, "readTextureFlags", ReadTextureFlags);
|
|
196
212
|
Nan::SetMethod(target, "loadTextureAreaOracle", LoadTextureAreaOracle);
|
|
197
|
-
Nan::SetMethod(
|
|
198
|
-
|
|
199
|
-
Nan::SetMethod(
|
|
213
|
+
Nan::SetMethod(
|
|
214
|
+
target, "renderTextureSamplingOracle", RenderTextureSamplingOracle);
|
|
215
|
+
Nan::SetMethod(
|
|
216
|
+
target, "renderTextureMipmapOracle", RenderTextureMipmapOracle);
|
|
200
217
|
}
|