sfml.js 1.0.0-rc.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -136,9 +136,13 @@ node examples/all-types.cjs --frames=120
136
136
  node examples/network.cjs
137
137
  ```
138
138
 
139
- [移植済みサンプル](examples/ported/README.ja.md)は、従来のデモを SFML 3 API に適合させたものです。`drawAsync()` または `displayAsync()` を必要とする 2 つのサンプルは `UNSUPPORTED` を報告します。このバインディングでは、これらのメソッドを公開していません。
139
+ [機能サンプル](examples/features/README.ja.md) · [公式サンプル](examples/official/README.ja.md) · [ゲームとアプリ](examples/projects/README.ja.md)
140
140
 
141
- [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) と [play-nes](https://github.com/XadillaX/play-nes) は旧 API で開発されたプロジェクトであり、移行が必要です。
141
+ [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) には、sfml.js で実装した Bomberman、Breakout、Tetris、Doodle Jump、Arkanoid が含まれています。インストールと起動の手順は[ゲームプロジェクト](examples/projects/README.ja.md#node-sfml-demos)を参照してください。
142
+
143
+ [16-sfml.js-games-ported](https://github.com/XadillaX/16-sfml.js-games-ported) は、[jsyqrt/games](https://github.com/jsyqrt/games) の C++ と SFML で作られた全 16 ゲームを、ClojureScript と sfml.js に移植したものです。ゲーム一覧と nbb の起動コマンドは[16 ゲーム](examples/projects/README.ja.md#16-games)を参照してください。
144
+
145
+ [play-nes](examples/projects/README.ja.md#play-nes) — sfml.js と JSNES で構築されたデスクトップ NES エミュレータ。
142
146
 
143
147
  ## コントリビュート
144
148
 
package/README.ko.md CHANGED
@@ -136,9 +136,13 @@ node examples/all-types.cjs --frames=120
136
136
  node examples/network.cjs
137
137
  ```
138
138
 
139
- [포팅된 예제](examples/ported/README.ko.md)는 기존 데모를 유지하면서 SFML 3 API에 맞게 조정한 것입니다. `drawAsync()` 또는 `displayAsync()`가 필요한 두 예제는 `UNSUPPORTED`를 출력합니다. 이 바인딩에서는 해당 메서드를 제공하지 않습니다.
139
+ [기능 예제](examples/features/README.ko.md) · [공식 예제](examples/official/README.ko.md) · [게임과 앱](examples/projects/README.ko.md)
140
140
 
141
- [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos)와 [play-nes](https://github.com/XadillaX/play-nes)는 이전 API로 제작된 프로젝트이므로 마이그레이션이 필요합니다.
141
+ [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos)에는 sfml.js로 구현한 Bomberman, Breakout, Tetris, Doodle Jump, Arkanoid가 포함되어 있습니다. 설치 및 실행 명령은 [게임 프로젝트](examples/projects/README.ko.md#node-sfml-demos)를 참고하세요.
142
+
143
+ [16-sfml.js-games-ported](https://github.com/XadillaX/16-sfml.js-games-ported)는 [jsyqrt/games](https://github.com/jsyqrt/games)의 C++과 SFML로 작성된 원본 게임 16개를 모두 ClojureScript와 sfml.js로 이식한 프로젝트입니다. 게임 목록과 nbb 실행 명령은 [게임 16개](examples/projects/README.ko.md#16-games)를 참고하세요.
144
+
145
+ [play-nes](examples/projects/README.ko.md#play-nes) — sfml.js와 JSNES로 구축된 데스크톱 NES 에뮬레이터.
142
146
 
143
147
  ## 기여하기
144
148
 
package/README.md CHANGED
@@ -136,9 +136,13 @@ node examples/all-types.cjs --frames=120
136
136
  node examples/network.cjs
137
137
  ```
138
138
 
139
- The [ported examples](examples/ported/README.md) retain the legacy demonstrations with SFML 3 API adaptations. The two examples requiring `drawAsync()` or `displayAsync()` report `UNSUPPORTED`; those methods are not exposed by this binding.
139
+ [Feature examples](examples/features/README.md) · [Official examples](examples/official/README.md) · [Games and applications](examples/projects/README.md)
140
140
 
141
- [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) and [play-nes](https://github.com/XadillaX/play-nes) are projects built with the legacy API and require migration.
141
+ [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) contains Bomberman, Breakout, Tetris, Doodle Jump and Arkanoid implementations using sfml.js. See [game setup](examples/projects/README.md#node-sfml-demos) for installation and launch commands.
142
+
143
+ [16-sfml.js-games-ported](https://github.com/XadillaX/16-sfml.js-games-ported) ports all 16 games from [jsyqrt/games](https://github.com/jsyqrt/games), originally written in C++ with SFML, to ClojureScript with sfml.js. See [16 games](examples/projects/README.md#16-games) for the game list and nbb launch commands.
144
+
145
+ [play-nes](examples/projects/README.md#play-nes) — a desktop NES emulator built with sfml.js and JSNES.
142
146
 
143
147
  ## Contributing
144
148
 
package/README.zh-CN.md CHANGED
@@ -136,9 +136,13 @@ node examples/all-types.cjs --frames=120
136
136
  node examples/network.cjs
137
137
  ```
138
138
 
139
- [旧版示例](examples/ported/README.zh-CN.md) 保留原演示,并适配 SFML 3 API。其中依赖 `drawAsync()` 或 `displayAsync()` 的两个入口报告 `UNSUPPORTED`;当前绑定不提供这两个方法。
139
+ [功能示例](examples/features/README.zh-CN.md) · [官方示例](examples/official/README.zh-CN.md) · [游戏与应用](examples/projects/README.zh-CN.md)
140
140
 
141
- [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) 和 [play-nes](https://github.com/XadillaX/play-nes) 使用旧版 API,需要适配后使用。
141
+ [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos) 包含使用 sfml.js 实现的 Bomberman、Breakout、Tetris、Doodle Jump 和 Arkanoid。安装与启动命令见 [游戏项目](examples/projects/README.zh-CN.md#node-sfml-demos)。
142
+
143
+ [16-sfml.js-games-ported](https://github.com/XadillaX/16-sfml.js-games-ported) 将 [jsyqrt/games](https://github.com/jsyqrt/games) 中原本使用 C++ 和 SFML 编写的全部 16 个游戏迁移为 ClojureScript + sfml.js。游戏清单与 nbb 启动命令见 [16 个游戏](examples/projects/README.zh-CN.md#16-games)。
144
+
145
+ [play-nes](examples/projects/README.zh-CN.md#play-nes) — 基于 sfml.js 和 JSNES 的桌面 NES 模拟器。
142
146
 
143
147
  ## 参与贡献
144
148
 
Binary file
@@ -36,7 +36,6 @@ npm ci
36
36
  | `npm run test:types` | TypeScript のインターフェースを検証 |
37
37
  | `npm run test:runtime` | ランタイムテストを直列に実行。事前にビルドが必要 |
38
38
  | `npm test` | lint、ビルド、型検査、ランタイムテストを順に実行 |
39
- | `npm run test:ported` | 移植済みサンプルを検証し、成功と未対応を区別して報告 |
40
39
  | `npm pack --dry-run` | npm パッケージのファイル一覧を確認 |
41
40
 
42
41
  TypeScript だけを変更した場合は `npm run build:ts`、ネイティブ部分を変更した場合は `npm run build` を実行します。ランタイムテストは自動的に再ビルドしないため、実行前にビルド結果とソースコードが一致していることを確認してください。
@@ -46,10 +45,9 @@ TypeScript だけを変更した場合は `npm run build:ts`、ネイティブ
46
45
 
47
46
  ```sh
48
47
  npm test
49
- npm run test:ported
50
48
  ```
51
49
 
52
- `npm test` は lint、ネイティブ部分と TypeScript のビルド、型検査、ランタイムテストを実行します。test:ported は旧バージョンから移植したサンプルを別途検証し、成功と未対応を区別します。
50
+ `npm test` は lint、ネイティブ部分と TypeScript のビルド、型検査、ランタイムテストを実行します。
53
51
 
54
52
  ランタイムテストはファイル単位で直列に実行し、公開インターフェース、ネイティブ SFML との比較、実際に描画されたピクセル、非同期 I/O、スナップショット、ライフサイクルを検証します。型テストは `test/*.types.ts`、ランタイムテストは `test/*.test.cjs`、ネイティブ比較テストは `test/native/` にあります。
55
53
 
@@ -116,9 +114,7 @@ npm run demo:audio
116
114
  npm run demo:network
117
115
  ```
118
116
 
119
- サンプルの説明は [examples/README.md](../examples/README.ja.md)を参照してください。ビルド済みであれば、`node examples/<名称>.cjs`(`<名称>` はサンプル名)で直接実行できます。`--frames` に対応する入口ではフレーム数を制限できます。スクリーンショットの撮影方法もサンプル一覧に記載しています。
120
-
121
- 旧版の `drawAsync`/`displayAsync` を使う 2 つのサンプルは、未対応であることを明示的に報告します。詳細は[移植に関する説明](../examples/ported/README.ja.md)を参照してください。
117
+ サンプルは[概要](../examples/README.ja.md)、[機能](../examples/features/README.ja.md)、[公式](../examples/official/README.ja.md)、[ゲームとアプリ](../examples/projects/README.ja.md)に分かれています。コマンドと[撮影機能](../examples/features/README.ja.md#screenshots)は各入口で説明しています。ビルド後はスクリプトを直接実行し、`--frames` は対応する入口にだけ渡してください。
122
118
 
123
119
  ## ソースコードと生成ファイル
124
120
 
@@ -36,7 +36,6 @@ npm ci
36
36
  | `npm run test:types` | TypeScript 인터페이스 검증 |
37
37
  | `npm run test:runtime` | 런타임 테스트를 직렬 실행. 사전 빌드 필요 |
38
38
  | `npm test` | lint, 빌드, 타입 검사, 런타임 테스트를 순서대로 실행 |
39
- | `npm run test:ported` | 포팅된 예제를 검증하고 통과와 미지원을 구분해 보고 |
40
39
  | `npm pack --dry-run` | npm 패키지 파일 목록 확인 |
41
40
 
42
41
  TypeScript만 수정했다면 `npm run build:ts`를 실행할 수 있습니다. 네이티브 코드를 수정했다면 `npm run build`를 실행하세요. 런타임 테스트는 자동으로 다시 빌드하지 않으므로, 실행 전에 빌드 결과가 소스와 일치하는지 확인해야 합니다.
@@ -46,10 +45,9 @@ TypeScript만 수정했다면 `npm run build:ts`를 실행할 수 있습니다.
46
45
 
47
46
  ```sh
48
47
  npm test
49
- npm run test:ported
50
48
  ```
51
49
 
52
- `npm test`는 lint, 네이티브 및 TypeScript 빌드, 타입 검사, 런타임 테스트를 실행합니다. test:ported는 이전 버전에서 포팅한 예제를 별도로 검증하며, 통과와 미지원을 구분합니다.
50
+ `npm test`는 lint, 네이티브 및 TypeScript 빌드, 타입 검사, 런타임 테스트를 실행합니다.
53
51
 
54
52
  런타임 테스트는 파일별로 직렬 실행되며 공개 인터페이스, 네이티브 SFML 대조, 실제 렌더링 픽셀, 비동기 I/O, 스냅샷, 수명 주기를 검증합니다. 타입 테스트는 `test/*.types.ts`, 런타임 테스트는 `test/*.test.cjs`, 네이티브 대조 테스트는 `test/native/`에 있습니다.
55
53
 
@@ -116,9 +114,7 @@ npm run demo:audio
116
114
  npm run demo:network
117
115
  ```
118
116
 
119
- 예제 설명은 [examples/README.md](../examples/README.ko.md)를 참고하세요. 빌드된 상태라면 `node examples/<이름>.cjs`를 직접 실행할 수 있습니다. `--frames`를 지원하는 진입점에서는 프레임 수를 제한할 수 있으며, 스크린샷 방법도 예제 목록에 설명되어 있습니다.
120
-
121
- 이전 버전의 `drawAsync`/`displayAsync` 예제 두 개는 미지원 상태를 명시적으로 보고합니다. 자세한 내용은 [포팅 안내](../examples/ported/README.ko.md)를 참고하세요.
117
+ 예제는 [개요](../examples/README.ko.md), [기능 예제](../examples/features/README.ko.md), [공식 예제](../examples/official/README.ko.md), [게임과 앱](../examples/projects/README.ko.md)으로 나뉩니다. 명령과 [캡처 지원](../examples/features/README.ko.md#screenshots)은 각 진입점에 설명되어 있습니다. 빌드 후 스크립트를 직접 실행하고 지원하는 진입점에만 `--frames`를 전달하세요.
122
118
 
123
119
  ## 소스와 생성 파일
124
120
 
@@ -37,7 +37,6 @@ Run these commands from the repository root:
37
37
  | `npm run test:types` | Validate TypeScript APIs |
38
38
  | `npm run test:runtime` | Run runtime tests serially; requires a prior build |
39
39
  | `npm test` | Run lint, build, type checks and runtime tests in sequence |
40
- | `npm run test:ported` | Validate ported examples, reporting passes and unsupported cases separately |
41
40
  | `npm pack --dry-run` | Inspect the npm package file list |
42
41
 
43
42
  For TypeScript-only changes, run `npm run build:ts`; after native changes, run `npm run build`. Runtime tests do not rebuild automatically, so ensure the build matches the source before running them.
@@ -48,10 +47,9 @@ For TypeScript-only changes, run `npm run build:ts`; after native changes, run `
48
47
 
49
48
  ```sh
50
49
  npm test
51
- npm run test:ported
52
50
  ```
53
51
 
54
- `npm test` runs lint, native and TypeScript builds, type checks and runtime tests. test:ported separately validates ported legacy examples, distinguishing passing cases from unsupported ones.
52
+ `npm test` runs lint, native and TypeScript builds, type checks and runtime tests.
55
53
 
56
54
  Runtime tests run serially by file, covering public APIs, comparisons with native SFML, actual rendered pixels, asynchronous I/O, snapshots and lifetimes. Type tests are in `test/*.types.ts`, runtime tests in `test/*.test.cjs`, and native comparisons in `test/native/`.
57
55
 
@@ -118,9 +116,7 @@ npm run demo:audio
118
116
  npm run demo:network
119
117
  ```
120
118
 
121
- See [examples/README.md](../examples/README.md) for descriptions. After building, run `node examples/<name>.cjs` directly. Entry points supporting `--frames` can limit the frame count; the examples guide also explains how to capture screenshots.
122
-
123
- The two legacy `drawAsync`/`displayAsync` examples explicitly report that they are unsupported; see the [ported examples](../examples/ported/README.md).
119
+ The examples are organized into [overview](../examples/README.md), [feature examples](../examples/features/README.md), [official examples](../examples/official/README.md) and [games and applications](../examples/projects/README.md). Commands and [screenshot support](../examples/features/README.md#screenshots) are documented with their entry points. After building, run the script directly; pass `--frames` only where supported.
124
120
 
125
121
  ## Source and generated files
126
122
 
@@ -37,7 +37,6 @@ npm ci
37
37
  | `npm run test:types` | 验证 TypeScript 接口 |
38
38
  | `npm run test:runtime` | 串行运行运行时测试,需要先构建 |
39
39
  | `npm test` | 依次执行 lint、构建、类型检查和运行时测试 |
40
- | `npm run test:ported` | 验证迁移示例,分别报告通过和不支持 |
41
40
  | `npm pack --dry-run` | 检查 npm 包文件清单 |
42
41
 
43
42
  只修改 TypeScript 时可执行 `npm run build:ts`;修改 Native 后执行 `npm run build`。运行时测试不会自动重建,运行前确保构建与源码一致。
@@ -48,10 +47,9 @@ npm ci
48
47
 
49
48
  ```sh
50
49
  npm test
51
- npm run test:ported
52
50
  ```
53
51
 
54
- `npm test` 执行 lint、Native 与 TypeScript 构建、类型检查和运行时测试。test:ported 单独验证旧版迁移示例,并区分通过与不支持。
52
+ `npm test` 执行 lint、Native 与 TypeScript 构建、类型检查和运行时测试。
55
53
 
56
54
  运行时测试按文件串行运行,覆盖公开接口、原生 SFML 对照、实际渲染像素、异步 I/O、快照及生命周期。类型测试位于 `test/*.types.ts`,运行时测试为 `test/*.test.cjs`,原生对照在 `test/native/`。
57
55
 
@@ -118,9 +116,7 @@ npm run demo:audio
118
116
  npm run demo:network
119
117
  ```
120
118
 
121
- 示例说明见 [examples/README.zh-CN.md](../examples/README.zh-CN.md)。已构建时可直接运行 `node examples/<名称>.cjs`。支持 `--frames` 的入口可限制帧数,截图方式也在示例目录说明中。
122
-
123
- 旧版 `drawAsync`/`displayAsync` 两个示例明确报告不支持,详情见 [迁移说明](../examples/ported/README.zh-CN.md)。
119
+ 示例分为 [总览](../examples/README.zh-CN.md)、[功能示例](../examples/features/README.zh-CN.md)、[官方示例](../examples/official/README.zh-CN.md) 和 [游戏与应用](../examples/projects/README.zh-CN.md)。命令和 [截图支持](../examples/features/README.zh-CN.md#screenshots) 随入口说明。构建后直接运行脚本,仅对支持的入口传入 `--frames`。
124
120
 
125
121
  ## 源码与生成文件
126
122
 
@@ -3,17 +3,55 @@
3
3
  #include <nan.h>
4
4
 
5
5
  #include <memory>
6
+ #include <unordered_map>
6
7
  #include <utility>
7
8
 
8
9
  namespace sfmljs {
9
10
 
11
+ // V8 retains instantiated template metadata in its native context. Reuse one
12
+ // shape per Node environment, and release its persistent before isolate teardown.
13
+ // All handle types have the same layout; the private marker below checks T.
14
+ class SharedHandleTemplate final {
15
+ public:
16
+ static v8::Local<v8::ObjectTemplate> Get() {
17
+ auto* environment = node::GetCurrentEnvironment(Nan::GetCurrentContext());
18
+ auto found = templates_.find(environment);
19
+ if (found == templates_.end()) {
20
+ auto* cache = new SharedHandleTemplate(environment);
21
+ found = templates_.emplace(environment, cache).first;
22
+ node::AddEnvironmentCleanupHook(v8::Isolate::GetCurrent(), Cleanup, cache);
23
+ }
24
+ return Nan::New(found->second->shape_);
25
+ }
26
+
27
+ private:
28
+ explicit SharedHandleTemplate(node::Environment* environment)
29
+ : environment_(environment) {
30
+ auto shape = Nan::New<v8::ObjectTemplate>();
31
+ shape->SetInternalFieldCount(1);
32
+ shape_.Reset(shape);
33
+ }
34
+
35
+ static void Cleanup(void* data) {
36
+ auto* cache = static_cast<SharedHandleTemplate*>(data);
37
+ cache->shape_.Reset();
38
+ templates_.erase(cache->environment_);
39
+ delete cache;
40
+ }
41
+
42
+ // Worker threads must never share V8 handles. The cleanup hook also removes
43
+ // entries when an environment is replaced on the same thread.
44
+ inline static thread_local
45
+ std::unordered_map<node::Environment*, SharedHandleTemplate*> templates_;
46
+ node::Environment* environment_;
47
+ Nan::Persistent<v8::ObjectTemplate> shape_;
48
+ };
49
+
10
50
  template <typename T>
11
51
  class SharedHandle final : public Nan::ObjectWrap {
12
52
  public:
13
53
  static v8::Local<v8::Object> Create(std::shared_ptr<T> owner) {
14
- auto shape = Nan::New<v8::ObjectTemplate>();
15
- shape->SetInternalFieldCount(1);
16
- auto object = Nan::NewInstance(shape).ToLocalChecked();
54
+ auto object = Nan::NewInstance(SharedHandleTemplate::Get()).ToLocalChecked();
17
55
  auto* handle = new SharedHandle(std::move(owner));
18
56
  handle->Wrap(object);
19
57
  Nan::SetPrivate(object, Key(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfml.js",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0",
4
4
  "description": "SFML's Node.js binding.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,8 +54,7 @@
54
54
  "demo:audio": "npm run build && node examples/audio.cjs",
55
55
  "demo:network": "npm run build:ts && node examples/network.cjs",
56
56
  "demo:ported": "npm run build:ts && node examples/ported/render_window.cjs",
57
- "test:ported": "npm run build:ts && node tools/test-ported-examples.cjs",
58
- "lint": "eslint --ext .ts,.cjs src tools test examples .eslintrc.cjs",
57
+ "lint": "eslint --ext .ts,.js,.cjs,.mjs . && eslint --no-ignore site/.vitepress/theme/hero-light.mjs",
59
58
  "jslint": "npm run lint",
60
59
  "test:types": "tsc -p test/tsconfig.json",
61
60
  "test:runtime": "node tools/run-tests.cjs",
@@ -95,6 +94,7 @@
95
94
  "@types/ssh2": "1.15.6",
96
95
  "@typescript-eslint/eslint-plugin": "^7.18.0",
97
96
  "@typescript-eslint/parser": "^7.18.0",
97
+ "@wettstein/nodegl": "1.2.1",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-egg": "^14.1.0",
100
100
  "eslint-plugin-import": "^2.32.0",
@@ -102,6 +102,7 @@
102
102
  "eslint-plugin-node": "^11.1.0",
103
103
  "typedoc": "0.28.3",
104
104
  "typedoc-material-theme": "1.4.0",
105
- "typescript": "5.0.4"
105
+ "typescript": "5.0.4",
106
+ "x11": "4.3.1"
106
107
  }
107
108
  }