sfml.js 1.0.0-rc.2 → 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 +16 -11
- package/README.ko.md +16 -11
- package/README.md +16 -11
- package/README.zh-CN.md +16 -11
- package/assets/breakout.png +0 -0
- 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 +43 -50
- 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 -148
- package/docs/development.ko.md +0 -148
- package/docs/development.md +0 -150
- package/docs/development.zh-CN.md +0 -150
- 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 -69
- 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,18 +1,19 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <array>
|
|
2
|
+
#include <vector>
|
|
2
3
|
|
|
4
|
+
#include "shared-handle.h"
|
|
3
5
|
#include <SFML/Graphics/Drawable.hpp>
|
|
4
6
|
#include <SFML/Graphics/Image.hpp>
|
|
5
7
|
#include <SFML/Graphics/RenderTexture.hpp>
|
|
6
8
|
#include <SFML/Graphics/Sprite.hpp>
|
|
7
9
|
#include <SFML/Graphics/Transformable.hpp>
|
|
8
10
|
|
|
9
|
-
#include <array>
|
|
10
|
-
#include <vector>
|
|
11
|
-
|
|
12
11
|
namespace {
|
|
13
12
|
|
|
14
13
|
template <std::size_t N>
|
|
15
|
-
bool ReadMode(
|
|
14
|
+
bool ReadMode(
|
|
15
|
+
v8::Local<v8::Value> input,
|
|
16
|
+
std::array<std::uint32_t, N>& values) { // NOLINT(runtime/references)
|
|
16
17
|
if (!input->IsUint32Array() ||
|
|
17
18
|
input.As<v8::Uint32Array>()->ByteLength() != sizeof(values)) {
|
|
18
19
|
Nan::ThrowTypeError("Expected a mode field array");
|
|
@@ -28,9 +29,12 @@ NAN_METHOD(CompareBlendModes) {
|
|
|
28
29
|
const auto make = [](const auto& values) {
|
|
29
30
|
using F = sf::BlendMode::Factor;
|
|
30
31
|
using E = sf::BlendMode::Equation;
|
|
31
|
-
return sf::BlendMode(static_cast<F>(values[0]),
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
return sf::BlendMode(static_cast<F>(values[0]),
|
|
33
|
+
static_cast<F>(values[1]),
|
|
34
|
+
static_cast<E>(values[2]),
|
|
35
|
+
static_cast<F>(values[3]),
|
|
36
|
+
static_cast<F>(values[4]),
|
|
37
|
+
static_cast<E>(values[5]));
|
|
34
38
|
};
|
|
35
39
|
const auto left = make(a), right = make(b);
|
|
36
40
|
auto result = Nan::New<v8::Array>(2);
|
|
@@ -44,9 +48,10 @@ NAN_METHOD(CompareStencilModes) {
|
|
|
44
48
|
if (!ReadMode(info[0], a) || !ReadMode(info[1], b)) return;
|
|
45
49
|
const auto make = [](const auto& values) {
|
|
46
50
|
return sf::StencilMode{static_cast<sf::StencilComparison>(values[0]),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
static_cast<sf::StencilUpdateOperation>(values[1]),
|
|
52
|
+
sf::StencilValue(values[2]),
|
|
53
|
+
sf::StencilValue(values[3]),
|
|
54
|
+
values[4] != 0};
|
|
50
55
|
};
|
|
51
56
|
const auto left = make(a), right = make(b);
|
|
52
57
|
auto result = Nan::New<v8::Array>(2);
|
|
@@ -67,7 +72,8 @@ class Group : public sf::Drawable, public sf::Transformable {
|
|
|
67
72
|
}
|
|
68
73
|
};
|
|
69
74
|
|
|
70
|
-
void Nested(sf::RenderTarget& target,
|
|
75
|
+
void Nested(sf::RenderTarget& target, // NOLINT(runtime/references)
|
|
76
|
+
const sf::Texture& texture) {
|
|
71
77
|
sf::Sprite sprite(texture);
|
|
72
78
|
sprite.setPosition({3.25f, 2.5f});
|
|
73
79
|
sprite.setScale({8.f, 6.f});
|
|
@@ -91,16 +97,28 @@ void Nested(sf::RenderTarget& target, const sf::Texture& texture) {
|
|
|
91
97
|
states.transform.translate({200.f, 200.f});
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
void Blends(sf::RenderTarget& target,
|
|
100
|
+
void Blends(sf::RenderTarget& target, // NOLINT(runtime/references)
|
|
101
|
+
const sf::Texture& texture) {
|
|
95
102
|
using F = sf::BlendMode::Factor;
|
|
96
103
|
using E = sf::BlendMode::Equation;
|
|
97
|
-
const std::array modes{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
const std::array modes{sf::BlendAlpha,
|
|
105
|
+
sf::BlendAdd,
|
|
106
|
+
sf::BlendMultiply,
|
|
107
|
+
sf::BlendMin,
|
|
108
|
+
sf::BlendMax,
|
|
109
|
+
sf::BlendNone,
|
|
110
|
+
sf::BlendMode(F::One,
|
|
111
|
+
F::One,
|
|
112
|
+
E::Subtract,
|
|
113
|
+
F::DstAlpha,
|
|
114
|
+
F::OneMinusDstAlpha,
|
|
115
|
+
E::ReverseSubtract),
|
|
116
|
+
sf::BlendMode(F::OneMinusDstColor,
|
|
117
|
+
F::SrcColor,
|
|
118
|
+
E::ReverseSubtract,
|
|
119
|
+
F::OneMinusSrcColor,
|
|
120
|
+
F::DstColor,
|
|
121
|
+
E::Add)};
|
|
104
122
|
sf::Sprite sprite(texture);
|
|
105
123
|
sprite.setScale({8.f, 32.f});
|
|
106
124
|
for (std::size_t i = 0; i < modes.size(); ++i) {
|
|
@@ -112,7 +130,8 @@ void Blends(sf::RenderTarget& target, const sf::Texture& texture) {
|
|
|
112
130
|
}
|
|
113
131
|
}
|
|
114
132
|
|
|
115
|
-
void Stencils(sf::RenderTarget& target,
|
|
133
|
+
void Stencils(sf::RenderTarget& target, // NOLINT(runtime/references)
|
|
134
|
+
const sf::Texture& texture) {
|
|
116
135
|
sf::Sprite sprite(texture);
|
|
117
136
|
sprite.setScale({8.f, 8.f});
|
|
118
137
|
for (unsigned comparison = 0; comparison < 8; ++comparison) {
|
|
@@ -120,20 +139,31 @@ void Stencils(sf::RenderTarget& target, const sf::Texture& texture) {
|
|
|
120
139
|
target.clearStencil(2);
|
|
121
140
|
sprite.setPosition({static_cast<float>(operation * 8),
|
|
122
141
|
static_cast<float>(comparison * 8)});
|
|
123
|
-
target.draw(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
142
|
+
target.draw(
|
|
143
|
+
sprite,
|
|
144
|
+
sf::StencilMode{sf::StencilComparison::Always,
|
|
145
|
+
static_cast<sf::StencilUpdateOperation>(operation),
|
|
146
|
+
5,
|
|
147
|
+
0xff,
|
|
148
|
+
true});
|
|
149
|
+
target.draw(
|
|
150
|
+
sprite,
|
|
151
|
+
sf::StencilMode{static_cast<sf::StencilComparison>(comparison),
|
|
152
|
+
sf::StencilUpdateOperation::Keep,
|
|
153
|
+
2,
|
|
154
|
+
0xff,
|
|
155
|
+
false});
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
158
|
// A masked comparison in the remaining column.
|
|
132
159
|
target.clearStencil(0x12);
|
|
133
160
|
sprite.setPosition({48.f, 0.f});
|
|
134
|
-
target.draw(sprite,
|
|
135
|
-
|
|
136
|
-
|
|
161
|
+
target.draw(sprite,
|
|
162
|
+
sf::StencilMode{sf::StencilComparison::Equal,
|
|
163
|
+
sf::StencilUpdateOperation::Keep,
|
|
164
|
+
0x02,
|
|
165
|
+
0x0f,
|
|
166
|
+
false});
|
|
137
167
|
}
|
|
138
168
|
|
|
139
169
|
NAN_METHOD(RenderDrawableOracle) {
|
|
@@ -149,14 +179,18 @@ NAN_METHOD(RenderDrawableOracle) {
|
|
|
149
179
|
return Nan::ThrowError("Could not create drawable oracle target");
|
|
150
180
|
}
|
|
151
181
|
target.clear(sf::Color(24, 40, 72, 180), 0);
|
|
152
|
-
if (scenario == 0)
|
|
153
|
-
|
|
154
|
-
else
|
|
182
|
+
if (scenario == 0)
|
|
183
|
+
Nested(target, *texture->owner());
|
|
184
|
+
else if (scenario == 1)
|
|
185
|
+
Blends(target, *texture->owner());
|
|
186
|
+
else
|
|
187
|
+
Stencils(target, *texture->owner());
|
|
155
188
|
target.display();
|
|
156
189
|
const auto image = target.getTexture().copyToImage();
|
|
157
|
-
info.GetReturnValue().Set(
|
|
158
|
-
reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
159
|
-
|
|
190
|
+
info.GetReturnValue().Set(
|
|
191
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
192
|
+
64 * 64 * 4)
|
|
193
|
+
.ToLocalChecked());
|
|
160
194
|
}
|
|
161
195
|
|
|
162
196
|
} // namespace
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#include "../../native/exception-boundary.h"
|
|
2
|
-
|
|
3
|
-
#include <SFML/Graphics/Font.hpp>
|
|
4
|
-
#include <SFML/System/Exception.hpp>
|
|
5
|
-
|
|
6
1
|
#include <atomic>
|
|
7
2
|
#include <memory>
|
|
8
3
|
#include <stdexcept>
|
|
9
4
|
|
|
5
|
+
#include "exception-boundary.h"
|
|
6
|
+
#include <SFML/Graphics/Font.hpp>
|
|
7
|
+
#include <SFML/System/Exception.hpp>
|
|
8
|
+
|
|
10
9
|
namespace {
|
|
11
10
|
|
|
12
11
|
std::atomic<unsigned> activeScopes{};
|
|
@@ -39,14 +38,18 @@ NAN_METHOD(ReadExceptionScopes) {
|
|
|
39
38
|
NAN_METHOD(PassJsException) {
|
|
40
39
|
if (!info[0]->IsFunction()) return Nan::ThrowTypeError("Expected a callback");
|
|
41
40
|
// A pending JS exception must pass through without being replaced.
|
|
42
|
-
Nan::Call(info[0].As<v8::Function>(),
|
|
41
|
+
Nan::Call(info[0].As<v8::Function>(),
|
|
42
|
+
Nan::GetCurrentContext()->Global(),
|
|
43
|
+
0,
|
|
44
|
+
nullptr);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
class FailureWorker final : public sfmljs::AsyncWorker {
|
|
46
48
|
public:
|
|
47
49
|
FailureWorker(Nan::Callback* callback, unsigned kind, bool completion)
|
|
48
50
|
: sfmljs::AsyncWorker(callback, "sfml:ExceptionProbe"),
|
|
49
|
-
kind_(kind),
|
|
51
|
+
kind_(kind),
|
|
52
|
+
completion_(completion) {}
|
|
50
53
|
|
|
51
54
|
void ExecuteWork() override {
|
|
52
55
|
if (!completion_) Fail(kind_);
|
|
@@ -67,8 +70,10 @@ class FailureWorker final : public sfmljs::AsyncWorker {
|
|
|
67
70
|
NAN_METHOD(QueueNativeException) {
|
|
68
71
|
if (!info[2]->IsFunction()) return Nan::ThrowTypeError("Expected a callback");
|
|
69
72
|
auto callback = std::make_unique<Nan::Callback>(info[2].As<v8::Function>());
|
|
70
|
-
auto worker =
|
|
71
|
-
|
|
73
|
+
auto worker =
|
|
74
|
+
std::make_unique<FailureWorker>(callback.get(),
|
|
75
|
+
Nan::To<unsigned>(info[0]).FromMaybe(0),
|
|
76
|
+
info[1]->IsTrue());
|
|
72
77
|
callback.release();
|
|
73
78
|
Nan::AsyncQueueWorker(worker.release());
|
|
74
79
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <chrono> // NOLINT(build/c++11)
|
|
2
2
|
|
|
3
|
-
#include
|
|
3
|
+
#include "../../native/image-state.h"
|
|
4
4
|
|
|
5
5
|
namespace {
|
|
6
6
|
|
|
@@ -16,9 +16,11 @@ NAN_METHOD(ReadImagePixels) {
|
|
|
16
16
|
if (bytes > std::numeric_limits<std::uint32_t>::max()) {
|
|
17
17
|
return Nan::ThrowRangeError("Image too large for the readback probe");
|
|
18
18
|
}
|
|
19
|
-
info.GetReturnValue().Set(
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
info.GetReturnValue().Set(
|
|
20
|
+
Nan::CopyBuffer(
|
|
21
|
+
bytes ? reinterpret_cast<const char*>(image.getPixelsPtr()) : "",
|
|
22
|
+
static_cast<std::uint32_t>(bytes))
|
|
23
|
+
.ToLocalChecked());
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
NAN_METHOD(ImageSharesPixels) {
|
|
@@ -72,15 +74,22 @@ NAN_METHOD(BenchmarkImageBulk) {
|
|
|
72
74
|
const auto operation = Nan::To<std::uint32_t>(info[2]).FromJust();
|
|
73
75
|
const auto count = Nan::To<std::uint32_t>(info[3]).FromJust();
|
|
74
76
|
if (operation > 3 || dest->owner()->current == source->owner()->current) {
|
|
75
|
-
return Nan::ThrowRangeError(
|
|
77
|
+
return Nan::ThrowRangeError(
|
|
78
|
+
"Expected a valid operation and distinct images");
|
|
76
79
|
}
|
|
77
80
|
auto& image = *dest->owner()->current;
|
|
78
81
|
const auto start = std::chrono::steady_clock::now();
|
|
79
82
|
for (std::uint32_t i = 0; i < count; ++i) {
|
|
80
83
|
switch (operation) {
|
|
81
|
-
case 0:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
case 0:
|
|
85
|
+
image.flipHorizontally();
|
|
86
|
+
break;
|
|
87
|
+
case 1:
|
|
88
|
+
image.flipVertically();
|
|
89
|
+
break;
|
|
90
|
+
case 2:
|
|
91
|
+
image.createMaskFromColor(sf::Color::Red, 0);
|
|
92
|
+
break;
|
|
84
93
|
case 3:
|
|
85
94
|
if (!image.copy(*source->owner()->current, {0, 0})) {
|
|
86
95
|
return Nan::ThrowError("Benchmark copy failed");
|
|
@@ -89,7 +98,8 @@ NAN_METHOD(BenchmarkImageBulk) {
|
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
const auto elapsed = std::chrono::duration<double, std::milli>(
|
|
92
|
-
|
|
101
|
+
std::chrono::steady_clock::now() - start)
|
|
102
|
+
.count();
|
|
93
103
|
info.GetReturnValue().Set(elapsed);
|
|
94
104
|
}
|
|
95
105
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#include "../../native/value-binding.h"
|
|
2
2
|
|
|
3
|
+
namespace sfmljs::values {
|
|
3
4
|
namespace {
|
|
4
5
|
|
|
5
6
|
using sfmljs::SharedHandle;
|
|
6
|
-
using namespace sfmljs::values;
|
|
7
7
|
|
|
8
8
|
template <typename T>
|
|
9
9
|
void ReadMatrix(const CallbackInfo& info) {
|
|
@@ -22,7 +22,8 @@ void SetMatrixElement(const CallbackInfo& info) {
|
|
|
22
22
|
auto* handle = SharedHandle<T>::From(info[0]);
|
|
23
23
|
if (!handle) return;
|
|
24
24
|
auto& data = handle->owner()->array;
|
|
25
|
-
if (!info[1]->IsUint32() ||
|
|
25
|
+
if (!info[1]->IsUint32() ||
|
|
26
|
+
Nan::To<uint32_t>(info[1]).FromJust() >= data.size()) {
|
|
26
27
|
return Nan::ThrowRangeError("Expected a valid matrix index");
|
|
27
28
|
}
|
|
28
29
|
if (!info[2]->IsNumber()) {
|
|
@@ -60,8 +61,11 @@ NAN_MODULE_INIT(InitializeMatrixProbes) {
|
|
|
60
61
|
Nan::SetMethod(target, "readMat4", ReadMatrix<sf::Glsl::Mat4>);
|
|
61
62
|
Nan::SetMethod(target, "setMat3Element", SetMatrixElement<sf::Glsl::Mat3>);
|
|
62
63
|
Nan::SetMethod(target, "setMat4Element", SetMatrixElement<sf::Glsl::Mat4>);
|
|
63
|
-
Nan::SetMethod(
|
|
64
|
-
|
|
64
|
+
Nan::SetMethod(
|
|
65
|
+
target, "mat3FromTransform", MatrixFromTransform<sf::Glsl::Mat3>);
|
|
66
|
+
Nan::SetMethod(
|
|
67
|
+
target, "mat4FromTransform", MatrixFromTransform<sf::Glsl::Mat4>);
|
|
65
68
|
Nan::SetMethod(target, "mat3FromArray", MatrixFromArray<sf::Glsl::Mat3>);
|
|
66
69
|
Nan::SetMethod(target, "mat4FromArray", MatrixFromArray<sf::Glsl::Mat4>);
|
|
67
70
|
}
|
|
71
|
+
} // namespace sfmljs::values
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
#include <SFML/Network/Packet.hpp>
|
|
2
|
-
#include <SFML/Network/IpAddress.hpp>
|
|
3
|
-
#include <SFML/System/String.hpp>
|
|
4
1
|
#include <cstdint>
|
|
5
2
|
#include <iomanip>
|
|
6
3
|
#include <iostream>
|
|
7
4
|
#include <limits>
|
|
8
5
|
|
|
6
|
+
#include <SFML/Network/IpAddress.hpp>
|
|
7
|
+
#include <SFML/Network/Packet.hpp>
|
|
8
|
+
#include <SFML/System/String.hpp>
|
|
9
|
+
|
|
9
10
|
int main() {
|
|
10
11
|
sf::Packet packet;
|
|
11
|
-
packet << true << std::int8_t(-8) << std::uint8_t(255)
|
|
12
|
-
<< std::
|
|
13
|
-
<< std::
|
|
12
|
+
packet << true << std::int8_t(-8) << std::uint8_t(255) << std::int16_t(-32768)
|
|
13
|
+
<< std::uint16_t(65535) << std::int32_t(-2147483647 - 1)
|
|
14
|
+
<< std::uint32_t(0xffffffff)
|
|
14
15
|
<< std::numeric_limits<std::int64_t>::min()
|
|
15
|
-
<< std::numeric_limits<std::uint64_t>::max()
|
|
16
|
-
<<
|
|
16
|
+
<< std::numeric_limits<std::uint64_t>::max() << 1.5f
|
|
17
|
+
<< -3.141592653589793;
|
|
17
18
|
sf::String unicode;
|
|
18
19
|
unicode += U'\u97f3';
|
|
19
20
|
unicode += U'\u9891';
|
|
@@ -23,10 +24,15 @@ int main() {
|
|
|
23
24
|
<< std::string("\xff\0\xfe", 3);
|
|
24
25
|
const auto* bytes = static_cast<const unsigned char*>(packet.getData());
|
|
25
26
|
for (std::size_t i = 0; i < packet.getDataSize(); ++i)
|
|
26
|
-
std::cout << std::hex << std::setfill('0') << std::setw(2)
|
|
27
|
+
std::cout << std::hex << std::setfill('0') << std::setw(2)
|
|
28
|
+
<< unsigned(bytes[i]);
|
|
27
29
|
std::cout << '\n';
|
|
28
|
-
for (const auto* text : {"127.0.0.1",
|
|
29
|
-
|
|
30
|
+
for (const auto* text : {"127.0.0.1",
|
|
31
|
+
"2001:db8::1",
|
|
32
|
+
"::ffff:127.0.0.1",
|
|
33
|
+
"::192.168.1.1",
|
|
34
|
+
"::1",
|
|
35
|
+
"2001:0:0:1:0:0:1:1"}) {
|
|
30
36
|
std::cout << sf::IpAddress::fromString(text)->toString() << '\n';
|
|
31
37
|
}
|
|
32
38
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include "../../native/graphics-state.h"
|
|
2
2
|
#include "../../native/image-state.h"
|
|
3
|
-
|
|
4
3
|
#include <SFML/Graphics/VertexArray.hpp>
|
|
5
4
|
#include <SFML/Window/Context.hpp>
|
|
6
5
|
#define GL_SILENCE_DEPRECATION
|
|
@@ -30,8 +29,8 @@ NAN_METHOD(InspectActiveFramebuffer) {
|
|
|
30
29
|
NAN_METHOD(ClearActiveFramebuffer) {
|
|
31
30
|
const auto clearColor = reinterpret_cast<decltype(&glClearColor)>(
|
|
32
31
|
sf::Context::getFunction("glClearColor"));
|
|
33
|
-
const auto clear =
|
|
34
|
-
sf::Context::getFunction("glClear"));
|
|
32
|
+
const auto clear =
|
|
33
|
+
reinterpret_cast<decltype(&glClear)>(sf::Context::getFunction("glClear"));
|
|
35
34
|
const auto disable = reinterpret_cast<decltype(&glDisable)>(
|
|
36
35
|
sf::Context::getFunction("glDisable"));
|
|
37
36
|
disable(GL_SCISSOR_TEST);
|
|
@@ -43,9 +42,11 @@ NAN_METHOD(ReadRenderTextureState) {
|
|
|
43
42
|
auto* target = SharedHandle<Target>::From(info[0]);
|
|
44
43
|
if (!target) return;
|
|
45
44
|
auto result = sfmljs::DescribeTexture(target->owner()->target.getTexture());
|
|
46
|
-
Nan::Set(result,
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
Nan::Set(result,
|
|
46
|
+
Nan::New("targetSrgb").ToLocalChecked(),
|
|
47
|
+
Nan::New(target->owner()->initialized &&
|
|
48
|
+
target->owner()->target.isSrgb()))
|
|
49
|
+
.FromJust();
|
|
49
50
|
info.GetReturnValue().Set(result);
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -67,12 +68,15 @@ NAN_METHOD(RenderTextureSamplingOracle) {
|
|
|
67
68
|
quad[3] = {{8, 1}, sf::Color::White, {edge, 1}};
|
|
68
69
|
sf::RenderStates states(&source.getTexture());
|
|
69
70
|
output.draw(quad, states);
|
|
70
|
-
if (repeat)
|
|
71
|
-
|
|
71
|
+
if (repeat)
|
|
72
|
+
source.setRepeated(true);
|
|
73
|
+
else
|
|
74
|
+
source.setSmooth(true);
|
|
72
75
|
states.transform.translate({0, 1});
|
|
73
76
|
output.draw(quad, states);
|
|
74
77
|
output.display();
|
|
75
|
-
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
78
|
+
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
79
|
+
info.GetIsolate(),
|
|
76
80
|
std::make_shared<sf::Image>(output.getTexture().copyToImage())));
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -102,10 +106,11 @@ NAN_METHOD(RenderTextureMipmapOracle) {
|
|
|
102
106
|
states.transform.translate({0, 8});
|
|
103
107
|
output.draw(quad, states);
|
|
104
108
|
output.display();
|
|
105
|
-
auto result = sfmljs::MapImage(
|
|
109
|
+
auto result = sfmljs::MapImage(
|
|
110
|
+
info.GetIsolate(),
|
|
106
111
|
std::make_shared<sf::Image>(output.getTexture().copyToImage()));
|
|
107
|
-
Nan::Set(result, Nan::New("generated").ToLocalChecked(),
|
|
108
|
-
|
|
112
|
+
Nan::Set(result, Nan::New("generated").ToLocalChecked(), Nan::New(generated))
|
|
113
|
+
.FromJust();
|
|
109
114
|
info.GetReturnValue().Set(result);
|
|
110
115
|
}
|
|
111
116
|
|
|
@@ -115,17 +120,18 @@ NAN_METHOD(RenderTextureSharesTexture) {
|
|
|
115
120
|
const auto texture = sfmljs::ReadTexture(info[1]);
|
|
116
121
|
if (!texture) return;
|
|
117
122
|
const auto& owner = target->owner();
|
|
118
|
-
info.GetReturnValue().Set(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
info.GetReturnValue().Set(texture.get() == &owner->target.getTexture() &&
|
|
124
|
+
!texture.owner_before(owner) &&
|
|
125
|
+
!owner.owner_before(texture) &&
|
|
126
|
+
texture->getNativeHandle() ==
|
|
127
|
+
owner->target.getTexture().getNativeHandle());
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
NAN_METHOD(ObserveRenderTexture) {
|
|
125
131
|
auto* target = SharedHandle<Target>::From(info[0]);
|
|
126
|
-
if (target)
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
if (target)
|
|
133
|
+
info.GetReturnValue().Set(SharedHandle<Observation>::Create(
|
|
134
|
+
std::make_shared<Observation>(target->owner())));
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
NAN_METHOD(RenderTextureExpired) {
|
|
@@ -172,7 +178,8 @@ NAN_METHOD(RenderTextureViewOracle) {
|
|
|
172
178
|
states.transform.translate({0, 2});
|
|
173
179
|
target.draw(quad, states);
|
|
174
180
|
target.display();
|
|
175
|
-
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
181
|
+
info.GetReturnValue().Set(sfmljs::MapImage(
|
|
182
|
+
info.GetIsolate(),
|
|
176
183
|
std::make_shared<sf::Image>(target.getTexture().copyToImage())));
|
|
177
184
|
}
|
|
178
185
|
|
|
@@ -182,10 +189,12 @@ NAN_MODULE_INIT(InitializeRenderTextureProbes) {
|
|
|
182
189
|
Nan::SetMethod(target, "inspectActiveFramebuffer", InspectActiveFramebuffer);
|
|
183
190
|
Nan::SetMethod(target, "clearActiveFramebuffer", ClearActiveFramebuffer);
|
|
184
191
|
Nan::SetMethod(target, "readRenderTextureState", ReadRenderTextureState);
|
|
185
|
-
Nan::SetMethod(
|
|
186
|
-
|
|
187
|
-
Nan::SetMethod(
|
|
188
|
-
|
|
192
|
+
Nan::SetMethod(
|
|
193
|
+
target, "renderOffscreenSamplingOracle", RenderTextureSamplingOracle);
|
|
194
|
+
Nan::SetMethod(
|
|
195
|
+
target, "renderOffscreenMipmapOracle", RenderTextureMipmapOracle);
|
|
196
|
+
Nan::SetMethod(
|
|
197
|
+
target, "renderTextureSharesTexture", RenderTextureSharesTexture);
|
|
189
198
|
Nan::SetMethod(target, "observeRenderTexture", ObserveRenderTexture);
|
|
190
199
|
Nan::SetMethod(target, "renderTextureExpired", RenderTextureExpired);
|
|
191
200
|
Nan::SetMethod(target, "textureRegistered", TextureRegistered);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include "../../native/graphics-state.h"
|
|
2
|
-
#include "
|
|
3
|
-
|
|
2
|
+
#include "shared-handle.h"
|
|
4
3
|
#include <SFML/Graphics/Image.hpp>
|
|
5
4
|
#include <SFML/Graphics/VertexArray.hpp>
|
|
6
5
|
#define GL_SILENCE_DEPRECATION
|
|
@@ -21,8 +20,7 @@ NAN_METHOD(RenderShaderOracle) {
|
|
|
21
20
|
states.blendMode = sf::BlendNone;
|
|
22
21
|
states.transform.translate({2, 1}).scale({0.75f, 1.25f});
|
|
23
22
|
sf::VertexArray vertices(sf::PrimitiveType::TriangleStrip, 4);
|
|
24
|
-
const std::array<sf::Vector2f, 4> positions{{
|
|
25
|
-
{0, 0}, {4, 0}, {0, 4}, {4, 4}}};
|
|
23
|
+
const std::array<sf::Vector2f, 4> positions{{{0, 0}, {4, 0}, {0, 4}, {4, 4}}};
|
|
26
24
|
for (std::size_t i = 0; i < positions.size(); ++i) {
|
|
27
25
|
vertices[i] = {positions[i], sf::Color(128, 255, 64), positions[i]};
|
|
28
26
|
}
|
|
@@ -43,9 +41,10 @@ NAN_METHOD(RenderShaderOracle) {
|
|
|
43
41
|
}
|
|
44
42
|
target.display();
|
|
45
43
|
const auto image = target.getTexture().copyToImage();
|
|
46
|
-
info.GetReturnValue().Set(
|
|
47
|
-
reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
48
|
-
|
|
44
|
+
info.GetReturnValue().Set(
|
|
45
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
46
|
+
8 * 8 * 4)
|
|
47
|
+
.ToLocalChecked());
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
NAN_METHOD(BoundShader) {
|
|
@@ -56,8 +55,9 @@ NAN_METHOD(BoundShader) {
|
|
|
56
55
|
|
|
57
56
|
NAN_METHOD(ShaderRegistrySize) {
|
|
58
57
|
auto* context = sfmljs::SharedHandle<sfmljs::GraphicsContext>::From(info[0]);
|
|
59
|
-
if (context)
|
|
60
|
-
|
|
58
|
+
if (context)
|
|
59
|
+
info.GetReturnValue().Set(
|
|
60
|
+
Nan::New(static_cast<unsigned>(context->owner()->shaders.size())));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
} // namespace
|
|
@@ -13,15 +13,19 @@ v8::Local<v8::Value> Get(v8::Local<v8::Object> input, const char* name) {
|
|
|
13
13
|
struct Polygon : sf::Shape {
|
|
14
14
|
std::vector<sf::Vector2f> points;
|
|
15
15
|
std::size_t getPointCount() const override { return points.size(); }
|
|
16
|
-
sf::Vector2f getPoint(std::size_t index) const override {
|
|
16
|
+
sf::Vector2f getPoint(std::size_t index) const override {
|
|
17
|
+
return points[index];
|
|
18
|
+
}
|
|
17
19
|
void refresh() { update(); }
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
template <class T>
|
|
21
23
|
v8::Local<v8::Array> Box(const sf::Rect<T>& rect) {
|
|
22
24
|
auto result = Nan::New<v8::Array>(4);
|
|
23
|
-
const double fields[]{double(rect.position.x),
|
|
24
|
-
|
|
25
|
+
const double fields[]{static_cast<double>(rect.position.x),
|
|
26
|
+
static_cast<double>(rect.position.y),
|
|
27
|
+
static_cast<double>(rect.size.x),
|
|
28
|
+
static_cast<double>(rect.size.y)};
|
|
25
29
|
for (unsigned i = 0; i < 4; ++i) {
|
|
26
30
|
Nan::Set(result, i, Nan::New(fields[i])).FromJust();
|
|
27
31
|
}
|
|
@@ -30,7 +34,7 @@ v8::Local<v8::Array> Box(const sf::Rect<T>& rect) {
|
|
|
30
34
|
|
|
31
35
|
v8::Local<v8::Object> Describe(const sf::Shape& shape) {
|
|
32
36
|
auto result = Nan::New<v8::Object>();
|
|
33
|
-
#define FIELD(name, value)
|
|
37
|
+
#define FIELD(name, value) \
|
|
34
38
|
Nan::Set(result, Nan::New(name).ToLocalChecked(), value).FromJust()
|
|
35
39
|
FIELD("rect", Box(shape.getTextureRect()));
|
|
36
40
|
FIELD("local", Box(shape.getLocalBounds()));
|
|
@@ -56,13 +60,14 @@ v8::Local<v8::Object> Describe(const sf::Shape& shape) {
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
std::unique_ptr<sf::Shape> Configure(v8::Local<v8::Object> input,
|
|
59
|
-
|
|
63
|
+
sf::RenderStates& states) { // NOLINT
|
|
60
64
|
const auto kind = Nan::To<unsigned>(Get(input, "kind")).FromJust();
|
|
61
65
|
Nan::TypedArrayContents<float> dimensions(Get(input, "dimensions"));
|
|
62
66
|
Nan::TypedArrayContents<float> points(Get(input, "points"));
|
|
63
67
|
std::unique_ptr<sf::Shape> shape;
|
|
64
68
|
if (kind == 1) {
|
|
65
|
-
shape =
|
|
69
|
+
shape =
|
|
70
|
+
std::make_unique<sf::CircleShape>((*dimensions)[0], (*dimensions)[1]);
|
|
66
71
|
} else if (kind == 2) {
|
|
67
72
|
shape = std::make_unique<sf::RectangleShape>(
|
|
68
73
|
sf::Vector2f{(*dimensions)[0], (*dimensions)[1]});
|
|
@@ -88,11 +93,12 @@ std::unique_ptr<sf::Shape> Configure(v8::Local<v8::Object> input,
|
|
|
88
93
|
}
|
|
89
94
|
Nan::TypedArrayContents<std::int32_t> rect(Get(input, "rect"));
|
|
90
95
|
shape->setTextureRect({{(*rect)[0], (*rect)[1]}, {(*rect)[2], (*rect)[3]}});
|
|
91
|
-
shape->setFillColor(
|
|
92
|
-
Nan::To<std::uint32_t>(Get(input, "fill")).FromJust()));
|
|
93
|
-
shape->setOutlineColor(
|
|
94
|
-
Nan::To<std::uint32_t>(Get(input, "outline")).FromJust()));
|
|
95
|
-
shape->setOutlineThickness(
|
|
96
|
+
shape->setFillColor(
|
|
97
|
+
sf::Color(Nan::To<std::uint32_t>(Get(input, "fill")).FromJust()));
|
|
98
|
+
shape->setOutlineColor(
|
|
99
|
+
sf::Color(Nan::To<std::uint32_t>(Get(input, "outline")).FromJust()));
|
|
100
|
+
shape->setOutlineThickness(
|
|
101
|
+
Nan::To<double>(Get(input, "thickness")).FromJust());
|
|
96
102
|
shape->setMiterLimit(Nan::To<double>(Get(input, "miterLimit")).FromJust());
|
|
97
103
|
Nan::TypedArrayContents<float> pose(Get(input, "transform"));
|
|
98
104
|
shape->setPosition({(*pose)[0], (*pose)[1]});
|
|
@@ -100,10 +106,15 @@ std::unique_ptr<sf::Shape> Configure(v8::Local<v8::Object> input,
|
|
|
100
106
|
shape->setScale({(*pose)[3], (*pose)[4]});
|
|
101
107
|
shape->setOrigin({(*pose)[5], (*pose)[6]});
|
|
102
108
|
Nan::TypedArrayContents<float> matrix(Get(input, "parent"));
|
|
103
|
-
states.transform = sf::Transform(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
states.transform = sf::Transform((*matrix)[0],
|
|
110
|
+
(*matrix)[4],
|
|
111
|
+
(*matrix)[12],
|
|
112
|
+
(*matrix)[1],
|
|
113
|
+
(*matrix)[5],
|
|
114
|
+
(*matrix)[13],
|
|
115
|
+
(*matrix)[3],
|
|
116
|
+
(*matrix)[7],
|
|
117
|
+
(*matrix)[15]);
|
|
107
118
|
return shape;
|
|
108
119
|
}
|
|
109
120
|
|
|
@@ -126,9 +137,10 @@ NAN_METHOD(RenderShapeOracle) {
|
|
|
126
137
|
}
|
|
127
138
|
target.display();
|
|
128
139
|
const auto image = target.getTexture().copyToImage();
|
|
129
|
-
info.GetReturnValue().Set(
|
|
130
|
-
reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
131
|
-
|
|
140
|
+
info.GetReturnValue().Set(
|
|
141
|
+
Nan::CopyBuffer(reinterpret_cast<const char*>(image.getPixelsPtr()),
|
|
142
|
+
64 * 64 * 4)
|
|
143
|
+
.ToLocalChecked());
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
NAN_METHOD(ReadShape) {
|
|
@@ -136,8 +148,10 @@ NAN_METHOD(ReadShape) {
|
|
|
136
148
|
if (!handle) return;
|
|
137
149
|
const auto& state = *handle->owner();
|
|
138
150
|
auto result = Describe(*state.shape);
|
|
139
|
-
Nan::Set(result,
|
|
140
|
-
Nan::New(
|
|
151
|
+
Nan::Set(result,
|
|
152
|
+
Nan::New("currentTexture").ToLocalChecked(),
|
|
153
|
+
Nan::New(state.shape->getTexture() == state.texture.get()))
|
|
154
|
+
.FromJust();
|
|
141
155
|
info.GetReturnValue().Set(result);
|
|
142
156
|
}
|
|
143
157
|
|
|
@@ -146,9 +160,9 @@ NAN_METHOD(ShapeAliases) {
|
|
|
146
160
|
auto* transform = SharedHandle<sfmljs::TransformableState>::From(info[1]);
|
|
147
161
|
auto* rectangle = SharedHandle<sf::IntRect>::From(info[2]);
|
|
148
162
|
if (!handle || !transform || !rectangle) return;
|
|
149
|
-
info.GetReturnValue().Set(
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
info.GetReturnValue().Set(transform->owner().get() == handle->owner().get() &&
|
|
164
|
+
rectangle->owner().get() ==
|
|
165
|
+
&handle->owner()->appearance.rectangle);
|
|
152
166
|
}
|
|
153
167
|
} // namespace
|
|
154
168
|
|