Skip to content

Commit 8a00cfe

Browse files
committed
feat: try to refactor ecs with becsy
1 parent fdae86f commit 8a00cfe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2008
-416
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ pnpm run dev
9494
- Drawing dots grid.
9595
- Drawing wireframe for Geometry.
9696

97-
<img src="./screenshots/lesson5.png" width="300" alt="Lesson 5 grids">
98-
<img src="./screenshots/lesson5-2.png" width="300" alt="Lesson 5 wireframe">
97+
| Grid | Wireframe |
98+
| :--------------------------------: | :---------------------------------------: |
99+
| ![Grid](./screenshots/lesson5.png) | ![Wireframe](./screenshots/lesson5-2.png) |
99100

100101
## Lesson 6 - Event system [🔗](https://infinitecanvas.cc/guide/lesson-006)
101102

@@ -167,7 +168,9 @@ pnpm run dev
167168
- Support `fillRule` property
168169
- Draw some hand-drawn shapes
169170

170-
<img src="./screenshots/lesson13.png" width="300" alt="Lesson 13 - path">
171+
| Path and rough shapes | Fill rule |
172+
| :--------------------------------------------------: | :----------------------------------------: |
173+
| ![Path and rough shapes](./screenshots/lesson13.png) | ![Fill rule](./screenshots/lesson13-2.png) |
171174

172175
## Lesson 14 - Canvas mode and auxiliary UI [🔗](https://infinitecanvas.cc/guide/lesson-014)
173176

README.zh_CN.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ pnpm run dev
9494
- 绘制点网格
9595
- 为 Geometry 绘制 wireframe
9696

97-
<img src="./screenshots/lesson5.png" width="300" alt="Lesson 5 grids">
98-
<img src="./screenshots/lesson5-2.png" width="300" alt="Lesson 5 wireframe">
97+
| Grid | Wireframe |
98+
| :--------------------------------: | :---------------------------------------: |
99+
| ![Grid](./screenshots/lesson5.png) | ![Wireframe](./screenshots/lesson5-2.png) |
99100

100101
## 课程 6 - 事件系统 [🔗](https://infinitecanvas.cc/zh/guide/lesson-006)
101102

@@ -167,7 +168,9 @@ pnpm run dev
167168
- 支持 `fillRule` 属性
168169
- 实现一些手绘风格图形
169170

170-
<img src="./screenshots/lesson13.png" width="300" alt="Lesson 13 - path">
171+
| Path and rough shapes | Fill rule |
172+
| :--------------------------------------------------: | :----------------------------------------: |
173+
| ![Path and rough shapes](./screenshots/lesson13.png) | ![Fill rule](./screenshots/lesson13-2.png) |
171174

172175
## 课程 14 - 画布模式 [🔗](https://infinitecanvas.cc/zh/guide/lesson-014)
173176

packages/core/src/plugins/Painter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ export class Painter implements Plugin {
143143
fill: 'transparent',
144144
stroke: 'black',
145145
selectable: true,
146+
sizeAttenuation: true,
146147
});
147148
}
148-
this.#activePenLayer.appendChild(toPaint);
149+
root.appendChild(toPaint);
149150
};
150151

151152
const onMove = (state: PenState) => {
@@ -181,7 +182,7 @@ export class Painter implements Plugin {
181182
this.#cancelEvent.detail = state;
182183
root.dispatchEvent(this.#cancelEvent);
183184

184-
this.#activePenLayer.removeChild(toPaint);
185+
root.removeChild(toPaint);
185186
};
186187

187188
this.#pen.on(PenEvent.START, onStart);

packages/ecs/examples/main.ts

+47-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
import { App, Commands, Transform } from '../src';
1+
import {
2+
App,
3+
Entity,
4+
Commands,
5+
System,
6+
StartUp,
7+
Transform,
8+
Parent,
9+
Children,
10+
DefaultPlugins,
11+
GlobalTransform,
12+
} from '../src';
213

314
const $canvas = document.getElementById('canvas') as HTMLCanvasElement;
415
const resize = (width: number, height: number) => {
@@ -12,38 +23,45 @@ const resize = (width: number, height: number) => {
1223
};
1324
resize(window.innerWidth, window.innerHeight);
1425

15-
let started = false;
26+
let parent_entity: Entity;
27+
let child_entity: Entity;
28+
let grandchild_entity: Entity;
29+
30+
class StartUpSystem extends System {
31+
commands = new Commands(this);
32+
33+
q = this.query(
34+
(q) => q.using(Parent, Children, Transform, GlobalTransform).write,
35+
);
36+
q2 = this.query((q) => q.current.with(Parent).read);
37+
38+
initialize(): void {
39+
const parent = this.commands.spawn(new Transform());
40+
const child = this.commands.spawn(new Transform());
41+
parent.addChild(child.id());
42+
43+
const grandchild = this.commands.spawn(new Transform());
44+
child.addChild(grandchild.id());
45+
46+
parent_entity = parent.id().hold();
47+
child_entity = child.id().hold();
48+
grandchild_entity = grandchild.id().hold();
49+
this.commands.execute();
50+
51+
parent_entity.write(Transform).scale.x = 2;
52+
child_entity.write(Transform).scale.x = 3;
53+
}
54+
55+
execute(): void {
56+
// expect(parent_entity?.read(Parent).children).toBe([child_entity]);
57+
}
58+
}
1659

1760
const app = new App({
1861
canvas: $canvas,
1962
})
20-
.addSystems(({ commands }) => {
21-
if (started) return;
22-
started = true;
23-
24-
const parent = commands.spawn(Transform);
25-
const child = commands.spawn(Transform);
26-
const grandChild = commands.spawn(Transform);
27-
parent.appendChild(child);
28-
child.appendChild(grandChild);
29-
30-
commands.execute();
31-
32-
parent.id().set(Transform, (transform) => {
33-
transform.position.set(100, 100);
34-
return transform;
35-
});
36-
37-
console.log(parent.id().get(Transform)?.worldTransform);
38-
console.log(child.id().get(Transform)?.worldTransform);
39-
console.log(grandChild.id().get(Transform)?.worldTransform);
40-
child.id().set(Transform, (transform) => {
41-
transform.position.set(200, 200);
42-
return transform;
43-
});
44-
45-
child.removeChild(grandChild);
46-
})
63+
.addPlugins(...DefaultPlugins)
64+
.addSystems(StartUp, StartUpSystem)
4765
.run();
4866

4967
// window.addEventListener('resize', () => {

packages/ecs/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@
3838
"dependencies": {
3939
"@antv/g-device-api": "^1.6.12",
4040
"@antv/util": "^3.3.10",
41+
"@lastolivegames/becsy": "^0.16.0",
4142
"@loaders.gl/core": "^4.2.2",
4243
"@loaders.gl/images": "^4.2.2",
4344
"@pixi/math": "^7.4.2",
4445
"bezier-easing": "^2.1.0",
4546
"bidi-js": "^1.0.3",
4647
"d3-color": "^3.1.0",
47-
"directed": "^0.1.6",
4848
"earcut": "^3.0.0",
4949
"eventemitter3": "^5.0.1",
5050
"gl-matrix": "^3.4.3",
51-
"koota": "^0.2.2",
5251
"libtess": "^1.2.2",
5352
"potpack": "^2.0.0",
5453
"rbush": "^3.0.1",

0 commit comments

Comments
 (0)