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