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,8 +1,12 @@
1
1
  import { Vector2, Vector2i, Vector2u } from '../system/vector2';
2
2
  import { Vector3, Vector3f } from '../system/vector3';
3
3
  import type {
4
- KeyboardKey, KeyboardScancode, MouseButton, MouseWheel,
5
- JoystickAxis, SensorType,
4
+ KeyboardKey,
5
+ KeyboardScancode,
6
+ MouseButton,
7
+ MouseWheel,
8
+ JoystickAxis,
9
+ SensorType,
6
10
  } from './gen/constants';
7
11
 
8
12
  interface KeyEvent {
@@ -502,10 +506,12 @@ export class Event<K extends EventKind = EventKind> {
502
506
  for (const key of Object.keys(copy)) {
503
507
  const value = (copy as Record<string, unknown>)[key];
504
508
  if (value instanceof Vector2 || value instanceof Vector3) {
505
- (copy as Record<string, unknown>)[key] = value instanceof Vector3
506
- ? new Vector3f(value as Vector3f)
507
- : value.scalarType === 'u32' ? new Vector2u(value as Vector2u)
508
- : new Vector2i(value as Vector2i);
509
+ (copy as Record<string, unknown>)[key] =
510
+ value instanceof Vector3
511
+ ? new Vector3f(value as Vector3f)
512
+ : value.scalarType === 'u32'
513
+ ? new Vector2u(value as Vector2u)
514
+ : new Vector2i(value as Vector2i);
509
515
  }
510
516
  }
511
517
  this.data = copy;
@@ -538,7 +544,7 @@ export class Event<K extends EventKind = EventKind> {
538
544
  * @ko 종류가 일치하면 데이터를, 그렇지 않으면 undefined를 반환한다.
539
545
  */
540
546
  getIf<P extends EventKind>(kind: P): EventData<P> | undefined {
541
- return this.is(kind) ? this.data as EventData<P> : undefined;
547
+ return this.is(kind) ? (this.data as EventData<P>) : undefined;
542
548
  }
543
549
 
544
550
  /**
@@ -554,8 +560,10 @@ export class Event<K extends EventKind = EventKind> {
554
560
 
555
561
  type NativeFields<T> = {
556
562
  [K in keyof T]: T[K] extends Vector2<'i32' | 'u32'>
557
- ? [number, number] : T[K] extends Vector3f
558
- ? [number, number, number] : T[K];
563
+ ? [number, number]
564
+ : T[K] extends Vector3f
565
+ ? [number, number, number]
566
+ : T[K];
559
567
  };
560
568
  export type NativeWindowEvent = {
561
569
  [K in EventKind]: NativeFields<EventData<K>>;
@@ -564,10 +572,16 @@ export type NativeWindowEvent = {
564
572
  export function windowEvent(raw: NativeWindowEvent): Event {
565
573
  const data = { ...raw } as unknown as EventData;
566
574
  if (data.kind === 'Resized') {
567
- data.size = new Vector2u(...(raw as NativeFields<EventData<'Resized'>>).size);
575
+ data.size = new Vector2u(
576
+ ...(raw as NativeFields<EventData<'Resized'>>).size,
577
+ );
568
578
  }
569
- if ('position' in data && 'position' in raw && Array.isArray(raw.position)) {
570
- data.position = new Vector2i(...raw.position as [number, number]);
579
+ if (
580
+ 'position' in data &&
581
+ 'position' in raw &&
582
+ Array.isArray(raw.position)
583
+ ) {
584
+ data.position = new Vector2i(...(raw.position as [number, number]));
571
585
  }
572
586
  if (data.kind === 'MouseMovedRaw' && raw.kind === 'MouseMovedRaw') {
573
587
  data.delta = new Vector2i(...raw.delta);
@@ -11,8 +11,12 @@ export {
11
11
  function windowHandle(
12
12
  window?: Window,
13
13
  ): NativeGraphicsHandle<'window'> | undefined {
14
- if (window === undefined) return undefined;
15
- if (!(window instanceof Window)) throw new TypeError('Expected a Window');
14
+ if (window === undefined) {
15
+ return undefined;
16
+ }
17
+ if (!(window instanceof Window)) {
18
+ throw new TypeError('Expected a Window');
19
+ }
16
20
  return window[graphicsNative];
17
21
  }
18
22
 
@@ -60,7 +60,9 @@ export class VideoMode {
60
60
  ) {
61
61
  const size = source instanceof VideoMode ? source.size
62
62
  : source as Readonly<Vector2u> | undefined;
63
- if (size !== undefined) windowSize(size, false);
63
+ if (size !== undefined) {
64
+ windowSize(size, false);
65
+ }
64
66
  this.sizeValue = size === undefined ? new Vector2u() : new Vector2u(size);
65
67
  numericProperties(this, { bitsPerPixel: 0 });
66
68
  this.bitsPerPixel = source instanceof VideoMode
@@ -4,13 +4,18 @@ import { Vector2, Vector2i, Vector2u } from '../system/vector2';
4
4
  import { Time } from '../system/time';
5
5
  import type { ReadonlyValue } from '../internal/value-storage';
6
6
  import {
7
- contextSettings, settingsFromBuffer, type ContextSettings,
7
+ contextSettings,
8
+ settingsFromBuffer,
9
+ type ContextSettings,
8
10
  } from './context-settings';
9
11
  import { Style, State } from './gen/constants';
10
12
  import { VideoMode, windowSize, unsigned } from './video-mode';
11
13
  import { Cursor, rgbaPixels } from './cursor';
12
14
  import {
13
- Event, windowEvent, type EventHandlers, type EventVisitor,
15
+ Event,
16
+ windowEvent,
17
+ type EventHandlers,
18
+ type EventVisitor,
14
19
  } from './event';
15
20
 
16
21
  /**
@@ -62,7 +67,10 @@ const mixedWindows = new WeakSet<object>();
62
67
  * @ko 윈도우 훅은 약한 키로만 유지하여 Native가 역참조로 JS 객체를 유지하지
63
68
  * 않도록 한다.
64
69
  */
65
- const windowHooks = new WeakMap<Window, readonly [() => void, () => void]>();
70
+ const windowHooks = new WeakMap<
71
+ Window,
72
+ readonly [() => void, () => void]
73
+ >();
66
74
 
67
75
  /**
68
76
  * Register dynamic hooks after construction, allowing render windows to
@@ -74,7 +82,9 @@ const windowHooks = new WeakMap<Window, readonly [() => void, () => void]>();
74
82
  * 초기화할 수 있게 한다.
75
83
  */
76
84
  export function registerWindowHooks(
77
- window: Window, onCreate: () => void, onResize: () => void,
85
+ window: Window,
86
+ onCreate: () => void,
87
+ onResize: () => void,
78
88
  ): void {
79
89
  windowHooks.set(window, [ onCreate, onResize ]);
80
90
  }
@@ -90,8 +100,11 @@ export function registerWindowHooks(
90
100
  */
91
101
  function dispatchWindowHooks(window: Window): void {
92
102
  let notification: 'create' | 'resize' | undefined;
93
- while ((notification =
94
- native.takeWindowNotification(window[graphicsNative])) !== undefined) {
103
+ while (
104
+ (notification = native.takeWindowNotification(
105
+ window[graphicsNative],
106
+ )) !== undefined
107
+ ) {
95
108
  windowHooks.get(window)?.[notification === 'create' ? 0 : 1]();
96
109
  }
97
110
  }
@@ -110,9 +123,13 @@ export class Window {
110
123
  readonly [graphicsNative]: NativeGraphicsHandle<'window'>;
111
124
 
112
125
  static [Symbol.hasInstance](value: unknown): boolean {
113
- return Function.prototype[Symbol.hasInstance].call(this, value) ||
114
- (this === Window && typeof value === 'object' && value !== null &&
115
- mixedWindows.has(value));
126
+ return (
127
+ Function.prototype[Symbol.hasInstance].call(this, value) ||
128
+ (this === Window &&
129
+ typeof value === 'object' &&
130
+ value !== null &&
131
+ mixedWindows.has(value))
132
+ );
116
133
  }
117
134
 
118
135
  /**
@@ -129,7 +146,8 @@ export class Window {
129
146
  * @ko 픽셀 크기, 제목, 설정을 지정하여 윈도우를 연다.
130
147
  */
131
148
  constructor(
132
- mode: Readonly<VideoMode> | Readonly<Vector2u>, title: string,
149
+ mode: Readonly<VideoMode> | Readonly<Vector2u>,
150
+ title: string,
133
151
  options?: Readonly<WindowOptions>,
134
152
  );
135
153
  /**
@@ -150,7 +168,11 @@ export class Window {
150
168
  } else if (mode !== undefined) {
151
169
  Window.prototype.create.bind(this)(mode, title as string, options);
152
170
  }
153
- registerWindowHooks(this, () => this.onCreate(), () => this.onResize());
171
+ registerWindowHooks(
172
+ this,
173
+ () => this.onCreate(),
174
+ () => this.onResize(),
175
+ );
154
176
  }
155
177
 
156
178
  /**
@@ -182,7 +204,8 @@ export class Window {
182
204
  * @ko 윈도우를 열거나 다시 생성한다. mode는 픽셀 크기 또는 전체 비디오 모드이다.
183
205
  */
184
206
  create(
185
- mode: Readonly<VideoMode> | Readonly<Vector2u>, title: string,
207
+ mode: Readonly<VideoMode> | Readonly<Vector2u>,
208
+ title: string,
186
209
  options?: Readonly<WindowOptions>,
187
210
  ): void;
188
211
  /**
@@ -198,17 +221,23 @@ export class Window {
198
221
  options: Readonly<WindowOptions> = {},
199
222
  ): void {
200
223
  if (typeof mode === 'bigint') {
201
- native.openWindowHandle(this[graphicsNative], mode,
202
- contextSettings(title as ContextSettings ?? {}));
224
+ native.openWindowHandle(
225
+ this[graphicsNative],
226
+ mode,
227
+ contextSettings((title as ContextSettings) ?? {}),
228
+ );
203
229
  dispatchWindowHooks(this);
204
230
  return;
205
231
  }
206
- const size = mode instanceof VideoMode ? mode.size : mode as Vector2u;
232
+ const size = mode instanceof VideoMode ? mode.size : (mode as Vector2u);
207
233
  const bits = mode instanceof VideoMode ? mode.bitsPerPixel : 32;
208
234
  windowSize(size);
209
235
  unsigned(bits);
210
- const { style = Style.Default, state = State.Windowed, settings = {} } =
211
- options;
236
+ const {
237
+ style = Style.Default,
238
+ state = State.Windowed,
239
+ settings = {},
240
+ } = options;
212
241
  unsigned(style);
213
242
  // eslint-disable-next-line no-bitwise
214
243
  if ((style & ~Style.Default) !== 0) {
@@ -217,8 +246,16 @@ export class Window {
217
246
  if (state !== State.Windowed && state !== State.Fullscreen) {
218
247
  throw new RangeError('Unknown window state');
219
248
  }
220
- native.openWindow(this[graphicsNative], size.x, size.y, title as string,
221
- bits, style, state, contextSettings(settings));
249
+ native.openWindow(
250
+ this[graphicsNative],
251
+ size.x,
252
+ size.y,
253
+ title as string,
254
+ bits,
255
+ style,
256
+ state,
257
+ contextSettings(settings),
258
+ );
222
259
  dispatchWindowHooks(this);
223
260
  }
224
261
 
@@ -273,7 +310,12 @@ export class Window {
273
310
  if (!(position instanceof Vector2) || position.scalarType !== 'i32') {
274
311
  throw new TypeError('Expected a Vector2i');
275
312
  }
276
- native.windowCommand(this[graphicsNative], 'position', position.x, position.y);
313
+ native.windowCommand(
314
+ this[graphicsNative],
315
+ 'position',
316
+ position.x,
317
+ position.y,
318
+ );
277
319
  }
278
320
 
279
321
  /**
@@ -296,8 +338,15 @@ export class Window {
296
338
  * @ko 클라이언트 영역의 최소 픽셀 크기를 설정한다. undefined는 제한을 해제한다.
297
339
  */
298
340
  setMinimumSize(size: Readonly<Vector2u> | undefined): void {
299
- if (size !== undefined) windowSize(size);
300
- native.windowCommand(this[graphicsNative], 'minimumSize', size?.x, size?.y);
341
+ if (size !== undefined) {
342
+ windowSize(size);
343
+ }
344
+ native.windowCommand(
345
+ this[graphicsNative],
346
+ 'minimumSize',
347
+ size?.x,
348
+ size?.y,
349
+ );
301
350
  dispatchWindowHooks(this);
302
351
  }
303
352
 
@@ -309,8 +358,15 @@ export class Window {
309
358
  * @ko 클라이언트 영역의 최대 픽셀 크기를 설정한다. undefined는 제한을 해제한다.
310
359
  */
311
360
  setMaximumSize(size: Readonly<Vector2u> | undefined): void {
312
- if (size !== undefined) windowSize(size);
313
- native.windowCommand(this[graphicsNative], 'maximumSize', size?.x, size?.y);
361
+ if (size !== undefined) {
362
+ windowSize(size);
363
+ }
364
+ native.windowCommand(
365
+ this[graphicsNative],
366
+ 'maximumSize',
367
+ size?.x,
368
+ size?.y,
369
+ );
314
370
  dispatchWindowHooks(this);
315
371
  }
316
372
 
@@ -378,7 +434,9 @@ export class Window {
378
434
  * @ko 윈도우 안에서 사용할 커서를 설정한다.
379
435
  */
380
436
  setMouseCursor(cursor: Cursor): void {
381
- if (!(cursor instanceof Cursor)) throw new TypeError('Expected a Cursor');
437
+ if (!(cursor instanceof Cursor)) {
438
+ throw new TypeError('Expected a Cursor');
439
+ }
382
440
  native.setWindowCursor(this[graphicsNative], cursor[graphicsNative]);
383
441
  }
384
442
 
@@ -402,7 +460,11 @@ export class Window {
402
460
  if (!Number.isFinite(threshold) || threshold < 0 || threshold > 100) {
403
461
  throw new RangeError('Joystick threshold must be from 0 to 100');
404
462
  }
405
- native.windowCommand(this[graphicsNative], 'joystickThreshold', threshold);
463
+ native.windowCommand(
464
+ this[graphicsNative],
465
+ 'joystickThreshold',
466
+ threshold,
467
+ );
406
468
  }
407
469
 
408
470
  /**
@@ -444,9 +506,15 @@ export class Window {
444
506
  * @ja 作成した VkSurfaceKHR を返す。作成に失敗した場合は undefined。
445
507
  * @ko 생성한 VkSurfaceKHR를 반환한다. 생성 실패 시 undefined를 반환한다.
446
508
  */
447
- createVulkanSurface(instance: bigint, allocator = 0n): bigint | undefined {
509
+ createVulkanSurface(
510
+ instance: bigint,
511
+ allocator = 0n,
512
+ ): bigint | undefined {
448
513
  return native.createWindowVulkanSurface(
449
- this[graphicsNative], instance, allocator);
514
+ this[graphicsNative],
515
+ instance,
516
+ allocator,
517
+ );
450
518
  }
451
519
 
452
520
  /**
@@ -457,7 +525,9 @@ export class Window {
457
525
  * @ko 실제 생성된 OpenGL 컨텍스트 설정을 반환한다. 요청한 값과 다를 수 있다.
458
526
  */
459
527
  getSettings(): Readonly<Required<ContextSettings>> {
460
- return settingsFromBuffer(native.getWindowSettings(this[graphicsNative]));
528
+ return settingsFromBuffer(
529
+ native.getWindowSettings(this[graphicsNative]),
530
+ );
461
531
  }
462
532
 
463
533
  /**
@@ -504,9 +574,13 @@ export class Window {
504
574
  * @ko SFML처럼 호출 스레드를 블로킹한다. Time.Zero는 무기한 대기한다.
505
575
  */
506
576
  waitEvent(timeout: ReadonlyValue<Time> = Time.Zero): Event | undefined {
507
- if (!(timeout instanceof Time)) throw new TypeError('Expected a Time');
577
+ if (!(timeout instanceof Time)) {
578
+ throw new TypeError('Expected a Time');
579
+ }
508
580
  const raw = native.waitWindowEvent(
509
- this[graphicsNative], timeout.asMicroseconds());
581
+ this[graphicsNative],
582
+ timeout.asMicroseconds(),
583
+ );
510
584
  dispatchWindowHooks(this);
511
585
  return raw === undefined ? undefined : windowEvent(raw);
512
586
  }
@@ -527,12 +601,15 @@ export class Window {
527
601
  */
528
602
  handleEvents(visitor: EventVisitor): void;
529
603
  handleEvents(
530
- handlers: EventHandlers | EventVisitor, fallback?: EventVisitor,
604
+ handlers: EventHandlers | EventVisitor,
605
+ fallback?: EventVisitor,
531
606
  ): void {
532
607
  let event: Event | undefined;
533
608
  while ((event = this.pollEvent()) !== undefined) {
534
- const handler = typeof handlers === 'function' ? handlers
535
- : handlers[event.kind] as EventVisitor | undefined;
609
+ const handler =
610
+ typeof handlers === 'function'
611
+ ? handlers
612
+ : (handlers[event.kind] as EventVisitor | undefined);
536
613
  (handler ?? fallback)?.(event.data);
537
614
  }
538
615
  }
@@ -572,8 +649,13 @@ export class Window {
572
649
  */
573
650
  export function installWindowMethods(prototype: object): void {
574
651
  for (const key of Reflect.ownKeys(Window.prototype)) {
575
- if (key === 'constructor' || key in prototype) continue;
576
- Object.defineProperty(prototype, key,
577
- Object.getOwnPropertyDescriptor(Window.prototype, key)!);
652
+ if (key === 'constructor' || key in prototype) {
653
+ continue;
654
+ }
655
+ Object.defineProperty(
656
+ prototype,
657
+ key,
658
+ Object.getOwnPropertyDescriptor(Window.prototype, key)!,
659
+ );
578
660
  }
579
661
  }
@@ -1,9 +1,8 @@
1
- #include "../../native/audio-worker.h"
2
1
  #include "../../native/audio-recorder.h"
2
+ #include "../../native/audio-worker.h"
3
3
 
4
+ namespace sfmljs::audio {
4
5
  namespace {
5
- using namespace sfmljs;
6
- using namespace sfmljs::audio;
7
6
 
8
7
  NAN_METHOD(AudioSourceOracle) {
9
8
  auto* handle = SourceHandle::From(info[0]);
@@ -18,17 +17,30 @@ NAN_METHOD(AudioSourceOracle) {
18
17
  const auto direction = sound.getDirection();
19
18
  const auto velocity = sound.getVelocity();
20
19
  const std::array<float, 24> values{
21
- sound.getPitch(), sound.getPan(), sound.getVolume(),
22
- static_cast<float>(sound.isSpatializationEnabled()),
23
- position.x, position.y, position.z,
24
- direction.x, direction.y, direction.z,
25
- cone.innerAngle.asRadians(), cone.outerAngle.asRadians(), cone.outerGain,
26
- velocity.x, velocity.y, velocity.z,
27
- sound.getDopplerFactor(), sound.getDirectionalAttenuationFactor(),
28
- static_cast<float>(sound.isRelativeToListener()),
29
- sound.getMinDistance(), sound.getMaxDistance(), sound.getMinGain(),
30
- sound.getMaxGain(), sound.getAttenuation()
31
- };
20
+ sound.getPitch(),
21
+ sound.getPan(),
22
+ sound.getVolume(),
23
+ static_cast<float>(sound.isSpatializationEnabled()),
24
+ position.x,
25
+ position.y,
26
+ position.z,
27
+ direction.x,
28
+ direction.y,
29
+ direction.z,
30
+ cone.innerAngle.asRadians(),
31
+ cone.outerAngle.asRadians(),
32
+ cone.outerGain,
33
+ velocity.x,
34
+ velocity.y,
35
+ velocity.z,
36
+ sound.getDopplerFactor(),
37
+ sound.getDirectionalAttenuationFactor(),
38
+ static_cast<float>(sound.isRelativeToListener()),
39
+ sound.getMinDistance(),
40
+ sound.getMaxDistance(),
41
+ sound.getMinGain(),
42
+ sound.getMaxGain(),
43
+ sound.getAttenuation()};
32
44
  auto result = Nan::New<v8::Array>(values.size());
33
45
  for (unsigned i = 0; i < values.size(); ++i) {
34
46
  Nan::Set(result, i, Nan::New(values[i])).FromJust();
@@ -42,7 +54,8 @@ NAN_METHOD(AudioBufferAliases) {
42
54
  if (!handle || !ReadBytes(info[1], samples, true)) return;
43
55
  const auto& buffer = handle->owner()->current->buffer;
44
56
  info.GetReturnValue().Set(buffer.getSamples() == samples.data &&
45
- buffer.getSampleCount() * sizeof(std::int16_t) == samples.size);
57
+ buffer.getSampleCount() * sizeof(std::int16_t) ==
58
+ samples.size);
46
59
  }
47
60
 
48
61
  NAN_METHOD(AudioSoundBufferMatches) {
@@ -51,8 +64,8 @@ NAN_METHOD(AudioSoundBufferMatches) {
51
64
  if (!source || !buffer) return;
52
65
  const auto* sound = source->owner()->AsSound();
53
66
  if (!sound) return Nan::ThrowTypeError("Expected a Sound");
54
- info.GetReturnValue().Set(
55
- &sound->getBuffer() == &buffer->owner()->current->buffer);
67
+ info.GetReturnValue().Set(&sound->getBuffer() ==
68
+ &buffer->owner()->current->buffer);
56
69
  }
57
70
 
58
71
  NAN_METHOD(AudioAssignmentState) {
@@ -62,12 +75,17 @@ NAN_METHOD(AudioAssignmentState) {
62
75
  auto result = Nan::New<v8::Object>();
63
76
  const auto pointer = [&](const void* value) {
64
77
  return v8::BigInt::NewFromUnsigned(info.GetIsolate(),
65
- reinterpret_cast<std::uintptr_t>(value));
78
+ reinterpret_cast<std::uintptr_t>(value));
66
79
  };
67
80
  Set(result, "sound", pointer(source->sound.get()));
68
81
  Set(result, "effect", pointer(source->effect.get()));
69
- Set(result, "generation", v8::BigInt::NewFromUnsigned(info.GetIsolate(),
70
- source->effect ? source->effect->generation.load(std::memory_order_acquire) : 0));
82
+ Set(result,
83
+ "generation",
84
+ v8::BigInt::NewFromUnsigned(
85
+ info.GetIsolate(),
86
+ source->effect
87
+ ? source->effect->generation.load(std::memory_order_acquire)
88
+ : 0));
71
89
  info.GetReturnValue().Set(result);
72
90
  }
73
91
 
@@ -75,7 +93,8 @@ NAN_METHOD(CreateAudioQueueProbe) {
75
93
  unsigned kind, frames, channels, rate, slots;
76
94
  if (!Unsigned(info[0], kind) || !Unsigned(info[1], frames) ||
77
95
  !Unsigned(info[2], channels) || !Unsigned(info[3], rate) ||
78
- !Unsigned(info[4], slots)) return;
96
+ !Unsigned(info[4], slots))
97
+ return;
79
98
  auto state = CreateWorkerState(kind, frames, channels, rate, slots);
80
99
  state->running = true;
81
100
  auto result = Nan::New<v8::Object>();
@@ -90,15 +109,18 @@ NAN_METHOD(PrepareAudioRecorderProbe) {
90
109
  auto* handle = RecorderHandle::From(info[0]);
91
110
  unsigned rate, frames, slots;
92
111
  if (!handle || !Unsigned(info[1], rate) || !Unsigned(info[2], frames) ||
93
- !Unsigned(info[3], slots)) return;
112
+ !Unsigned(info[3], slots))
113
+ return;
94
114
  auto recorder = handle->owner();
95
115
  if (recorder->active) return Nan::ThrowError("Recorder is already running");
96
116
  if (!rate) return Nan::ThrowRangeError("Sample rate must be positive");
97
117
  recorder->callbackRecorder = recorder->bufferRecorder && info[4]->IsTrue();
98
118
  recorder->values[0] = rate;
99
119
  recorder->current.reset();
100
- recorder->worker = recorder->bufferRecorder && !recorder->callbackRecorder
101
- ? nullptr : CreateWorkerState(1, frames, recorder->values[1], rate, slots);
120
+ recorder->worker =
121
+ recorder->bufferRecorder && !recorder->callbackRecorder
122
+ ? nullptr
123
+ : CreateWorkerState(1, frames, recorder->values[1], rate, slots);
102
124
  auto result = Nan::New<v8::Object>();
103
125
  if (recorder->worker) {
104
126
  recorder->worker->running.store(true, std::memory_order_release);
@@ -126,12 +148,17 @@ NAN_METHOD(AudioQueueProbe) {
126
148
  sf::SoundStream::Chunk chunk;
127
149
  const bool more = state->Stream(chunk);
128
150
  auto samples = std::make_shared<std::vector<std::int16_t>>();
129
- if (chunk.sampleCount) samples->assign(chunk.samples, chunk.samples + chunk.sampleCount);
151
+ if (chunk.sampleCount)
152
+ samples->assign(chunk.samples, chunk.samples + chunk.sampleCount);
130
153
  auto result = Nan::New<v8::Object>();
131
154
  Set(result, "more", Nan::New(more));
132
- Set(result, "samples", samples->empty()
133
- ? v8::ArrayBuffer::New(info.GetIsolate(), 0)
134
- : MapShared(info.GetIsolate(), samples, samples->data(), samples->size() * 2));
155
+ Set(result,
156
+ "samples",
157
+ samples->empty() ? v8::ArrayBuffer::New(info.GetIsolate(), 0)
158
+ : MapShared(info.GetIsolate(),
159
+ samples,
160
+ samples->data(),
161
+ samples->size() * 2));
135
162
  info.GetReturnValue().Set(result);
136
163
  } else if (command == 1) {
137
164
  Bytes samples;
@@ -146,11 +173,14 @@ NAN_METHOD(AudioQueueProbe) {
146
173
  float* input = nullptr;
147
174
  unsigned inFrames{};
148
175
  if (!info[2]->IsNull()) {
149
- if (!info[2]->IsFloat32Array()) return Nan::ThrowTypeError("Expected float samples");
176
+ if (!info[2]->IsFloat32Array())
177
+ return Nan::ThrowTypeError("Expected float samples");
150
178
  auto view = info[2].As<v8::Float32Array>();
151
- if (view->Buffer()->WasDetached()) return Nan::ThrowTypeError("Detached samples");
179
+ if (view->Buffer()->WasDetached())
180
+ return Nan::ThrowTypeError("Detached samples");
152
181
  input = reinterpret_cast<float*>(
153
- static_cast<std::byte*>(view->Buffer()->GetBackingStore()->Data()) + view->ByteOffset());
182
+ static_cast<std::byte*>(view->Buffer()->GetBackingStore()->Data()) +
183
+ view->ByteOffset());
154
184
  inFrames = static_cast<unsigned>(view->Length() / channels);
155
185
  }
156
186
  auto output = std::make_shared<std::vector<float>>(outFrames * channels);
@@ -158,16 +188,22 @@ NAN_METHOD(AudioQueueProbe) {
158
188
  auto result = Nan::New<v8::Object>();
159
189
  Set(result, "inputFrames", Nan::New(inFrames));
160
190
  Set(result, "outputFrames", Nan::New(outFrames));
161
- Set(result, "samples", MapShared(info.GetIsolate(), output, output->data(), output->size() * 4));
191
+ Set(result,
192
+ "samples",
193
+ MapShared(
194
+ info.GetIsolate(), output, output->data(), output->size() * 4));
162
195
  info.GetReturnValue().Set(result);
163
196
  } else if (command == 3) {
164
- if (!info[2]->IsBigInt()) return Nan::ThrowTypeError("Expected seek microseconds");
197
+ if (!info[2]->IsBigInt())
198
+ return Nan::ThrowTypeError("Expected seek microseconds");
165
199
  state->Seek(info[2].As<v8::BigInt>()->Int64Value());
166
200
  } else if (command == 4) {
167
201
  state->running.store(false, std::memory_order_release);
168
- } else return Nan::ThrowRangeError("Unknown audio probe command");
169
- }
202
+ } else {
203
+ return Nan::ThrowRangeError("Unknown audio probe command");
204
+ }
170
205
  }
206
+ } // namespace
171
207
 
172
208
  NAN_MODULE_INIT(InitializeAudioProbes) {
173
209
  sfmljs::SetMethod<AudioSourceOracle>(target, "audioSourceOracle");
@@ -175,7 +211,9 @@ NAN_MODULE_INIT(InitializeAudioProbes) {
175
211
  sfmljs::SetMethod<AudioSoundBufferMatches>(target, "audioSoundBufferMatches");
176
212
  sfmljs::SetMethod<AudioAssignmentState>(target, "audioAssignmentState");
177
213
  sfmljs::SetMethod<CreateAudioQueueProbe>(target, "createAudioQueueProbe");
178
- sfmljs::SetMethod<PrepareAudioRecorderProbe>(target, "prepareAudioRecorderProbe");
214
+ sfmljs::SetMethod<PrepareAudioRecorderProbe>(target,
215
+ "prepareAudioRecorderProbe");
179
216
  sfmljs::SetMethod<StartAudioRecorderProbe>(target, "startAudioRecorderProbe");
180
217
  sfmljs::SetMethod<AudioQueueProbe>(target, "audioQueueProbe");
181
218
  }
219
+ } // namespace sfmljs::audio
@@ -1,8 +1,8 @@
1
- #include "../../native/deferred-delete.h"
2
- #include "../../native/shared-handle.h"
3
-
4
1
  #include <atomic>
5
- #include <thread>
2
+ #include <thread> // NOLINT(build/c++11)
3
+
4
+ #include "../../native/deferred-delete.h"
5
+ #include "shared-handle.h"
6
6
 
7
7
  namespace {
8
8
  struct Observation {
@@ -27,11 +27,15 @@ NAN_METHOD(CreateDeletionProbe) {
27
27
  auto observation = std::make_shared<Observation>();
28
28
  auto owner = sfmljs::MakeThreadOwned<Resource>(observation);
29
29
  auto result = Nan::New<v8::Object>();
30
- Nan::Set(result, Nan::New("observation").ToLocalChecked(),
31
- ObservationHandle::Create(observation)).FromJust();
32
- Nan::Set(result, Nan::New("buffer").ToLocalChecked(),
33
- sfmljs::MapShared(info.GetIsolate(), owner, &owner->value,
34
- sizeof(owner->value))).FromJust();
30
+ Nan::Set(result,
31
+ Nan::New("observation").ToLocalChecked(),
32
+ ObservationHandle::Create(observation))
33
+ .FromJust();
34
+ Nan::Set(result,
35
+ Nan::New("buffer").ToLocalChecked(),
36
+ sfmljs::MapShared(
37
+ info.GetIsolate(), owner, &owner->value, sizeof(owner->value)))
38
+ .FromJust();
35
39
  info.GetReturnValue().Set(result);
36
40
  }
37
41
 
@@ -49,8 +53,10 @@ NAN_METHOD(ReadDeletionProbe) {
49
53
  auto* observation = ObservationHandle::From(info[0]);
50
54
  if (!observation) return;
51
55
  auto result = Nan::New<v8::Array>(2);
52
- Nan::Set(result, 0, Nan::New(observation->owner()->destroyed.load())).FromJust();
53
- Nan::Set(result, 1, Nan::New(observation->owner()->wrongThread.load())).FromJust();
56
+ Nan::Set(result, 0, Nan::New(observation->owner()->destroyed.load()))
57
+ .FromJust();
58
+ Nan::Set(result, 1, Nan::New(observation->owner()->wrongThread.load()))
59
+ .FromJust();
54
60
  info.GetReturnValue().Set(result);
55
61
  }
56
62
  } // namespace