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,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
- sf::Context::isExtensionAvailable("GL_ARB_framebuffer_object");
23
+ sf::Context::isExtensionAvailable("GL_ARB_framebuffer_object");
24
24
  if (!separate_ &&
25
- !sf::Context::isExtensionAvailable("GL_EXT_framebuffer_object")) return;
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, v8::Local<v8::Value> y,
53
- sf::Vector2u& position) {
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, sf::Vector2u size,
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.x > target.x - dest.x || size.y > target.y - dest.y) {
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
- ? sfmljs::MakeThreadOwned<sfmljs::TextureState>(
99
- context->owner(), id, *source)
100
- : sfmljs::MakeThreadOwned<sfmljs::TextureState>(context->owner(), id);
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(result, Nan::New("info").ToLocalChecked(),
111
- sfmljs::MapTexture(texture)).FromJust();
112
- Nan::Set(result, Nan::New("handle").ToLocalChecked(),
113
- TextureHandle::Create(texture)).FromJust();
114
- Nan::Set(result, Nan::New("id").ToLocalChecked(),
115
- Nan::New(texture->id)).FromJust();
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(info.GetIsolate(),
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(), static_cast<sf::CoordinateType>(
175
- Nan::To<std::uint32_t>(info[1]).FromJust()));
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
- (!sfmljs::ReadImageSize(info[2], info[3], size) ||
249
- !ReadPosition(info[4], info[5], dest))) return;
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) texture->owner()->setSmooth(info[1]->IsTrue());
308
- else texture->owner()->setRepeated(info[1]->IsTrue());
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).Add("height", size.y)
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)).Map(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(v8::Local<v8::Value> value) {
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)).FromJust();
42
- Nan::Set(result, Nan::New("height").ToLocalChecked(), Nan::New(size.y)).FromJust();
43
- Nan::Set(result, Nan::New("smooth").ToLocalChecked(),
44
- Nan::New(texture.isSmooth())).FromJust();
45
- Nan::Set(result, Nan::New("repeated").ToLocalChecked(),
46
- Nan::New(texture.isRepeated())).FromJust();
47
- Nan::Set(result, Nan::New("sRgb").ToLocalChecked(),
48
- Nan::New(texture.isSrgb())).FromJust();
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
 
@@ -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, sf::Time& result) {
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, Nan::New("handle").ToLocalChecked(),
12
- sfmljs::TransformableHandle(state)).FromJust();
13
- Nan::Set(result, Nan::New("buffer").ToLocalChecked(),
14
- sfmljs::MapShared(info.GetIsolate(), state, state->values.data(),
15
- sizeof(state->values))).FromJust();
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(sf::Transformable& object,
17
- const TransformableData& values) {
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]});
@@ -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, const std::shared_ptr<T>& owner,
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, Nan::New("handle").ToLocalChecked(),
27
- SharedHandle<T>::Create(owner)).FromJust();
28
- Nan::Set(result, Nan::New("buffer").ToLocalChecked(),
29
- backing ? v8::ArrayBuffer::New(info.GetIsolate(), std::move(backing))
30
- : MapShared(info.GetIsolate(), owner, owner.get(), sizeof(T)))
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
- std::is_same_v<T, float> || std::is_same_v<T, double> ||
86
- std::is_integral_v<T>,
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
- ((name == ScalarName<typename Layout<Types>::Scalar>()
114
- ? (callback.template operator()<Types>(), true) : false) || ...);
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], [&]<typename T>() { WrapBackingStore<T>(info, info[1]); });
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>, Vector<unsigned>, Vector<float>,
162
- Vector<bool>, Vector<double>, Vector<std::int8_t>, Vector<std::uint8_t>,
163
- Vector<std::int16_t>, Vector<std::uint16_t>,
164
- Vector<std::int64_t>, Vector<std::uint64_t>>;
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, Member Parent::*field) {
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([&](auto... fields) {
193
- std::size_t current = 0;
194
- return ((index == current++
195
- ? (ReturnMember(info, owner, fields), true) : false) || ...);
196
- }, members);
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
 
@@ -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) == 4 || sizeof(T) == 8);
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) == 4 || sizeof(T) == 8);
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 = std::tuple{
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 &&
@@ -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
- using namespace sfmljs::values;
6
-
7
- sfmljs::SetMethod<AngleValues::Create>(target, "createAngle");
8
- sfmljs::SetMethod<AngleValues::Wrap>(target, "wrapAngle");
9
- sfmljs::SetMethod<TransformValues::Create>(target, "createTransform");
10
- sfmljs::SetMethod<TransformValues::Wrap>(target, "wrapTransform");
11
- sfmljs::SetMethod<Mat3Values::Wrap>(target, "wrapMat3");
12
- sfmljs::SetMethod<Mat4Values::Wrap>(target, "wrapMat4");
13
- sfmljs::SetMethod<Vector2Values::Create>(target, "createVector2");
14
- sfmljs::SetMethod<Vector2Values::Wrap>(target, "wrapVector2");
15
- sfmljs::SetMethod<Vector3Values::Create>(target, "createVector3");
16
- sfmljs::SetMethod<Vector3Values::Wrap>(target, "wrapVector3");
17
- sfmljs::SetMethod<Vector4Values::Create>(target, "createVector4");
18
- sfmljs::SetMethod<Vector4Values::Wrap>(target, "wrapVector4");
19
- sfmljs::SetMethod<ColorValues::Create>(target, "createColor");
20
- sfmljs::SetMethod<ColorValues::Wrap>(target, "wrapColor");
21
- sfmljs::SetMethod<RectValues::Create>(target, "createRect");
22
- sfmljs::SetMethod<RectValues::Wrap>(target, "wrapRect");
23
- sfmljs::SetMethod<Member<RectValues>>(target, "rectMember");
24
- sfmljs::SetMethod<VertexValues::Create>(target, "createVertex");
25
- sfmljs::SetMethod<VertexValues::Wrap>(target, "wrapVertex");
26
- sfmljs::SetMethod<Member<VertexValues>>(target, "vertexMember");
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
  }
@@ -1,8 +1,8 @@
1
- #include "vertex-storage.h"
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 = std::make_shared<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() ? v8::ArrayBuffer::New(info.GetIsolate(), 0)
22
- : sfmljs::MapShared(info.GetIsolate(), storage, storage->data(),
23
- storage->size() * sizeof(sf::Vertex));
24
- Nan::Set(result, Nan::New("handle").ToLocalChecked(),
25
- Handle::Create(storage)).FromJust();
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(info, std::shared_ptr<sf::Vertex>(
42
- storage->owner(), &(*storage->owner())[index]));
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