sfml.js 1.0.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +44 -51
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,10 +1,16 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { native, type NativeGraphicsHandle } from '../internal/native';
3
3
  import {
4
- flushGraphics, graphicsContext, graphicsNative, shaderId, shaderTextures,
4
+ flushGraphics,
5
+ graphicsContext,
6
+ graphicsNative,
7
+ shaderId,
8
+ shaderTextures,
5
9
  } from '../internal/graphics-state';
6
10
  import {
7
- vector2Storage, vector3Storage, type ReadonlyValue as R,
11
+ vector2Storage,
12
+ vector3Storage,
13
+ type ReadonlyValue as R,
8
14
  } from '../internal/value-storage';
9
15
  import { glslStorage } from '../internal/glsl-value';
10
16
  import { InputStream } from '../system/input-stream';
@@ -41,13 +47,30 @@ export enum ShaderType {
41
47
  Fragment,
42
48
  }
43
49
 
44
- type Uniform = number | boolean | R<Glsl.Vec2> | R<Glsl.Vec3> | R<Glsl.Vec4> |
45
- R<Glsl.Ivec2> | R<Glsl.Ivec3> | R<Glsl.Ivec4> |
46
- R<Glsl.Bvec2> | R<Glsl.Bvec3> | R<Glsl.Bvec4> |
47
- R<Glsl.Mat3> | R<Glsl.Mat4> | ReadonlyTexture | typeof Shader.CurrentTexture;
48
- type ArrayElement = number | R<Glsl.Vec2> | R<Glsl.Vec3> | R<Glsl.Vec4> |
49
- R<Glsl.Mat3> | R<Glsl.Mat4>;
50
- type Sources<T> = [ T, ShaderType ] | [ T, T ] | [ T, T, T ];
50
+ type Uniform =
51
+ | number
52
+ | boolean
53
+ | R<Glsl.Vec2>
54
+ | R<Glsl.Vec3>
55
+ | R<Glsl.Vec4>
56
+ | R<Glsl.Ivec2>
57
+ | R<Glsl.Ivec3>
58
+ | R<Glsl.Ivec4>
59
+ | R<Glsl.Bvec2>
60
+ | R<Glsl.Bvec3>
61
+ | R<Glsl.Bvec4>
62
+ | R<Glsl.Mat3>
63
+ | R<Glsl.Mat4>
64
+ | ReadonlyTexture
65
+ | typeof Shader.CurrentTexture;
66
+ type ArrayElement =
67
+ | number
68
+ | R<Glsl.Vec2>
69
+ | R<Glsl.Vec3>
70
+ | R<Glsl.Vec4>
71
+ | R<Glsl.Mat3>
72
+ | R<Glsl.Mat4>;
73
+ type Sources<T> = [T, ShaderType] | [T, T] | [T, T, T];
51
74
 
52
75
  /**
53
76
  * Read-only interface to the same shader program.
@@ -55,9 +78,15 @@ type Sources<T> = [ T, ShaderType ] | [ T, T ] | [ T, T, T ];
55
78
  * @ja 同じシェーダープログラムへの読み取り専用インターフェース。
56
79
  * @ko 동일한 셰이더 프로그램의 읽기 전용 인터페이스입니다.
57
80
  */
58
- export type ReadonlyShader = Readonly<Pick<Shader,
59
- typeof graphicsNative | typeof shaderId | typeof shaderTextures |
60
- 'getNativeHandle'>>;
81
+ export type ReadonlyShader = Readonly<
82
+ Pick<
83
+ Shader,
84
+ | typeof graphicsNative
85
+ | typeof shaderId
86
+ | typeof shaderTextures
87
+ | 'getNativeHandle'
88
+ >
89
+ >;
61
90
 
62
91
  function nameString(name: string): void {
63
92
  if (typeof name !== 'string' || name.includes('\0')) {
@@ -65,20 +94,49 @@ function nameString(name: string): void {
65
94
  }
66
95
  }
67
96
 
68
- function numeric(value: Uniform): { type: number; data: Float32Array | Int32Array } {
69
- if (typeof value === 'number') return { type: 0, data: new Float32Array([ value ]) };
70
- if (typeof value === 'boolean') return { type: 2, data: new Int32Array([ +value ]) };
71
- if (value instanceof Glsl.Vec2) return { type: 3, data: value[vector2Storage] as Float32Array };
72
- if (value instanceof Glsl.Vec3) return { type: 4, data: value[vector3Storage] as Float32Array };
73
- if (value instanceof Glsl.Vec4) return { type: 5, data: value[glslStorage] as Float32Array };
74
- if (value instanceof Glsl.Ivec2) return { type: 6, data: value[vector2Storage] as Int32Array };
75
- if (value instanceof Glsl.Ivec3) return { type: 7, data: value[vector3Storage] as Int32Array };
76
- if (value instanceof Glsl.Ivec4) return { type: 8, data: value[glslStorage] as Int32Array };
77
- if (value instanceof Glsl.Bvec2) return { type: 9, data: new Int32Array(value[glslStorage]) };
78
- if (value instanceof Glsl.Bvec3) return { type: 10, data: new Int32Array(value[glslStorage]) };
79
- if (value instanceof Glsl.Bvec4) return { type: 11, data: new Int32Array(value[glslStorage]) };
80
- if (value instanceof Glsl.Mat3) return { type: 12, data: value[glslStorage] };
81
- if (value instanceof Glsl.Mat4) return { type: 13, data: value[glslStorage] };
97
+ function numeric(value: Uniform): {
98
+ type: number;
99
+ data: Float32Array | Int32Array;
100
+ } {
101
+ if (typeof value === 'number') {
102
+ return { type: 0, data: new Float32Array([ value ]) };
103
+ }
104
+ if (typeof value === 'boolean') {
105
+ return { type: 2, data: new Int32Array([ +value ]) };
106
+ }
107
+ if (value instanceof Glsl.Vec2) {
108
+ return { type: 3, data: value[vector2Storage] as Float32Array };
109
+ }
110
+ if (value instanceof Glsl.Vec3) {
111
+ return { type: 4, data: value[vector3Storage] as Float32Array };
112
+ }
113
+ if (value instanceof Glsl.Vec4) {
114
+ return { type: 5, data: value[glslStorage] as Float32Array };
115
+ }
116
+ if (value instanceof Glsl.Ivec2) {
117
+ return { type: 6, data: value[vector2Storage] as Int32Array };
118
+ }
119
+ if (value instanceof Glsl.Ivec3) {
120
+ return { type: 7, data: value[vector3Storage] as Int32Array };
121
+ }
122
+ if (value instanceof Glsl.Ivec4) {
123
+ return { type: 8, data: value[glslStorage] as Int32Array };
124
+ }
125
+ if (value instanceof Glsl.Bvec2) {
126
+ return { type: 9, data: new Int32Array(value[glslStorage]) };
127
+ }
128
+ if (value instanceof Glsl.Bvec3) {
129
+ return { type: 10, data: new Int32Array(value[glslStorage]) };
130
+ }
131
+ if (value instanceof Glsl.Bvec4) {
132
+ return { type: 11, data: new Int32Array(value[glslStorage]) };
133
+ }
134
+ if (value instanceof Glsl.Mat3) {
135
+ return { type: 12, data: value[glslStorage] };
136
+ }
137
+ if (value instanceof Glsl.Mat4) {
138
+ return { type: 13, data: value[glslStorage] };
139
+ }
82
140
  throw new TypeError('Expected a Shader uniform value');
83
141
  }
84
142
 
@@ -103,7 +161,9 @@ export class Shader {
103
161
  * @ja 描画時に現在のオブジェクトにバインドされたテクスチャを使う uniform テクスチャのプレースホルダー。
104
162
  * @ko 그릴 때 현재 객체에 바인딩된 텍스처를 사용하는 텍스처 uniform 자리표시자입니다.
105
163
  */
106
- static readonly CurrentTexture: unique symbol = Symbol('Shader.CurrentTexture');
164
+ static readonly CurrentTexture: unique symbol = Symbol(
165
+ 'Shader.CurrentTexture',
166
+ );
107
167
  readonly [graphicsNative]: NativeGraphicsHandle<'shader'>;
108
168
  readonly [shaderId]: number;
109
169
  /**
@@ -172,16 +232,26 @@ export class Shader {
172
232
  const code: (string | null)[] = [ null, null, null ];
173
233
  for (let i = 0; i < 3; i++) {
174
234
  const stream = stages[i];
175
- if (stream === null) continue;
176
- if (!(stream instanceof InputStream)) throw new TypeError('Expected an InputStream');
235
+ if (stream === null) {
236
+ continue;
237
+ }
238
+ if (!(stream instanceof InputStream)) {
239
+ throw new TypeError('Expected an InputStream');
240
+ }
177
241
  const size = await stream.getSize();
178
- if (size === undefined || size === 0n) return false;
242
+ if (size === undefined || size === 0n) {
243
+ return false;
244
+ }
179
245
  if (typeof size !== 'bigint' || size < 0n || size > 0x7fffffffn) {
180
246
  throw new RangeError('Shader stream size exceeds the buffer limit');
181
247
  }
182
- if (await stream.seek(0n) === undefined) return false;
248
+ if ((await stream.seek(0n)) === undefined) {
249
+ return false;
250
+ }
183
251
  const bytes = new Uint8Array(Number(size));
184
- if (await stream.read(bytes) !== size) return false;
252
+ if ((await stream.read(bytes)) !== size) {
253
+ return false;
254
+ }
185
255
  code[i] = Buffer.from(bytes.buffer).toString('utf8');
186
256
  }
187
257
  return this.compile(true, code);
@@ -204,23 +274,36 @@ export class Shader {
204
274
  * @ko 기록된 그리기를 먼저 제출한 후 GLSL float 또는 int를 명시하여 숫자 uniform을 설정합니다.
205
275
  */
206
276
  setUniform(name: string, value: number, type: 'float' | 'int'): void;
207
- setUniform(name: string, value: Uniform, scalarType?: 'float' | 'int'): void {
277
+ setUniform(
278
+ name: string,
279
+ value: Uniform,
280
+ scalarType?: 'float' | 'int',
281
+ ): void {
208
282
  nameString(name);
209
- if (scalarType !== undefined &&
210
- (typeof value !== 'number' || ![ 'float', 'int' ].includes(scalarType))) {
211
- throw new TypeError('Expected a numeric uniform and float or int type');
283
+ if (
284
+ scalarType !== undefined &&
285
+ (typeof value !== 'number' || ![ 'float', 'int' ].includes(scalarType))
286
+ ) {
287
+ throw new TypeError(
288
+ 'Expected a numeric uniform and float or int type',
289
+ );
212
290
  }
213
291
  if (value instanceof Texture || value === Shader.CurrentTexture) {
214
292
  flushGraphics();
215
- const location = native.setShaderTexture(this[graphicsNative], name,
216
- value instanceof Texture ? value[graphicsNative] : null);
293
+ const location = native.setShaderTexture(
294
+ this[graphicsNative],
295
+ name,
296
+ value instanceof Texture ? value[graphicsNative] : null,
297
+ );
217
298
  if (value instanceof Texture && location !== undefined) {
218
299
  this.textures.set(location, value);
219
300
  }
220
301
  return;
221
302
  }
222
- const { type, data } = scalarType === 'int'
223
- ? { type: 1, data: new Int32Array([ value as number ]) } : numeric(value);
303
+ const { type, data } =
304
+ scalarType === 'int'
305
+ ? { type: 1, data: new Int32Array([ value as number ]) }
306
+ : numeric(value);
224
307
  flushGraphics();
225
308
  native.setShaderUniform(this[graphicsNative], name, type, data, false);
226
309
  }
@@ -232,18 +315,30 @@ export class Shader {
232
315
  * @ja 記録済み描画を先に送信し、同じ型の float、浮動小数点ベクトル、または行列の配列を同期的にアップロードします。
233
316
  * @ko 기록된 그리기를 먼저 제출한 후 동일 형식의 float, 부동소수점 벡터 또는 행렬 배열을 동기적으로 업로드합니다.
234
317
  */
235
- setUniformArray(name: string, values: Float32Array | readonly ArrayElement[]): void {
318
+ setUniformArray(
319
+ name: string,
320
+ values: Float32Array | readonly ArrayElement[],
321
+ ): void {
236
322
  nameString(name);
237
323
  let type = 0;
238
324
  let data: Float32Array;
239
- if (values instanceof Float32Array) data = values;
240
- else {
241
- if (!Array.isArray(values)) throw new TypeError('Expected a uniform array');
325
+ if (values instanceof Float32Array) {
326
+ data = values;
327
+ } else {
328
+ if (!Array.isArray(values)) {
329
+ throw new TypeError('Expected a uniform array');
330
+ }
242
331
  const parts = Array.from(values, value => numeric(value));
243
- if (parts.length) type = parts[0].type;
244
- if (![ 0, 3, 4, 5, 12, 13 ].includes(type) ||
245
- parts.some(part => part.type !== type)) {
246
- throw new TypeError('Expected a homogeneous float, vector or matrix array');
332
+ if (parts.length) {
333
+ type = parts[0].type;
334
+ }
335
+ if (
336
+ ![ 0, 3, 4, 5, 12, 13 ].includes(type) ||
337
+ parts.some(part => part.type !== type)
338
+ ) {
339
+ throw new TypeError(
340
+ 'Expected a homogeneous float, vector or matrix array',
341
+ );
247
342
  }
248
343
  const size = parts[0]?.data.length ?? 1;
249
344
  data = new Float32Array(parts.length * size);
@@ -283,14 +378,18 @@ export class Shader {
283
378
  * @ja 現在の環境がシェーダーに対応しているかを返します。
284
379
  * @ko 현재 환경의 셰이더 지원 여부를 반환합니다.
285
380
  */
286
- static isAvailable(): boolean { return native.isShaderAvailable(false); }
381
+ static isAvailable(): boolean {
382
+ return native.isShaderAvailable(false);
383
+ }
287
384
  /**
288
385
  * Returns whether the current environment supports geometry shaders.
289
386
  * @zh 返回当前环境是否支持几何着色器。
290
387
  * @ja 現在の環境がジオメトリシェーダーに対応しているかを返します。
291
388
  * @ko 현재 환경의 기하 셰이더 지원 여부를 반환합니다.
292
389
  */
293
- static isGeometryAvailable(): boolean { return native.isShaderAvailable(true); }
390
+ static isGeometryAvailable(): boolean {
391
+ return native.isShaderAvailable(true);
392
+ }
294
393
 
295
394
  /**
296
395
  * Normalizes stage arguments into a [vertex, geometry, fragment] tuple.
@@ -300,16 +399,26 @@ export class Shader {
300
399
  */
301
400
  private stages<T>(sources: Sources<T>): (T | null)[] {
302
401
  if (sources.length === 2 && typeof sources[1] === 'number') {
303
- if (!Number.isInteger(sources[1]) || sources[1] < 0 || sources[1] > 2) {
402
+ if (
403
+ !Number.isInteger(sources[1]) ||
404
+ sources[1] < 0 ||
405
+ sources[1] > 2
406
+ ) {
304
407
  throw new RangeError('Invalid shader type');
305
408
  }
306
409
  const result: (T | null)[] = [ null, null, null ];
307
410
  result[sources[1]] = sources[0];
308
411
  return result;
309
412
  }
310
- if (sources.length === 2) return [ sources[0], null, sources[1] as T ];
311
- if (sources.length === 3) return sources as T[];
312
- throw new TypeError('Expected a shader source and type, or two/three sources');
413
+ if (sources.length === 2) {
414
+ return [ sources[0], null, sources[1] as T ];
415
+ }
416
+ if (sources.length === 3) {
417
+ return sources as T[];
418
+ }
419
+ throw new TypeError(
420
+ 'Expected a shader source and type, or two/three sources',
421
+ );
313
422
  }
314
423
 
315
424
  /**
@@ -318,11 +427,20 @@ export class Shader {
318
427
  * @ja ファイルまたはメモリからソースを読み込み、コンパイルします。
319
428
  * @ko 파일 또는 메모리에서 소스를 로드하고 컴파일합니다.
320
429
  */
321
- private async load(memory: boolean, sources: Sources<string>): Promise<boolean> {
430
+ private async load(
431
+ memory: boolean,
432
+ sources: Sources<string>,
433
+ ): Promise<boolean> {
322
434
  const stages = this.stages(sources).map(source => {
323
- if (source === null) return null;
324
- if (typeof source !== 'string') throw new TypeError('Expected shader source strings');
325
- if (!memory && source.includes('\0')) throw new TypeError('Invalid shader path');
435
+ if (source === null) {
436
+ return null;
437
+ }
438
+ if (typeof source !== 'string') {
439
+ throw new TypeError('Expected shader source strings');
440
+ }
441
+ if (!memory && source.includes('\0')) {
442
+ throw new TypeError('Invalid shader path');
443
+ }
326
444
  return memory || !source ? source : resolve(source);
327
445
  });
328
446
  return this.compile(memory, stages);
@@ -334,11 +452,18 @@ export class Shader {
334
452
  * @ja シェーダープログラムを非同期にコンパイルしてリンクします。
335
453
  * @ko 셰이더 프로그램을 비동기로 컴파일하고 링크합니다.
336
454
  */
337
- private compile(memory: boolean, sources: (string | null)[]): Promise<boolean> {
455
+ private compile(
456
+ memory: boolean,
457
+ sources: (string | null)[],
458
+ ): Promise<boolean> {
338
459
  return new Promise((resolve, reject) => {
339
460
  native.compileShader(memory, sources, (error, program) => {
340
- if (error) return reject(error);
341
- if (!program) return resolve(false);
461
+ if (error) {
462
+ return reject(error);
463
+ }
464
+ if (!program) {
465
+ return resolve(false);
466
+ }
342
467
  try {
343
468
  flushGraphics();
344
469
  native.commitShader(this[graphicsNative], program);
@@ -1,15 +1,27 @@
1
1
  import {
2
- native, type NativeGraphicsHandle, type NativeShapeInfo,
2
+ native,
3
+ type NativeGraphicsHandle,
4
+ type NativeShapeInfo,
3
5
  } from '../internal/native';
4
6
  import {
5
- dispatchDrawable, flushShapeReaders, graphicsContext, graphicsNative,
6
- recordShape, shapeState, textureId, type ShapeData,
7
+ dispatchDrawable,
8
+ flushShapeReaders,
9
+ graphicsContext,
10
+ graphicsNative,
11
+ recordShape,
12
+ shapeState,
13
+ textureId,
14
+ type ShapeData,
7
15
  } from '../internal/graphics-state';
8
16
  import {
9
- withTransformable, transformableState, type TransformableState,
17
+ withTransformable,
18
+ transformableState,
19
+ type TransformableState,
10
20
  } from '../internal/transformable';
11
21
  import {
12
- mutableValue, rectStorage, type ReadonlyValue as R,
22
+ mutableValue,
23
+ rectStorage,
24
+ type ReadonlyValue as R,
13
25
  } from '../internal/value-storage';
14
26
  import { LazyValue } from '../internal/lazy-value';
15
27
  import { nativeStruct } from '../internal/struct-view';
@@ -29,7 +41,9 @@ interface ShapeInit {
29
41
  }
30
42
 
31
43
  export function shapeNumber(value: number): number {
32
- if (typeof value !== 'number') throw new TypeError('Expected a number');
44
+ if (typeof value !== 'number') {
45
+ throw new TypeError('Expected a number');
46
+ }
33
47
  const result = Math.fround(value);
34
48
  if (!Number.isFinite(result)) {
35
49
  throw new RangeError('Expected a finite float32 value');
@@ -38,8 +52,11 @@ export function shapeNumber(value: number): number {
38
52
  }
39
53
 
40
54
  export function shapeCount(value: number): number {
41
- if (!Number.isInteger(value) || value < 0 ||
42
- value > Math.floor(0x7fffffff / (6 * 20)) - 2) {
55
+ if (
56
+ !Number.isInteger(value) ||
57
+ value < 0 ||
58
+ value > Math.floor(0x7fffffff / (6 * 20)) - 2
59
+ ) {
43
60
  throw new RangeError('Shape point count exceeds the buffer limit');
44
61
  }
45
62
  return value;
@@ -68,16 +85,23 @@ class ShapeResource extends Drawable {
68
85
 
69
86
  constructor(init: ShapeInit) {
70
87
  super();
71
- const mapping = native.createShape(graphicsContext(), init.kind,
72
- init.x ?? 0, init.y ?? 0, init.source?.[graphicsNative]);
88
+ const mapping = native.createShape(
89
+ graphicsContext(),
90
+ init.kind,
91
+ init.x ?? 0,
92
+ init.y ?? 0,
93
+ init.source?.[graphicsNative],
94
+ );
73
95
  this[graphicsNative] = mapping.handle;
74
96
  this[shapeState] = {
75
- id: mapping.id, words: new Uint32Array(mapping.appearance),
97
+ id: mapping.id,
98
+ words: new Uint32Array(mapping.appearance),
76
99
  rectangle: new Int32Array(mapping.appearance, 12, 4),
77
100
  texture: init.source?.[shapeState].texture ?? null,
78
101
  };
79
102
  this[transformableState] = {
80
- handle: mapping.transformable, values: new Float32Array(mapping.buffer),
103
+ handle: mapping.transformable,
104
+ values: new Float32Array(mapping.buffer),
81
105
  };
82
106
  this.shapeInfo = nativeStruct<NativeShapeInfo>(mapping.info);
83
107
  }
@@ -90,18 +114,27 @@ class ShapeResource extends Drawable {
90
114
  * @ko 텍스처 참조를 설정하고 유지합니다. null은 텍스처를 비활성화하며 resetRect가 true이면 전체 텍스처를 사용합니다.
91
115
  */
92
116
  setTexture(
93
- this: ShapeResource, texture: ReadonlyTexture | null, resetRect = false,
117
+ this: ShapeResource,
118
+ texture: ReadonlyTexture | null,
119
+ resetRect = false,
94
120
  ): void {
95
121
  if (texture !== null && !(texture instanceof Texture)) {
96
122
  throw new TypeError('Expected a Texture or null');
97
123
  }
98
- if (typeof resetRect !== 'boolean') throw new TypeError('Expected a boolean');
124
+ if (typeof resetRect !== 'boolean') {
125
+ throw new TypeError('Expected a boolean');
126
+ }
99
127
  const state = this[shapeState];
100
- const reset = texture && (resetRect ||
101
- (!state.texture && state.rectangle.every(value => value === 0)));
128
+ const reset =
129
+ texture &&
130
+ (resetRect ||
131
+ (!state.texture && state.rectangle.every(value => value === 0)));
102
132
  if (texture !== state.texture) {
103
- native.setShapeTexture(this[graphicsNative],
104
- texture?.[graphicsNative] ?? null, texture?.[textureId] ?? 0);
133
+ native.setShapeTexture(
134
+ this[graphicsNative],
135
+ texture?.[graphicsNative] ?? null,
136
+ texture?.[textureId] ?? 0,
137
+ );
105
138
  state.texture = texture;
106
139
  }
107
140
  if (reset) {
@@ -128,7 +161,9 @@ class ShapeResource extends Drawable {
128
161
  * @ko 사용할 텍스처 픽셀 영역을 복사합니다. 음수 크기로 텍스처를 반전할 수 있습니다.
129
162
  */
130
163
  setTextureRect(this: ShapeResource, rectangle: R<IntRect>): void {
131
- if (!(rectangle instanceof IntRect)) throw new TypeError('Expected an IntRect');
164
+ if (!(rectangle instanceof IntRect)) {
165
+ throw new TypeError('Expected an IntRect');
166
+ }
132
167
  this[shapeState].rectangle.set(rectangle[rectStorage]);
133
168
  }
134
169
 
@@ -141,9 +176,11 @@ class ShapeResource extends Drawable {
141
176
  getTextureRect(): R<IntRect> {
142
177
  if (!this.rectangleView) {
143
178
  const handle = this[graphicsNative];
144
- this.rectangleView = intRectFromState(new LazyValue(
145
- this[shapeState].rectangle, () => native.shapeTextureRect(handle),
146
- ));
179
+ this.rectangleView = intRectFromState(
180
+ new LazyValue(this[shapeState].rectangle, () =>
181
+ native.shapeTextureRect(handle),
182
+ ),
183
+ );
147
184
  }
148
185
  return this.rectangleView;
149
186
  }
@@ -155,7 +192,9 @@ class ShapeResource extends Drawable {
155
192
  * @ko 채우기 색상을 설정합니다. 그릴 때 텍스처 색상과 곱해집니다.
156
193
  */
157
194
  setFillColor(this: ShapeResource, color: R<Color>): void {
158
- if (!(color instanceof Color)) throw new TypeError('Expected a Color');
195
+ if (!(color instanceof Color)) {
196
+ throw new TypeError('Expected a Color');
197
+ }
159
198
  this[shapeState].words[1] = color.toInteger();
160
199
  }
161
200
 
@@ -176,7 +215,9 @@ class ShapeResource extends Drawable {
176
215
  * @ko 윤곽선 색상을 복사합니다.
177
216
  */
178
217
  setOutlineColor(this: ShapeResource, color: R<Color>): void {
179
- if (!(color instanceof Color)) throw new TypeError('Expected a Color');
218
+ if (!(color instanceof Color)) {
219
+ throw new TypeError('Expected a Color');
220
+ }
180
221
  this[shapeState].words[2] = color.toInteger();
181
222
  }
182
223
 
@@ -220,7 +261,9 @@ class ShapeResource extends Drawable {
220
261
  */
221
262
  setMiterLimit(this: ShapeResource, limit: number): void {
222
263
  limit = shapeNumber(limit);
223
- if (limit < 1) throw new RangeError('Miter limit must be at least 1');
264
+ if (limit < 1) {
265
+ throw new RangeError('Miter limit must be at least 1');
266
+ }
224
267
  this.changeGeometry(1, limit);
225
268
  }
226
269
 
@@ -252,31 +295,46 @@ class ShapeResource extends Drawable {
252
295
  */
253
296
  getLocalBounds(): FloatRect {
254
297
  const { left, top, boundsWidth, boundsHeight } = this.shapeInfo;
255
- return new FloatRect(new Vector2f(left, top),
256
- new Vector2f(boundsWidth, boundsHeight));
298
+ return new FloatRect(
299
+ new Vector2f(left, top),
300
+ new Vector2f(boundsWidth, boundsHeight),
301
+ );
257
302
  }
258
303
 
259
304
  protected changeGeometry(
260
- operation: number, x: number, y?: number, z?: number,
305
+ operation: number,
306
+ x: number,
307
+ y?: number,
308
+ z?: number,
261
309
  ): void {
262
310
  flushShapeReaders(this);
263
- native.changeShapeGeometry(
264
- this[graphicsNative], operation, x, y, z);
311
+ native.changeShapeGeometry(this[graphicsNative], operation, x, y, z);
265
312
  }
266
313
 
267
314
  protected readPoint(index: number): Vector2f {
268
- return new Vector2f(...native.getShapePoint(this[graphicsNative], index));
315
+ return new Vector2f(
316
+ ...native.getShapePoint(this[graphicsNative], index),
317
+ );
269
318
  }
270
319
 
271
- protected draw(this: Shape, target: RenderTarget, states: RenderStates): void {
320
+ protected draw(
321
+ this: Shape,
322
+ target: RenderTarget,
323
+ states: RenderStates,
324
+ ): void {
272
325
  target[recordShape](this, states);
273
326
  }
274
327
 
275
328
  [dispatchDrawable](
276
- this: Shape, target: RenderTarget, states: RenderStates,
329
+ this: Shape,
330
+ target: RenderTarget,
331
+ states: RenderStates,
277
332
  ): void {
278
- if (this.draw === ShapeResource.prototype.draw) this.draw(target, states);
279
- else super[dispatchDrawable](target, states);
333
+ if (this.draw === ShapeResource.prototype.draw) {
334
+ this.draw(target, states);
335
+ } else {
336
+ super[dispatchDrawable](target, states);
337
+ }
280
338
  }
281
339
  }
282
340