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,14 +1,14 @@
|
|
|
1
|
-
#include "graphics-state.h"
|
|
2
|
-
#include "exception-boundary.h"
|
|
3
|
-
#include "image-state.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/Window/Context.hpp>
|
|
6
1
|
#define GL_SILENCE_DEPRECATION
|
|
7
|
-
#include <SFML/OpenGL.hpp>
|
|
8
2
|
|
|
9
3
|
#include <exception>
|
|
10
4
|
#include <limits>
|
|
11
5
|
|
|
6
|
+
#include "exception-boundary.h"
|
|
7
|
+
#include "graphics-state.h"
|
|
8
|
+
#include "image-state.h"
|
|
9
|
+
#include <SFML/OpenGL.hpp>
|
|
10
|
+
#include <SFML/Window/Context.hpp>
|
|
11
|
+
|
|
12
12
|
namespace {
|
|
13
13
|
|
|
14
14
|
using TextureHandle = sfmljs::SharedHandle<sf::Texture>;
|
|
@@ -20,9 +20,10 @@ class WindowFramebuffer {
|
|
|
20
20
|
public:
|
|
21
21
|
explicit WindowFramebuffer(const sf::Window& window) {
|
|
22
22
|
separate_ = window.getSettings().majorVersion >= 3 ||
|
|
23
|
-
|
|
23
|
+
sf::Context::isExtensionAvailable("GL_ARB_framebuffer_object");
|
|
24
24
|
if (!separate_ &&
|
|
25
|
-
!sf::Context::isExtensionAvailable("GL_EXT_framebuffer_object"))
|
|
25
|
+
!sf::Context::isExtensionAvailable("GL_EXT_framebuffer_object"))
|
|
26
|
+
return;
|
|
26
27
|
bind_ = reinterpret_cast<decltype(&glBindTexture)>(sf::Context::getFunction(
|
|
27
28
|
separate_ ? "glBindFramebuffer" : "glBindFramebufferEXT"));
|
|
28
29
|
if (!bind_) return;
|
|
@@ -49,8 +50,9 @@ class WindowFramebuffer {
|
|
|
49
50
|
bool separate_{};
|
|
50
51
|
};
|
|
51
52
|
|
|
52
|
-
bool ReadPosition(v8::Local<v8::Value> x,
|
|
53
|
-
|
|
53
|
+
bool ReadPosition(v8::Local<v8::Value> x,
|
|
54
|
+
v8::Local<v8::Value> y,
|
|
55
|
+
sf::Vector2u& position) { // NOLINT(runtime/references)
|
|
54
56
|
if (!x->IsUint32() || !y->IsUint32()) {
|
|
55
57
|
Nan::ThrowRangeError("Expected unsigned integer texture coordinates");
|
|
56
58
|
return false;
|
|
@@ -60,12 +62,13 @@ bool ReadPosition(v8::Local<v8::Value> x, v8::Local<v8::Value> y,
|
|
|
60
62
|
return true;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
bool CheckRegion(const sf::Texture& texture,
|
|
65
|
+
bool CheckRegion(const sf::Texture& texture,
|
|
66
|
+
sf::Vector2u size,
|
|
64
67
|
sf::Vector2u dest) {
|
|
65
68
|
const auto target = texture.getSize();
|
|
66
69
|
// Subtract only after checking dest, avoiding unsigned integer overflow.
|
|
67
|
-
if (dest.x > target.x || dest.y > target.y ||
|
|
68
|
-
size.
|
|
70
|
+
if (dest.x > target.x || dest.y > target.y || size.x > target.x - dest.x ||
|
|
71
|
+
size.y > target.y - dest.y) {
|
|
69
72
|
Nan::ThrowRangeError("Update region is outside the texture");
|
|
70
73
|
return false;
|
|
71
74
|
}
|
|
@@ -94,10 +97,10 @@ NAN_METHOD(CreateTexture) {
|
|
|
94
97
|
}
|
|
95
98
|
try {
|
|
96
99
|
const auto id = context->owner()->nextId++;
|
|
97
|
-
auto texture = source
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
auto texture = source ? sfmljs::MakeThreadOwned<sfmljs::TextureState>(
|
|
101
|
+
context->owner(), id, *source)
|
|
102
|
+
: sfmljs::MakeThreadOwned<sfmljs::TextureState>(
|
|
103
|
+
context->owner(), id);
|
|
101
104
|
// SFML's copy constructor reports allocation failure only on stderr.
|
|
102
105
|
if (source && texture->getSize() != source->getSize()) {
|
|
103
106
|
return sfmljs::ThrowError("SFML could not copy the texture");
|
|
@@ -107,12 +110,15 @@ NAN_METHOD(CreateTexture) {
|
|
|
107
110
|
}
|
|
108
111
|
context->owner()->textures.emplace(texture->id, texture);
|
|
109
112
|
auto result = Nan::New<v8::Object>();
|
|
110
|
-
Nan::Set(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
Nan::Set(
|
|
114
|
+
result, Nan::New("info").ToLocalChecked(), sfmljs::MapTexture(texture))
|
|
115
|
+
.FromJust();
|
|
116
|
+
Nan::Set(result,
|
|
117
|
+
Nan::New("handle").ToLocalChecked(),
|
|
118
|
+
TextureHandle::Create(texture))
|
|
119
|
+
.FromJust();
|
|
120
|
+
Nan::Set(result, Nan::New("id").ToLocalChecked(), Nan::New(texture->id))
|
|
121
|
+
.FromJust();
|
|
116
122
|
info.GetReturnValue().Set(result);
|
|
117
123
|
} catch (const std::exception& error) {
|
|
118
124
|
sfmljs::ThrowError(error.what());
|
|
@@ -145,7 +151,8 @@ NAN_METHOD(CopyTextureToImage) {
|
|
|
145
151
|
return Nan::ThrowRangeError("Texture exceeds the image readback limit");
|
|
146
152
|
}
|
|
147
153
|
try {
|
|
148
|
-
info.GetReturnValue().Set(sfmljs::MapImageResource(
|
|
154
|
+
info.GetReturnValue().Set(sfmljs::MapImageResource(
|
|
155
|
+
info.GetIsolate(),
|
|
149
156
|
std::make_shared<sf::Image>(texture->copyToImage())));
|
|
150
157
|
} catch (const std::exception& error) {
|
|
151
158
|
sfmljs::ThrowError(error.what());
|
|
@@ -162,8 +169,7 @@ NAN_METHOD(GetTextureNativeHandle) {
|
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
NAN_METHOD(BindTexture) {
|
|
165
|
-
if (!info[1]->IsUint32() ||
|
|
166
|
-
Nan::To<std::uint32_t>(info[1]).FromJust() > 1) {
|
|
172
|
+
if (!info[1]->IsUint32() || Nan::To<std::uint32_t>(info[1]).FromJust() > 1) {
|
|
167
173
|
return Nan::ThrowRangeError("Expected a CoordinateType");
|
|
168
174
|
}
|
|
169
175
|
std::shared_ptr<const sf::Texture> texture;
|
|
@@ -171,8 +177,9 @@ NAN_METHOD(BindTexture) {
|
|
|
171
177
|
texture = sfmljs::ReadTexture(info[0]);
|
|
172
178
|
if (!texture) return;
|
|
173
179
|
}
|
|
174
|
-
sf::Texture::bind(texture.get(),
|
|
175
|
-
|
|
180
|
+
sf::Texture::bind(texture.get(),
|
|
181
|
+
static_cast<sf::CoordinateType>(
|
|
182
|
+
Nan::To<std::uint32_t>(info[1]).FromJust()));
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
NAN_METHOD(GenerateTextureMipmap) {
|
|
@@ -244,9 +251,9 @@ NAN_METHOD(UpdateTexture) {
|
|
|
244
251
|
if (!sfmljs::ReadImageBytes(info[1], pixels)) return;
|
|
245
252
|
auto size = texture->owner()->getSize();
|
|
246
253
|
sf::Vector2u dest;
|
|
247
|
-
if (info.Length() != 2 &&
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
if (info.Length() != 2 && (!sfmljs::ReadImageSize(info[2], info[3], size) ||
|
|
255
|
+
!ReadPosition(info[4], info[5], dest)))
|
|
256
|
+
return;
|
|
250
257
|
if (!CheckRegion(*texture->owner(), size, dest)) return;
|
|
251
258
|
const auto required = static_cast<std::uint64_t>(size.x) * size.y * 4;
|
|
252
259
|
if (pixels.size() != required) {
|
|
@@ -304,8 +311,10 @@ NAN_METHOD(SetSampling) {
|
|
|
304
311
|
auto* texture = TextureHandle::From(info[0]);
|
|
305
312
|
if (!texture) return;
|
|
306
313
|
if (!info[1]->IsBoolean()) return Nan::ThrowTypeError("Expected a boolean");
|
|
307
|
-
if constexpr (Smooth)
|
|
308
|
-
|
|
314
|
+
if constexpr (Smooth)
|
|
315
|
+
texture->owner()->setSmooth(info[1]->IsTrue());
|
|
316
|
+
else
|
|
317
|
+
texture->owner()->setRepeated(info[1]->IsTrue());
|
|
309
318
|
}
|
|
310
319
|
|
|
311
320
|
} // namespace
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#include "numeric-fields.h"
|
|
4
|
-
|
|
5
4
|
#include <SFML/Graphics/Texture.hpp>
|
|
6
5
|
|
|
7
6
|
namespace sfmljs {
|
|
@@ -16,15 +15,18 @@ inline v8::Local<v8::Object> MapTexture(
|
|
|
16
15
|
const std::shared_ptr<const sf::Texture>& texture) {
|
|
17
16
|
const auto& size = Field<TextureSize>(*texture);
|
|
18
17
|
return NumericFields()
|
|
19
|
-
.Add("width", size.x)
|
|
18
|
+
.Add("width", size.x)
|
|
19
|
+
.Add("height", size.y)
|
|
20
20
|
.Add("nativeHandle", Field<TextureId>(*texture))
|
|
21
21
|
.Add("smooth", Field<TextureSmooth>(*texture))
|
|
22
22
|
.Add("sRgb", Field<TextureSrgb>(*texture))
|
|
23
|
-
.Add("repeated", Field<TextureRepeated>(*texture))
|
|
23
|
+
.Add("repeated", Field<TextureRepeated>(*texture))
|
|
24
|
+
.Map(texture);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// RenderTexture lends a const alias; ordinary Texture owns a writable handle.
|
|
27
|
-
inline std::shared_ptr<const sf::Texture> ReadTexture(
|
|
28
|
+
inline std::shared_ptr<const sf::Texture> ReadTexture(
|
|
29
|
+
v8::Local<v8::Value> value) {
|
|
28
30
|
if (auto* handle = SharedHandle<sf::Texture>::TryFrom(value)) {
|
|
29
31
|
return handle->owner();
|
|
30
32
|
}
|
|
@@ -38,14 +40,20 @@ inline std::shared_ptr<const sf::Texture> ReadTexture(v8::Local<v8::Value> value
|
|
|
38
40
|
inline v8::Local<v8::Object> DescribeTexture(const sf::Texture& texture) {
|
|
39
41
|
auto result = Nan::New<v8::Object>();
|
|
40
42
|
const auto size = texture.getSize();
|
|
41
|
-
Nan::Set(result, Nan::New("width").ToLocalChecked(), Nan::New(size.x))
|
|
42
|
-
|
|
43
|
-
Nan::Set(result, Nan::New("
|
|
44
|
-
|
|
45
|
-
Nan::Set(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
Nan::Set(result, Nan::New("width").ToLocalChecked(), Nan::New(size.x))
|
|
44
|
+
.FromJust();
|
|
45
|
+
Nan::Set(result, Nan::New("height").ToLocalChecked(), Nan::New(size.y))
|
|
46
|
+
.FromJust();
|
|
47
|
+
Nan::Set(
|
|
48
|
+
result, Nan::New("smooth").ToLocalChecked(), Nan::New(texture.isSmooth()))
|
|
49
|
+
.FromJust();
|
|
50
|
+
Nan::Set(result,
|
|
51
|
+
Nan::New("repeated").ToLocalChecked(),
|
|
52
|
+
Nan::New(texture.isRepeated()))
|
|
53
|
+
.FromJust();
|
|
54
|
+
Nan::Set(
|
|
55
|
+
result, Nan::New("sRgb").ToLocalChecked(), Nan::New(texture.isSrgb()))
|
|
56
|
+
.FromJust();
|
|
49
57
|
return result;
|
|
50
58
|
}
|
|
51
59
|
|
package/native/time-value.h
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#include <nan.h>
|
|
4
|
+
|
|
4
5
|
#include <SFML/System/Time.hpp>
|
|
5
6
|
|
|
6
7
|
namespace sfmljs {
|
|
7
8
|
|
|
8
9
|
// Durations cross the binding by value. No persistent owner or mapped buffer.
|
|
9
|
-
inline bool ReadTime(v8::Local<v8::Value> value,
|
|
10
|
+
inline bool ReadTime(v8::Local<v8::Value> value,
|
|
11
|
+
sf::Time& result) { // NOLINT(runtime/references)
|
|
10
12
|
if (!value->IsBigInt()) {
|
|
11
13
|
Nan::ThrowTypeError("Expected a microsecond bigint");
|
|
12
14
|
return false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#include "transformable-state.h"
|
|
2
1
|
#include "exception-boundary.h"
|
|
2
|
+
#include "transformable-state.h"
|
|
3
3
|
|
|
4
4
|
namespace {
|
|
5
5
|
|
|
@@ -8,11 +8,17 @@ NAN_METHOD(CreateTransformable) {
|
|
|
8
8
|
const auto state = std::shared_ptr<sfmljs::TransformableState>(
|
|
9
9
|
object, static_cast<sfmljs::TransformableState*>(object.get()));
|
|
10
10
|
const auto result = Nan::New<v8::Object>();
|
|
11
|
-
Nan::Set(result,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
Nan::Set(result,
|
|
12
|
+
Nan::New("handle").ToLocalChecked(),
|
|
13
|
+
sfmljs::TransformableHandle(state))
|
|
14
|
+
.FromJust();
|
|
15
|
+
Nan::Set(result,
|
|
16
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
17
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
18
|
+
state,
|
|
19
|
+
state->values.data(),
|
|
20
|
+
sizeof(state->values)))
|
|
21
|
+
.FromJust();
|
|
16
22
|
info.GetReturnValue().Set(result);
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "shared-handle.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/Graphics/Transformable.hpp>
|
|
6
|
-
|
|
7
3
|
#include <array>
|
|
8
4
|
#include <cstddef>
|
|
9
5
|
|
|
6
|
+
#include "shared-handle.h"
|
|
7
|
+
#include <SFML/Graphics/Transformable.hpp>
|
|
8
|
+
|
|
10
9
|
namespace sfmljs {
|
|
11
10
|
|
|
12
11
|
// position.xy, rotation (radians), scale.xy, origin.xy.
|
|
13
12
|
using TransformableData = std::array<float, 7>;
|
|
14
13
|
static_assert(sizeof(TransformableData) == 28);
|
|
15
14
|
|
|
16
|
-
inline void ApplyTransform(
|
|
17
|
-
|
|
15
|
+
inline void ApplyTransform(
|
|
16
|
+
sf::Transformable& object, // NOLINT(runtime/references)
|
|
17
|
+
const TransformableData& values) {
|
|
18
18
|
object.setPosition({values[0], values[1]});
|
|
19
19
|
object.setRotation(sf::radians(values[2]));
|
|
20
20
|
object.setScale({values[3], values[4]});
|
package/native/value-binding.h
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "shared-handle.h"
|
|
4
|
-
#include "value-layout.h"
|
|
5
|
-
|
|
6
3
|
#include <array>
|
|
7
|
-
#include <bit>
|
|
4
|
+
#include <bit> // NOLINT(build/include_order): cpplint lacks C++20 headers
|
|
8
5
|
#include <cstdint>
|
|
9
6
|
#include <cstring>
|
|
10
7
|
#include <memory>
|
|
@@ -12,22 +9,30 @@
|
|
|
12
9
|
#include <string_view>
|
|
13
10
|
#include <type_traits>
|
|
14
11
|
|
|
12
|
+
#include "shared-handle.h"
|
|
13
|
+
#include "value-layout.h"
|
|
14
|
+
|
|
15
15
|
namespace sfmljs::values {
|
|
16
16
|
|
|
17
17
|
using CallbackInfo = Nan::FunctionCallbackInfo<v8::Value>;
|
|
18
18
|
|
|
19
19
|
template <typename T>
|
|
20
|
-
void ReturnMapped(const CallbackInfo& info,
|
|
20
|
+
void ReturnMapped(const CallbackInfo& info,
|
|
21
|
+
const std::shared_ptr<T>& owner,
|
|
21
22
|
std::shared_ptr<v8::BackingStore> backing = {}) {
|
|
22
23
|
static_assert(std::is_standard_layout_v<T>);
|
|
23
24
|
static_assert(std::is_trivially_copyable_v<T>);
|
|
24
25
|
static_assert(sizeof(T) == Layout<T>::bytes);
|
|
25
26
|
auto result = Nan::New<v8::Object>();
|
|
26
|
-
Nan::Set(result,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
Nan::Set(result,
|
|
28
|
+
Nan::New("handle").ToLocalChecked(),
|
|
29
|
+
SharedHandle<T>::Create(owner))
|
|
30
|
+
.FromJust();
|
|
31
|
+
Nan::Set(result,
|
|
32
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
33
|
+
backing
|
|
34
|
+
? v8::ArrayBuffer::New(info.GetIsolate(), std::move(backing))
|
|
35
|
+
: MapShared(info.GetIsolate(), owner, owner.get(), sizeof(T)))
|
|
31
36
|
.FromJust();
|
|
32
37
|
info.GetReturnValue().Set(result);
|
|
33
38
|
}
|
|
@@ -82,8 +87,8 @@ void WrapBackingStore(const CallbackInfo& info, v8::Local<v8::Value> input) {
|
|
|
82
87
|
template <typename T>
|
|
83
88
|
constexpr std::string_view ScalarName() {
|
|
84
89
|
static_assert(std::is_same_v<T, int> || std::is_same_v<T, unsigned int> ||
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
std::is_same_v<T, float> || std::is_same_v<T, double> ||
|
|
91
|
+
std::is_integral_v<T>,
|
|
87
92
|
"Unsupported value scalar");
|
|
88
93
|
if constexpr (std::is_same_v<T, int>) return "i32";
|
|
89
94
|
if constexpr (std::is_same_v<T, unsigned int>) return "u32";
|
|
@@ -109,9 +114,10 @@ struct Family {
|
|
|
109
114
|
}
|
|
110
115
|
const Nan::Utf8String input(type);
|
|
111
116
|
const std::string_view name(*input, input.length());
|
|
112
|
-
const bool found =
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
const bool found = ((name == ScalarName<typename Layout<Types>::Scalar>()
|
|
118
|
+
? (callback.template operator()<Types>(), true)
|
|
119
|
+
: false) ||
|
|
120
|
+
...);
|
|
115
121
|
if (!found) Nan::ThrowTypeError("Unsupported value scalar type");
|
|
116
122
|
}
|
|
117
123
|
|
|
@@ -147,7 +153,8 @@ struct Family {
|
|
|
147
153
|
if (info.Length() != 2) {
|
|
148
154
|
return Nan::ThrowTypeError("Expected a scalar type and ArrayBuffer");
|
|
149
155
|
}
|
|
150
|
-
Select(info[0],
|
|
156
|
+
Select(info[0],
|
|
157
|
+
[&]<typename T>() { WrapBackingStore<T>(info, info[1]); });
|
|
151
158
|
}
|
|
152
159
|
}
|
|
153
160
|
};
|
|
@@ -158,20 +165,27 @@ using Mat3Values = Family<sf::Glsl::Mat3>;
|
|
|
158
165
|
using Mat4Values = Family<sf::Glsl::Mat4>;
|
|
159
166
|
using ColorValues = Family<sf::Color>;
|
|
160
167
|
template <template <typename> typename Vector>
|
|
161
|
-
using VectorValues = Family<Vector<int>,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
using VectorValues = Family<Vector<int>,
|
|
169
|
+
Vector<unsigned>,
|
|
170
|
+
Vector<float>,
|
|
171
|
+
Vector<bool>,
|
|
172
|
+
Vector<double>,
|
|
173
|
+
Vector<std::int8_t>,
|
|
174
|
+
Vector<std::uint8_t>,
|
|
175
|
+
Vector<std::int16_t>,
|
|
176
|
+
Vector<std::uint16_t>,
|
|
177
|
+
Vector<std::int64_t>,
|
|
178
|
+
Vector<std::uint64_t>>;
|
|
165
179
|
using Vector2Values = VectorValues<sf::Vector2>;
|
|
166
180
|
using Vector3Values = VectorValues<sf::Vector3>;
|
|
167
|
-
using Vector4Values =
|
|
168
|
-
Family<sf::Glsl::Vec4, sf::Glsl::Ivec4, sf::Glsl::Bvec4>;
|
|
181
|
+
using Vector4Values = Family<sf::Glsl::Vec4, sf::Glsl::Ivec4, sf::Glsl::Bvec4>;
|
|
169
182
|
using RectValues = Family<sf::IntRect, sf::FloatRect>;
|
|
170
183
|
using VertexValues = Family<sf::Vertex>;
|
|
171
184
|
|
|
172
185
|
template <typename Parent, typename Member>
|
|
173
186
|
void ReturnMember(const CallbackInfo& info,
|
|
174
|
-
const std::shared_ptr<Parent>& owner,
|
|
187
|
+
const std::shared_ptr<Parent>& owner,
|
|
188
|
+
Member Parent::*field) {
|
|
175
189
|
// Point to the real member while sharing the parent's control block.
|
|
176
190
|
ReturnMapped(info, std::shared_ptr<Member>(owner, &(owner.get()->*field)));
|
|
177
191
|
}
|
|
@@ -189,11 +203,15 @@ void Member(const CallbackInfo& info) {
|
|
|
189
203
|
if (index >= std::tuple_size_v<decltype(members)>) {
|
|
190
204
|
return Nan::ThrowTypeError("Expected a valid value member index");
|
|
191
205
|
}
|
|
192
|
-
std::apply(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
206
|
+
std::apply(
|
|
207
|
+
[&](auto... fields) {
|
|
208
|
+
std::size_t current = 0;
|
|
209
|
+
return ((index == current++
|
|
210
|
+
? (ReturnMember(info, owner, fields), true)
|
|
211
|
+
: false) ||
|
|
212
|
+
...);
|
|
213
|
+
},
|
|
214
|
+
members);
|
|
197
215
|
});
|
|
198
216
|
}
|
|
199
217
|
|
package/native/value-layout.h
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
#include <tuple>
|
|
5
|
+
#include <type_traits>
|
|
6
|
+
|
|
3
7
|
#include <SFML/Graphics/Color.hpp>
|
|
4
8
|
#include <SFML/Graphics/Glsl.hpp>
|
|
5
9
|
#include <SFML/Graphics/Glyph.hpp>
|
|
@@ -10,10 +14,6 @@
|
|
|
10
14
|
#include <SFML/System/Vector2.hpp>
|
|
11
15
|
#include <SFML/System/Vector3.hpp>
|
|
12
16
|
|
|
13
|
-
#include <cstddef>
|
|
14
|
-
#include <tuple>
|
|
15
|
-
#include <type_traits>
|
|
16
|
-
|
|
17
17
|
namespace sfmljs::values {
|
|
18
18
|
|
|
19
19
|
// No default layout: exposing a new native value requires an explicit contract.
|
|
@@ -46,8 +46,8 @@ struct Layout<sf::Vector2<T>> {
|
|
|
46
46
|
using Scalar = T;
|
|
47
47
|
using Value = sf::Vector2<T>;
|
|
48
48
|
static constexpr std::size_t bytes = 2 * sizeof(T);
|
|
49
|
-
static_assert(sizeof(T) == 1 || sizeof(T) == 2 ||
|
|
50
|
-
sizeof(T) ==
|
|
49
|
+
static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 ||
|
|
50
|
+
sizeof(T) == 8);
|
|
51
51
|
static_assert(offsetof(Value, x) == 0 && offsetof(Value, y) == sizeof(T));
|
|
52
52
|
};
|
|
53
53
|
|
|
@@ -56,8 +56,8 @@ struct Layout<sf::Vector3<T>> {
|
|
|
56
56
|
using Scalar = T;
|
|
57
57
|
using Value = sf::Vector3<T>;
|
|
58
58
|
static constexpr std::size_t bytes = 3 * sizeof(T);
|
|
59
|
-
static_assert(sizeof(T) == 1 || sizeof(T) == 2 ||
|
|
60
|
-
sizeof(T) ==
|
|
59
|
+
static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 ||
|
|
60
|
+
sizeof(T) == 8);
|
|
61
61
|
static_assert(offsetof(Value, x) == 0 && offsetof(Value, y) == sizeof(T) &&
|
|
62
62
|
offsetof(Value, z) == 2 * sizeof(T));
|
|
63
63
|
};
|
|
@@ -104,8 +104,8 @@ struct Layout<sf::Vertex> {
|
|
|
104
104
|
template <>
|
|
105
105
|
struct Layout<sf::Glyph> {
|
|
106
106
|
static constexpr std::size_t bytes = 44;
|
|
107
|
-
static constexpr auto members =
|
|
108
|
-
&sf::Glyph::bounds, &sf::Glyph::textureRect};
|
|
107
|
+
static constexpr auto members =
|
|
108
|
+
std::tuple{&sf::Glyph::bounds, &sf::Glyph::textureRect};
|
|
109
109
|
static_assert(offsetof(sf::Glyph, advance) == 0 &&
|
|
110
110
|
offsetof(sf::Glyph, lsbDelta) == 4 &&
|
|
111
111
|
offsetof(sf::Glyph, rsbDelta) == 8 &&
|
package/native/values-binding.cc
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
#include "value-binding.h"
|
|
2
1
|
#include "exception-boundary.h"
|
|
2
|
+
#include "value-binding.h"
|
|
3
3
|
|
|
4
4
|
NAN_MODULE_INIT(InitializeValues) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sfmljs::SetMethod<
|
|
8
|
-
|
|
9
|
-
sfmljs::SetMethod<TransformValues::
|
|
10
|
-
|
|
11
|
-
sfmljs::SetMethod<Mat3Values::Wrap>(target, "wrapMat3");
|
|
12
|
-
sfmljs::SetMethod<Mat4Values::Wrap>(target, "wrapMat4");
|
|
13
|
-
sfmljs::SetMethod<Vector2Values::Create>(target,
|
|
14
|
-
|
|
15
|
-
sfmljs::SetMethod<
|
|
16
|
-
sfmljs::SetMethod<Vector3Values::
|
|
17
|
-
|
|
18
|
-
sfmljs::SetMethod<
|
|
19
|
-
sfmljs::SetMethod<
|
|
20
|
-
|
|
21
|
-
sfmljs::SetMethod<
|
|
22
|
-
sfmljs::SetMethod<
|
|
23
|
-
sfmljs::SetMethod<
|
|
24
|
-
sfmljs::SetMethod<
|
|
25
|
-
sfmljs::SetMethod<
|
|
26
|
-
sfmljs::SetMethod<Member<
|
|
5
|
+
sfmljs::SetMethod<sfmljs::values::AngleValues::Create>(target, "createAngle");
|
|
6
|
+
sfmljs::SetMethod<sfmljs::values::AngleValues::Wrap>(target, "wrapAngle");
|
|
7
|
+
sfmljs::SetMethod<sfmljs::values::TransformValues::Create>(target,
|
|
8
|
+
"createTransform");
|
|
9
|
+
sfmljs::SetMethod<sfmljs::values::TransformValues::Wrap>(target,
|
|
10
|
+
"wrapTransform");
|
|
11
|
+
sfmljs::SetMethod<sfmljs::values::Mat3Values::Wrap>(target, "wrapMat3");
|
|
12
|
+
sfmljs::SetMethod<sfmljs::values::Mat4Values::Wrap>(target, "wrapMat4");
|
|
13
|
+
sfmljs::SetMethod<sfmljs::values::Vector2Values::Create>(target,
|
|
14
|
+
"createVector2");
|
|
15
|
+
sfmljs::SetMethod<sfmljs::values::Vector2Values::Wrap>(target, "wrapVector2");
|
|
16
|
+
sfmljs::SetMethod<sfmljs::values::Vector3Values::Create>(target,
|
|
17
|
+
"createVector3");
|
|
18
|
+
sfmljs::SetMethod<sfmljs::values::Vector3Values::Wrap>(target, "wrapVector3");
|
|
19
|
+
sfmljs::SetMethod<sfmljs::values::Vector4Values::Create>(target,
|
|
20
|
+
"createVector4");
|
|
21
|
+
sfmljs::SetMethod<sfmljs::values::Vector4Values::Wrap>(target, "wrapVector4");
|
|
22
|
+
sfmljs::SetMethod<sfmljs::values::ColorValues::Create>(target, "createColor");
|
|
23
|
+
sfmljs::SetMethod<sfmljs::values::ColorValues::Wrap>(target, "wrapColor");
|
|
24
|
+
sfmljs::SetMethod<sfmljs::values::RectValues::Create>(target, "createRect");
|
|
25
|
+
sfmljs::SetMethod<sfmljs::values::RectValues::Wrap>(target, "wrapRect");
|
|
26
|
+
sfmljs::SetMethod<sfmljs::values::Member<sfmljs::values::RectValues>>(
|
|
27
|
+
target, "rectMember");
|
|
28
|
+
sfmljs::SetMethod<sfmljs::values::VertexValues::Create>(target,
|
|
29
|
+
"createVertex");
|
|
30
|
+
sfmljs::SetMethod<sfmljs::values::VertexValues::Wrap>(target, "wrapVertex");
|
|
31
|
+
sfmljs::SetMethod<sfmljs::values::Member<sfmljs::values::VertexValues>>(
|
|
32
|
+
target, "vertexMember");
|
|
27
33
|
}
|
package/native/vertex-binding.cc
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <exception>
|
|
2
|
+
|
|
2
3
|
#include "exception-boundary.h"
|
|
3
4
|
#include "value-binding.h"
|
|
4
|
-
|
|
5
|
-
#include <exception>
|
|
5
|
+
#include "vertex-storage.h"
|
|
6
6
|
|
|
7
7
|
namespace {
|
|
8
8
|
|
|
@@ -15,14 +15,18 @@ NAN_METHOD(CreateVertexStorage) {
|
|
|
15
15
|
return Nan::ThrowRangeError("Vertex capacity exceeds the buffer limit");
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
auto storage =
|
|
19
|
-
Nan::To<std::uint32_t>(info[0]).FromJust());
|
|
18
|
+
auto storage =
|
|
19
|
+
std::make_shared<Storage>(Nan::To<std::uint32_t>(info[0]).FromJust());
|
|
20
20
|
auto result = Nan::New<v8::Object>();
|
|
21
|
-
auto buffer = storage->empty()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
auto buffer = storage->empty()
|
|
22
|
+
? v8::ArrayBuffer::New(info.GetIsolate(), 0)
|
|
23
|
+
: sfmljs::MapShared(info.GetIsolate(),
|
|
24
|
+
storage,
|
|
25
|
+
storage->data(),
|
|
26
|
+
storage->size() * sizeof(sf::Vertex));
|
|
27
|
+
Nan::Set(
|
|
28
|
+
result, Nan::New("handle").ToLocalChecked(), Handle::Create(storage))
|
|
29
|
+
.FromJust();
|
|
26
30
|
Nan::Set(result, Nan::New("buffer").ToLocalChecked(), buffer).FromJust();
|
|
27
31
|
info.GetReturnValue().Set(result);
|
|
28
32
|
} catch (const std::exception& error) {
|
|
@@ -38,8 +42,10 @@ NAN_METHOD(VertexStorageMember) {
|
|
|
38
42
|
return Nan::ThrowRangeError("Vertex index is out of range");
|
|
39
43
|
}
|
|
40
44
|
const auto index = Nan::To<std::uint32_t>(info[1]).FromJust();
|
|
41
|
-
sfmljs::values::ReturnMapped(
|
|
42
|
-
|
|
45
|
+
sfmljs::values::ReturnMapped(
|
|
46
|
+
info,
|
|
47
|
+
std::shared_ptr<sf::Vertex>(storage->owner(),
|
|
48
|
+
&(*storage->owner())[index]));
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
} // namespace
|