sfml.js 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +40 -48
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/native/graphics-state.h
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <cstddef>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
3
11
|
#include "batch-drawable.h"
|
|
4
12
|
#include "deferred-delete.h"
|
|
5
13
|
#include "texture-resource.h"
|
|
6
14
|
#include "transformable-state.h"
|
|
7
|
-
|
|
8
15
|
#include <SFML/Graphics/RenderTexture.hpp>
|
|
9
16
|
#include <SFML/Graphics/RenderWindow.hpp>
|
|
10
17
|
#include <SFML/Graphics/Shader.hpp>
|
|
@@ -15,14 +22,6 @@
|
|
|
15
22
|
#include <SFML/System/Vector2.hpp>
|
|
16
23
|
#include <SFML/Window/Event.hpp>
|
|
17
24
|
|
|
18
|
-
#include <array>
|
|
19
|
-
#include <cstddef>
|
|
20
|
-
#include <cstdint>
|
|
21
|
-
#include <memory>
|
|
22
|
-
#include <string>
|
|
23
|
-
#include <unordered_map>
|
|
24
|
-
#include <vector>
|
|
25
|
-
|
|
26
25
|
namespace sfmljs {
|
|
27
26
|
|
|
28
27
|
static_assert(sizeof(sf::Vector2f) == 8);
|
|
@@ -39,7 +38,8 @@ struct GraphicsContext {
|
|
|
39
38
|
std::uint32_t nextId{1};
|
|
40
39
|
std::unordered_map<std::uint32_t, std::weak_ptr<SpriteState>> sprites;
|
|
41
40
|
std::unordered_map<std::uint32_t, std::weak_ptr<const sf::Texture>> textures;
|
|
42
|
-
std::unordered_map<std::uint32_t, std::weak_ptr<VertexBufferState>>
|
|
41
|
+
std::unordered_map<std::uint32_t, std::weak_ptr<VertexBufferState>>
|
|
42
|
+
vertexBuffers;
|
|
43
43
|
std::unordered_map<std::uint32_t, std::weak_ptr<ShaderState>> shaders;
|
|
44
44
|
std::unordered_map<std::uint32_t, std::weak_ptr<ShapeState>> shapes;
|
|
45
45
|
};
|
|
@@ -57,8 +57,10 @@ struct ShaderState : sf::GlResource {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
struct VertexBufferState : sf::VertexBuffer {
|
|
60
|
-
VertexBufferState(std::shared_ptr<GraphicsContext> context,
|
|
61
|
-
|
|
60
|
+
VertexBufferState(std::shared_ptr<GraphicsContext> context,
|
|
61
|
+
std::uint32_t id,
|
|
62
|
+
sf::PrimitiveType type,
|
|
63
|
+
Usage usage)
|
|
62
64
|
: sf::VertexBuffer(type, usage), context(std::move(context)), id(id) {}
|
|
63
65
|
~VertexBufferState() { context->vertexBuffers.erase(id); }
|
|
64
66
|
std::shared_ptr<GraphicsContext> context;
|
|
@@ -68,7 +70,8 @@ struct VertexBufferState : sf::VertexBuffer {
|
|
|
68
70
|
struct TextureState : sf::Texture {
|
|
69
71
|
TextureState(std::shared_ptr<GraphicsContext> context, std::uint32_t id)
|
|
70
72
|
: context(std::move(context)), id(id) {}
|
|
71
|
-
TextureState(std::shared_ptr<GraphicsContext> context,
|
|
73
|
+
TextureState(std::shared_ptr<GraphicsContext> context,
|
|
74
|
+
std::uint32_t id,
|
|
72
75
|
const sf::Texture& source)
|
|
73
76
|
: sf::Texture(source), context(std::move(context)), id(id) {}
|
|
74
77
|
~TextureState() { context->textures.erase(id); }
|
|
@@ -85,7 +88,8 @@ static_assert(sizeof(SpriteAppearance) == 24);
|
|
|
85
88
|
static_assert(offsetof(SpriteAppearance, rectangle) == 4);
|
|
86
89
|
static_assert(offsetof(SpriteAppearance, color) == 20);
|
|
87
90
|
|
|
88
|
-
inline void ApplyAppearance(sf::Sprite& sprite,
|
|
91
|
+
inline void ApplyAppearance(sf::Sprite& sprite, // NOLINT(runtime/references)
|
|
92
|
+
const sf::Texture& texture,
|
|
89
93
|
const SpriteAppearance& appearance) {
|
|
90
94
|
sprite.setTexture(texture);
|
|
91
95
|
sprite.setTextureRect(appearance.rectangle);
|
|
@@ -94,11 +98,14 @@ inline void ApplyAppearance(sf::Sprite& sprite, const sf::Texture& texture,
|
|
|
94
98
|
|
|
95
99
|
struct SpriteState : sf::Sprite, TransformableState {
|
|
96
100
|
SpriteState(std::shared_ptr<GraphicsContext> context,
|
|
97
|
-
std::shared_ptr<const sf::Texture> texture,
|
|
101
|
+
std::shared_ptr<const sf::Texture> texture,
|
|
102
|
+
std::uint32_t id,
|
|
98
103
|
std::uint32_t textureId)
|
|
99
104
|
: sf::Sprite(*texture),
|
|
100
105
|
TransformableState(static_cast<sf::Transformable*>(this)),
|
|
101
|
-
context(std::move(context)),
|
|
106
|
+
context(std::move(context)),
|
|
107
|
+
texture(std::move(texture)),
|
|
108
|
+
id(id),
|
|
102
109
|
appearance{textureId, getTextureRect(), 0xffffffff} {}
|
|
103
110
|
|
|
104
111
|
~SpriteState() { context->sprites.erase(id); }
|
|
@@ -122,36 +129,43 @@ struct DrawStates {
|
|
|
122
129
|
std::array<std::uint32_t, 5> stencil{};
|
|
123
130
|
|
|
124
131
|
bool Valid() const {
|
|
125
|
-
return blend[0] <= 9 && blend[1] <= 9 && blend[2] <= 4 &&
|
|
126
|
-
blend[
|
|
127
|
-
stencil[
|
|
132
|
+
return blend[0] <= 9 && blend[1] <= 9 && blend[2] <= 4 && blend[3] <= 9 &&
|
|
133
|
+
blend[4] <= 9 && blend[5] <= 4 && stencil[0] <= 7 &&
|
|
134
|
+
stencil[1] <= 5 && stencil[4] <= 1;
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
sf::RenderStates Make() const {
|
|
131
138
|
sf::RenderStates result;
|
|
132
|
-
result.transform = sf::Transform(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
result.transform = sf::Transform(matrix[0],
|
|
140
|
+
matrix[4],
|
|
141
|
+
matrix[12],
|
|
142
|
+
matrix[1],
|
|
143
|
+
matrix[5],
|
|
144
|
+
matrix[13],
|
|
145
|
+
matrix[3],
|
|
146
|
+
matrix[7],
|
|
147
|
+
matrix[15]);
|
|
136
148
|
using F = sf::BlendMode::Factor;
|
|
137
149
|
using E = sf::BlendMode::Equation;
|
|
138
|
-
result.blendMode = sf::BlendMode(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
result.blendMode = sf::BlendMode(static_cast<F>(blend[0]),
|
|
151
|
+
static_cast<F>(blend[1]),
|
|
152
|
+
static_cast<E>(blend[2]),
|
|
153
|
+
static_cast<F>(blend[3]),
|
|
154
|
+
static_cast<F>(blend[4]),
|
|
155
|
+
static_cast<E>(blend[5]));
|
|
156
|
+
result.stencilMode = {static_cast<sf::StencilComparison>(stencil[0]),
|
|
157
|
+
static_cast<sf::StencilUpdateOperation>(stencil[1]),
|
|
158
|
+
sf::StencilValue(stencil[2]),
|
|
159
|
+
sf::StencilValue(stencil[3]),
|
|
160
|
+
stencil[4] != 0};
|
|
147
161
|
return result;
|
|
148
162
|
}
|
|
149
163
|
};
|
|
150
164
|
|
|
151
|
-
// 0: clear color, 1: sprite, 2: clear color+stencil, 3: clear stencil, 4:
|
|
152
|
-
// 5: set view (13 floats at states.matrix, remaining command fields
|
|
153
|
-
// 6: GPU vertices (vertex payload followed by vertex buffer ID).
|
|
154
|
-
//
|
|
165
|
+
// 0: clear color, 1: sprite, 2: clear color+stencil, 3: clear stencil, 4:
|
|
166
|
+
// vertices. 5: set view (13 floats at states.matrix, remaining command fields
|
|
167
|
+
// unused). 6: GPU vertices (vertex payload followed by vertex buffer ID). 7:
|
|
168
|
+
// shape ID, ShapeAppearance in payload, combined matrix in states.
|
|
155
169
|
struct DrawCommand {
|
|
156
170
|
std::uint32_t type{};
|
|
157
171
|
std::uint32_t argument{};
|
package/native/image-binding.cc
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
#include "image-state.h"
|
|
2
|
-
#include "exception-boundary.h"
|
|
3
|
-
|
|
4
1
|
#include <exception>
|
|
5
2
|
#include <filesystem>
|
|
6
3
|
#include <optional>
|
|
7
4
|
#include <string>
|
|
8
5
|
#include <vector>
|
|
9
6
|
|
|
7
|
+
#include "exception-boundary.h"
|
|
8
|
+
#include "image-state.h"
|
|
9
|
+
|
|
10
10
|
namespace {
|
|
11
11
|
|
|
12
12
|
using sfmljs::ImageHandle;
|
|
@@ -83,8 +83,10 @@ NAN_METHOD(FlipImage) {
|
|
|
83
83
|
auto* handle = ImageHandle::From(info[0]);
|
|
84
84
|
if (!handle) return;
|
|
85
85
|
if (!info[1]->IsBoolean()) return Nan::ThrowTypeError("Expected flip axis");
|
|
86
|
-
if (info[1]->IsTrue())
|
|
87
|
-
|
|
86
|
+
if (info[1]->IsTrue())
|
|
87
|
+
handle->owner()->current->flipHorizontally();
|
|
88
|
+
else
|
|
89
|
+
handle->owner()->current->flipVertically();
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
NAN_METHOD(CopyImage) {
|
|
@@ -92,10 +94,11 @@ NAN_METHOD(CopyImage) {
|
|
|
92
94
|
if (!dest) return;
|
|
93
95
|
auto* source = ImageHandle::From(info[1]);
|
|
94
96
|
if (!source) return;
|
|
95
|
-
if (!info[2]->IsUint32() || !info[3]->IsUint32() ||
|
|
96
|
-
!info[
|
|
97
|
-
!info[
|
|
98
|
-
return Nan::ThrowTypeError(
|
|
97
|
+
if (!info[2]->IsUint32() || !info[3]->IsUint32() || !info[4]->IsInt32() ||
|
|
98
|
+
!info[5]->IsInt32() || !info[6]->IsInt32() || !info[7]->IsInt32() ||
|
|
99
|
+
!info[8]->IsBoolean()) {
|
|
100
|
+
return Nan::ThrowTypeError(
|
|
101
|
+
"Expected image copy coordinates and alpha flag");
|
|
99
102
|
}
|
|
100
103
|
const sf::Vector2u position{Nan::To<std::uint32_t>(info[2]).FromJust(),
|
|
101
104
|
Nan::To<std::uint32_t>(info[3]).FromJust()};
|
|
@@ -120,13 +123,18 @@ enum class ImageJob { LoadFile, LoadMemory, SaveFile, SaveMemory };
|
|
|
120
123
|
|
|
121
124
|
class ImageWorker final : public sfmljs::AsyncWorker {
|
|
122
125
|
public:
|
|
123
|
-
ImageWorker(Nan::Callback* callback,
|
|
126
|
+
ImageWorker(Nan::Callback* callback,
|
|
127
|
+
ImageJob job,
|
|
124
128
|
std::shared_ptr<ImageState> state,
|
|
125
|
-
std::shared_ptr<sf::Image> snapshot,
|
|
129
|
+
std::shared_ptr<sf::Image> snapshot,
|
|
130
|
+
std::string text,
|
|
126
131
|
std::vector<std::uint8_t> input)
|
|
127
|
-
: sfmljs::AsyncWorker(callback, "sfml:Image"),
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
: sfmljs::AsyncWorker(callback, "sfml:Image"),
|
|
133
|
+
job_(job),
|
|
134
|
+
state_(std::move(state)),
|
|
135
|
+
image_(std::move(snapshot)),
|
|
136
|
+
text_(std::move(text)),
|
|
137
|
+
input_(std::move(input)) {}
|
|
130
138
|
|
|
131
139
|
void ExecuteWork() override {
|
|
132
140
|
// No V8, NAN object creation, or access to state_->current on this thread.
|
|
@@ -171,14 +179,14 @@ class ImageWorker final : public sfmljs::AsyncWorker {
|
|
|
171
179
|
} else if (job_ == ImageJob::SaveFile) {
|
|
172
180
|
result = Nan::New(ok_);
|
|
173
181
|
} else if (ok_) {
|
|
174
|
-
auto bytes =
|
|
175
|
-
std::move(*encoded_));
|
|
182
|
+
auto bytes =
|
|
183
|
+
std::make_shared<std::vector<std::uint8_t>>(std::move(*encoded_));
|
|
176
184
|
if (bytes->size() > node::Buffer::kMaxLength) {
|
|
177
185
|
SetErrorMessage("Encoded image exceeds the byte buffer limit");
|
|
178
186
|
return HandleErrorCallback();
|
|
179
187
|
}
|
|
180
|
-
auto buffer = sfmljs::MapShared(
|
|
181
|
-
|
|
188
|
+
auto buffer = sfmljs::MapShared(
|
|
189
|
+
v8::Isolate::GetCurrent(), bytes, bytes->data(), bytes->size());
|
|
182
190
|
result = v8::Uint8Array::New(buffer, 0, bytes->size());
|
|
183
191
|
}
|
|
184
192
|
} catch (const std::exception& error) {
|
|
@@ -222,8 +230,8 @@ NAN_METHOD(QueueImageJob) {
|
|
|
222
230
|
if constexpr (Job == ImageJob::LoadFile || Job == ImageJob::SaveFile) {
|
|
223
231
|
// Capture relative paths at invocation, before process.chdir can occur.
|
|
224
232
|
if (!text.empty()) {
|
|
225
|
-
const auto path =
|
|
226
|
-
Utf8Path(text)).u8string();
|
|
233
|
+
const auto path =
|
|
234
|
+
std::filesystem::absolute(Utf8Path(text)).u8string();
|
|
227
235
|
text.assign(reinterpret_cast<const char*>(path.data()), path.size());
|
|
228
236
|
}
|
|
229
237
|
}
|
|
@@ -234,8 +242,12 @@ NAN_METHOD(QueueImageJob) {
|
|
|
234
242
|
snapshot = std::make_shared<sf::Image>(*handle->owner()->current);
|
|
235
243
|
}
|
|
236
244
|
auto callback = std::make_unique<Nan::Callback>(info[2].As<v8::Function>());
|
|
237
|
-
auto worker = std::make_unique<ImageWorker>(callback.get(),
|
|
238
|
-
|
|
245
|
+
auto worker = std::make_unique<ImageWorker>(callback.get(),
|
|
246
|
+
Job,
|
|
247
|
+
handle->owner(),
|
|
248
|
+
std::move(snapshot),
|
|
249
|
+
std::move(text),
|
|
250
|
+
std::move(input));
|
|
239
251
|
callback.release();
|
|
240
252
|
Nan::AsyncQueueWorker(worker.release());
|
|
241
253
|
} catch (const std::exception& error) {
|
|
@@ -252,7 +264,9 @@ NAN_MODULE_INIT(InitializeImage) {
|
|
|
252
264
|
sfmljs::SetMethod<FlipImage>(target, "flipImage");
|
|
253
265
|
sfmljs::SetMethod<CopyImage>(target, "copyImage");
|
|
254
266
|
sfmljs::SetMethod<QueueImageJob<ImageJob::LoadFile>>(target, "loadImageFile");
|
|
255
|
-
sfmljs::SetMethod<QueueImageJob<ImageJob::LoadMemory>>(target,
|
|
267
|
+
sfmljs::SetMethod<QueueImageJob<ImageJob::LoadMemory>>(target,
|
|
268
|
+
"loadImageMemory");
|
|
256
269
|
sfmljs::SetMethod<QueueImageJob<ImageJob::SaveFile>>(target, "saveImageFile");
|
|
257
|
-
sfmljs::SetMethod<QueueImageJob<ImageJob::SaveMemory>>(target,
|
|
270
|
+
sfmljs::SetMethod<QueueImageJob<ImageJob::SaveMemory>>(target,
|
|
271
|
+
"saveImageMemory");
|
|
258
272
|
}
|
package/native/image-state.h
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "numeric-fields.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/Graphics/Image.hpp>
|
|
6
|
-
|
|
7
3
|
#include <cstdint>
|
|
8
4
|
#include <limits>
|
|
9
5
|
#include <memory>
|
|
10
|
-
#include <span>
|
|
6
|
+
#include <span> // NOLINT(build/include_order): cpplint lacks C++20 headers
|
|
7
|
+
|
|
8
|
+
#include "numeric-fields.h"
|
|
9
|
+
#include <SFML/Graphics/Image.hpp>
|
|
11
10
|
|
|
12
11
|
namespace sfmljs {
|
|
13
12
|
|
|
@@ -26,23 +25,24 @@ inline std::size_t ImageBytes(const sf::Image& image) {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
inline bool ReadImageSize(v8::Local<v8::Value> width,
|
|
29
|
-
v8::Local<v8::Value> height,
|
|
28
|
+
v8::Local<v8::Value> height,
|
|
29
|
+
sf::Vector2u& size) { // NOLINT(runtime/references)
|
|
30
30
|
if (!width->IsUint32() || !height->IsUint32()) {
|
|
31
31
|
Nan::ThrowRangeError("Expected unsigned integer image dimensions");
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
size = {Nan::To<std::uint32_t>(width).FromJust(),
|
|
35
35
|
Nan::To<std::uint32_t>(height).FromJust()};
|
|
36
|
-
if (size.x != 0 &&
|
|
37
|
-
size.y > node::Buffer::kMaxLength / 4 / size.x) {
|
|
36
|
+
if (size.x != 0 && size.y > node::Buffer::kMaxLength / 4 / size.x) {
|
|
38
37
|
Nan::ThrowRangeError("Image dimensions exceed the pixel buffer limit");
|
|
39
38
|
return false;
|
|
40
39
|
}
|
|
41
40
|
return true;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
inline bool ReadImageBytes(
|
|
45
|
-
|
|
43
|
+
inline bool ReadImageBytes(
|
|
44
|
+
v8::Local<v8::Value> value,
|
|
45
|
+
std::span<const std::uint8_t>& bytes) { // NOLINT(runtime/references)
|
|
46
46
|
if (!value->IsUint8Array()) {
|
|
47
47
|
Nan::ThrowTypeError("Expected bytes in a Uint8Array");
|
|
48
48
|
return false;
|
|
@@ -66,18 +66,24 @@ inline bool ReadImageBytes(v8::Local<v8::Value> value,
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
inline v8::Local<v8::Object> MapImage(v8::Isolate* isolate,
|
|
69
|
-
|
|
69
|
+
const std::shared_ptr<sf::Image>& image) {
|
|
70
70
|
const auto& size = Field<ImageSize>(*image);
|
|
71
71
|
const auto bytes = ImageBytes(*image);
|
|
72
72
|
auto result = Nan::New<v8::Object>();
|
|
73
73
|
// sf::Image is mutable; only its public pointer accessor is const-qualified.
|
|
74
74
|
// A view owns this specific allocation, never the replaceable ImageState.
|
|
75
|
-
auto buffer =
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
auto buffer =
|
|
76
|
+
bytes == 0 ? v8::ArrayBuffer::New(isolate, 0)
|
|
77
|
+
: MapShared(isolate,
|
|
78
|
+
image,
|
|
79
|
+
const_cast<std::uint8_t*>(image->getPixelsPtr()),
|
|
80
|
+
bytes);
|
|
78
81
|
Nan::Set(result, Nan::New("buffer").ToLocalChecked(), buffer).FromJust();
|
|
79
|
-
Nan::Set(
|
|
80
|
-
|
|
82
|
+
Nan::Set(
|
|
83
|
+
result,
|
|
84
|
+
Nan::New("info").ToLocalChecked(),
|
|
85
|
+
NumericFields().Add("width", size.x).Add("height", size.y).Map(image))
|
|
86
|
+
.FromJust();
|
|
81
87
|
return result;
|
|
82
88
|
}
|
|
83
89
|
|
|
@@ -85,8 +91,10 @@ inline v8::Local<v8::Object> MapImageResource(
|
|
|
85
91
|
v8::Isolate* isolate, std::shared_ptr<sf::Image> image) {
|
|
86
92
|
auto result = MapImage(isolate, image);
|
|
87
93
|
auto state = std::make_shared<ImageState>(ImageState{std::move(image)});
|
|
88
|
-
Nan::Set(result,
|
|
89
|
-
|
|
94
|
+
Nan::Set(result,
|
|
95
|
+
Nan::New("handle").ToLocalChecked(),
|
|
96
|
+
ImageHandle::Create(std::move(state)))
|
|
97
|
+
.FromJust();
|
|
90
98
|
return result;
|
|
91
99
|
}
|
|
92
100
|
|
package/native/input-binding.cc
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#include "shared-handle.h"
|
|
2
1
|
#include "exception-boundary.h"
|
|
2
|
+
#include "shared-handle.h"
|
|
3
3
|
#include "window-event.h"
|
|
4
|
-
|
|
5
4
|
#include <SFML/System/String.hpp>
|
|
6
5
|
#include <SFML/Window/Clipboard.hpp>
|
|
7
6
|
#include <SFML/Window/Joystick.hpp>
|
|
@@ -13,7 +12,9 @@
|
|
|
13
12
|
|
|
14
13
|
namespace {
|
|
15
14
|
|
|
16
|
-
bool ReadIndex(v8::Local<v8::Value> value,
|
|
15
|
+
bool ReadIndex(v8::Local<v8::Value> value,
|
|
16
|
+
int count,
|
|
17
|
+
int& result, // NOLINT(runtime/references)
|
|
17
18
|
int minimum = 0) {
|
|
18
19
|
if (!value->IsInt32()) {
|
|
19
20
|
Nan::ThrowRangeError("Expected an integer input index");
|
|
@@ -36,7 +37,8 @@ bool ReadBoolean(v8::Local<v8::Value> value) {
|
|
|
36
37
|
v8::Local<v8::String> StringValue(const sf::String& value) {
|
|
37
38
|
const auto utf8 = value.toUtf8();
|
|
38
39
|
return Nan::New(reinterpret_cast<const char*>(utf8.data()),
|
|
39
|
-
static_cast<int>(utf8.size()))
|
|
40
|
+
static_cast<int>(utf8.size()))
|
|
41
|
+
.ToLocalChecked();
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
NAN_METHOD(GetClipboardString) {
|
|
@@ -44,7 +46,8 @@ NAN_METHOD(GetClipboardString) {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
NAN_METHOD(SetClipboardString) {
|
|
47
|
-
if (!info[0]->IsString())
|
|
49
|
+
if (!info[0]->IsString())
|
|
50
|
+
return Nan::ThrowTypeError("Expected clipboard text");
|
|
48
51
|
Nan::Utf8String text(info[0]);
|
|
49
52
|
sf::Clipboard::setString(sf::String::fromUtf8(*text, *text + text.length()));
|
|
50
53
|
}
|
|
@@ -76,11 +79,17 @@ NAN_METHOD(IsKeyPressed) {
|
|
|
76
79
|
if (!ReadBoolean(info[1])) return;
|
|
77
80
|
const bool scancode = info[1]->IsTrue();
|
|
78
81
|
int code;
|
|
79
|
-
if (!ReadIndex(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if (!ReadIndex(
|
|
83
|
+
info[0],
|
|
84
|
+
scancode ? sf::Keyboard::ScancodeCount : sf::Keyboard::KeyCount,
|
|
85
|
+
code,
|
|
86
|
+
-1))
|
|
87
|
+
return;
|
|
88
|
+
info.GetReturnValue().Set(
|
|
89
|
+
scancode
|
|
90
|
+
? sf::Keyboard::isKeyPressed(
|
|
91
|
+
static_cast<sf::Keyboard::Scancode>(code))
|
|
92
|
+
: sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code)));
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
NAN_METHOD(LocalizeKey) {
|
|
@@ -158,7 +167,8 @@ NAN_METHOD(GetJoystickButtonCount) {
|
|
|
158
167
|
NAN_METHOD(JoystickHasAxis) {
|
|
159
168
|
int joystick, axis;
|
|
160
169
|
if (!ReadIndex(info[0], sf::Joystick::Count, joystick) ||
|
|
161
|
-
!ReadIndex(info[1], sf::Joystick::AxisCount, axis))
|
|
170
|
+
!ReadIndex(info[1], sf::Joystick::AxisCount, axis))
|
|
171
|
+
return;
|
|
162
172
|
info.GetReturnValue().Set(
|
|
163
173
|
sf::Joystick::hasAxis(joystick, static_cast<sf::Joystick::Axis>(axis)));
|
|
164
174
|
}
|
|
@@ -166,17 +176,18 @@ NAN_METHOD(JoystickHasAxis) {
|
|
|
166
176
|
NAN_METHOD(IsJoystickButtonPressed) {
|
|
167
177
|
int joystick, button;
|
|
168
178
|
if (!ReadIndex(info[0], sf::Joystick::Count, joystick) ||
|
|
169
|
-
!ReadIndex(info[1], sf::Joystick::ButtonCount, button))
|
|
179
|
+
!ReadIndex(info[1], sf::Joystick::ButtonCount, button))
|
|
180
|
+
return;
|
|
170
181
|
info.GetReturnValue().Set(sf::Joystick::isButtonPressed(joystick, button));
|
|
171
182
|
}
|
|
172
183
|
|
|
173
184
|
NAN_METHOD(GetJoystickAxisPosition) {
|
|
174
185
|
int joystick, axis;
|
|
175
186
|
if (!ReadIndex(info[0], sf::Joystick::Count, joystick) ||
|
|
176
|
-
!ReadIndex(info[1], sf::Joystick::AxisCount, axis))
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
187
|
+
!ReadIndex(info[1], sf::Joystick::AxisCount, axis))
|
|
188
|
+
return;
|
|
189
|
+
info.GetReturnValue().Set(sf::Joystick::getAxisPosition(
|
|
190
|
+
joystick, static_cast<sf::Joystick::Axis>(axis)));
|
|
180
191
|
}
|
|
181
192
|
|
|
182
193
|
NAN_METHOD(GetJoystickIdentification) {
|
|
@@ -184,12 +195,13 @@ NAN_METHOD(GetJoystickIdentification) {
|
|
|
184
195
|
if (!ReadIndex(info[0], sf::Joystick::Count, joystick)) return;
|
|
185
196
|
const auto id = sf::Joystick::getIdentification(joystick);
|
|
186
197
|
auto result = Nan::New<v8::Object>();
|
|
187
|
-
Nan::Set(result, Nan::New("name").ToLocalChecked(),
|
|
188
|
-
|
|
189
|
-
Nan::Set(result, Nan::New("vendorId").ToLocalChecked(),
|
|
190
|
-
|
|
191
|
-
Nan::Set(
|
|
192
|
-
|
|
198
|
+
Nan::Set(result, Nan::New("name").ToLocalChecked(), StringValue(id.name))
|
|
199
|
+
.FromJust();
|
|
200
|
+
Nan::Set(result, Nan::New("vendorId").ToLocalChecked(), Nan::New(id.vendorId))
|
|
201
|
+
.FromJust();
|
|
202
|
+
Nan::Set(
|
|
203
|
+
result, Nan::New("productId").ToLocalChecked(), Nan::New(id.productId))
|
|
204
|
+
.FromJust();
|
|
193
205
|
info.GetReturnValue().Set(result);
|
|
194
206
|
}
|
|
195
207
|
|
|
@@ -206,9 +218,10 @@ NAN_METHOD(IsSensorAvailable) {
|
|
|
206
218
|
|
|
207
219
|
NAN_METHOD(SetSensorEnabled) {
|
|
208
220
|
int sensor;
|
|
209
|
-
if (!ReadIndex(info[0], sf::Sensor::Count, sensor) ||
|
|
210
|
-
|
|
211
|
-
sf::Sensor::setEnabled(static_cast<sf::Sensor::Type>(sensor),
|
|
221
|
+
if (!ReadIndex(info[0], sf::Sensor::Count, sensor) || !ReadBoolean(info[1]))
|
|
222
|
+
return;
|
|
223
|
+
sf::Sensor::setEnabled(static_cast<sf::Sensor::Type>(sensor),
|
|
224
|
+
info[1]->IsTrue());
|
|
212
225
|
}
|
|
213
226
|
|
|
214
227
|
NAN_METHOD(GetSensorValue) {
|
|
@@ -229,7 +242,8 @@ NAN_MODULE_INIT(InitializeInput) {
|
|
|
229
242
|
sfmljs::SetMethod<LocalizeKey>(target, "localizeKey");
|
|
230
243
|
sfmljs::SetMethod<DelocalizeKey>(target, "delocalizeKey");
|
|
231
244
|
sfmljs::SetMethod<GetKeyDescription>(target, "getKeyDescription");
|
|
232
|
-
sfmljs::SetMethod<SetVirtualKeyboardVisible>(target,
|
|
245
|
+
sfmljs::SetMethod<SetVirtualKeyboardVisible>(target,
|
|
246
|
+
"setVirtualKeyboardVisible");
|
|
233
247
|
sfmljs::SetMethod<IsMouseButtonPressed>(target, "isMouseButtonPressed");
|
|
234
248
|
sfmljs::SetMethod<GetMousePosition>(target, "getMousePosition");
|
|
235
249
|
sfmljs::SetMethod<SetMousePosition>(target, "setMousePosition");
|
|
@@ -238,7 +252,8 @@ NAN_MODULE_INIT(InitializeInput) {
|
|
|
238
252
|
sfmljs::SetMethod<JoystickHasAxis>(target, "joystickHasAxis");
|
|
239
253
|
sfmljs::SetMethod<IsJoystickButtonPressed>(target, "isJoystickButtonPressed");
|
|
240
254
|
sfmljs::SetMethod<GetJoystickAxisPosition>(target, "getJoystickAxisPosition");
|
|
241
|
-
sfmljs::SetMethod<GetJoystickIdentification>(target,
|
|
255
|
+
sfmljs::SetMethod<GetJoystickIdentification>(target,
|
|
256
|
+
"getJoystickIdentification");
|
|
242
257
|
sfmljs::SetMethod<UpdateJoysticks>(target, "updateJoysticks");
|
|
243
258
|
sfmljs::SetMethod<IsSensorAvailable>(target, "isSensorAvailable");
|
|
244
259
|
sfmljs::SetMethod<SetSensorEnabled>(target, "setSensorEnabled");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#include "render-window-state.h"
|
|
2
1
|
#include "exception-boundary.h"
|
|
2
|
+
#include "render-window-state.h"
|
|
3
3
|
#include "shared-handle.h"
|
|
4
4
|
|
|
5
5
|
namespace {
|
|
@@ -13,14 +13,20 @@ NAN_METHOD(CreateRenderWindow) {
|
|
|
13
13
|
try {
|
|
14
14
|
auto target = sfmljs::MakeThreadOwned<Target>(context->owner());
|
|
15
15
|
auto result = Nan::New<v8::Object>();
|
|
16
|
-
Nan::Set(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
Nan::Set(
|
|
17
|
+
result, Nan::New("handle").ToLocalChecked(), Handle::Create(target))
|
|
18
|
+
.FromJust();
|
|
19
|
+
Nan::Set(result,
|
|
20
|
+
Nan::New("window").ToLocalChecked(),
|
|
21
|
+
sfmljs::MakeWindowHandle(target))
|
|
22
|
+
.FromJust();
|
|
20
23
|
const auto commands = target->batch.Commands();
|
|
21
|
-
Nan::Set(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
Nan::Set(
|
|
25
|
+
result,
|
|
26
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
27
|
+
sfmljs::MapShared(
|
|
28
|
+
info.GetIsolate(), target, commands.data(), commands.size_bytes()))
|
|
29
|
+
.FromJust();
|
|
24
30
|
info.GetReturnValue().Set(result);
|
|
25
31
|
} catch (const std::exception& error) {
|
|
26
32
|
sfmljs::ThrowError(error.what());
|
|
@@ -30,12 +36,12 @@ NAN_METHOD(CreateRenderWindow) {
|
|
|
30
36
|
NAN_METHOD(SubmitRenderWindow) {
|
|
31
37
|
auto* target = Handle::From(info[0]);
|
|
32
38
|
if (!target) return;
|
|
33
|
-
if (!info[1]->IsUint32() ||
|
|
34
|
-
|
|
35
|
-
target->owner()->batch.Commands().size()) {
|
|
39
|
+
if (!info[1]->IsUint32() || Nan::To<std::uint32_t>(info[1]).FromJust() >
|
|
40
|
+
target->owner()->batch.Commands().size()) {
|
|
36
41
|
return Nan::ThrowRangeError("Invalid draw command count");
|
|
37
42
|
}
|
|
38
|
-
if (!info[2]->IsBoolean())
|
|
43
|
+
if (!info[2]->IsBoolean())
|
|
44
|
+
return Nan::ThrowTypeError("Expected display flag");
|
|
39
45
|
try {
|
|
40
46
|
if (!target->owner()->Submit(Nan::To<std::uint32_t>(info[1]).FromJust(),
|
|
41
47
|
info[2]->IsTrue())) {
|
|
@@ -56,10 +62,13 @@ NAN_METHOD(AllocateRenderWindowVertices) {
|
|
|
56
62
|
try {
|
|
57
63
|
const auto storage = target->owner()->batch.AllocateVertices(
|
|
58
64
|
Nan::To<std::uint32_t>(info[1]).FromJust());
|
|
59
|
-
info.GetReturnValue().Set(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
info.GetReturnValue().Set(
|
|
66
|
+
storage->empty()
|
|
67
|
+
? v8::ArrayBuffer::New(info.GetIsolate(), 0)
|
|
68
|
+
: sfmljs::MapShared(info.GetIsolate(),
|
|
69
|
+
storage,
|
|
70
|
+
storage->data(),
|
|
71
|
+
storage->size() * sizeof(sf::Vertex)));
|
|
63
72
|
} catch (const std::exception& error) {
|
|
64
73
|
sfmljs::ThrowError(error.what());
|
|
65
74
|
}
|
|
@@ -74,8 +83,9 @@ NAN_METHOD(SetRenderWindowActive) {
|
|
|
74
83
|
|
|
75
84
|
NAN_METHOD(IsRenderWindowSrgb) {
|
|
76
85
|
auto* target = Handle::From(info[0]);
|
|
77
|
-
if (target)
|
|
78
|
-
|
|
86
|
+
if (target)
|
|
87
|
+
info.GetReturnValue().Set(target->owner()->isOpen() &&
|
|
88
|
+
target->owner()->isSrgb());
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
NAN_METHOD(ChangeRenderWindowGLStates) {
|
|
@@ -86,9 +96,12 @@ NAN_METHOD(ChangeRenderWindowGLStates) {
|
|
|
86
96
|
}
|
|
87
97
|
if (!target->owner()->isOpen()) return;
|
|
88
98
|
const auto operation = Nan::To<std::uint32_t>(info[1]).FromJust();
|
|
89
|
-
if (operation == 0)
|
|
90
|
-
|
|
91
|
-
else
|
|
99
|
+
if (operation == 0)
|
|
100
|
+
target->owner()->pushGLStates();
|
|
101
|
+
else if (operation == 1)
|
|
102
|
+
target->owner()->popGLStates();
|
|
103
|
+
else
|
|
104
|
+
target->owner()->resetGLStates();
|
|
92
105
|
}
|
|
93
106
|
|
|
94
107
|
} // namespace
|
|
@@ -96,8 +109,10 @@ NAN_METHOD(ChangeRenderWindowGLStates) {
|
|
|
96
109
|
NAN_MODULE_INIT(InitializeRenderWindow) {
|
|
97
110
|
sfmljs::SetMethod<CreateRenderWindow>(target, "createRenderWindow");
|
|
98
111
|
sfmljs::SetMethod<SubmitRenderWindow>(target, "submitRenderWindow");
|
|
99
|
-
sfmljs::SetMethod<AllocateRenderWindowVertices>(
|
|
112
|
+
sfmljs::SetMethod<AllocateRenderWindowVertices>(
|
|
113
|
+
target, "allocateRenderWindowVertices");
|
|
100
114
|
sfmljs::SetMethod<SetRenderWindowActive>(target, "setRenderWindowActive");
|
|
101
115
|
sfmljs::SetMethod<IsRenderWindowSrgb>(target, "isRenderWindowSrgb");
|
|
102
|
-
sfmljs::SetMethod<ChangeRenderWindowGLStates>(target,
|
|
116
|
+
sfmljs::SetMethod<ChangeRenderWindowGLStates>(target,
|
|
117
|
+
"changeRenderWindowGLStates");
|
|
103
118
|
}
|