@vworlds/vecs 1.0.0 → 1.0.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.
- package/dist/package.json +6 -2
- package/package.json +6 -2
- package/.claude/settings.json +0 -12
- package/.devcontainer/devcontainer.json +0 -22
- package/.github/workflows/publish.yml +0 -32
- package/src/component.ts +0 -180
- package/src/entity.ts +0 -276
- package/src/index.ts +0 -6
- package/src/phase.ts +0 -49
- package/src/system.ts +0 -693
- package/src/util/array_map.ts +0 -93
- package/src/util/bitset.ts +0 -199
- package/src/util/events.ts +0 -95
- package/src/util/ordered_set.ts +0 -82
- package/src/world.ts +0 -534
- package/tests/_helpers.ts +0 -30
- package/tests/array_map.test.ts +0 -68
- package/tests/bitset.test.ts +0 -127
- package/tests/component.test.ts +0 -104
- package/tests/entity.test.ts +0 -179
- package/tests/events.test.ts +0 -48
- package/tests/ordered_set.test.ts +0 -153
- package/tests/setup.ts +0 -6
- package/tests/system.test.ts +0 -800
- package/tests/world.test.ts +0 -174
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -9
package/tests/world.test.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { World, Component } from "../src/index.js";
|
|
3
|
-
|
|
4
|
-
class A extends Component {}
|
|
5
|
-
class B extends Component {}
|
|
6
|
-
|
|
7
|
-
describe("World — entity management", () => {
|
|
8
|
-
it("createEntity assigns sequential ids starting at 0", () => {
|
|
9
|
-
const w = new World();
|
|
10
|
-
const a = w.createEntity();
|
|
11
|
-
const b = w.createEntity();
|
|
12
|
-
expect(a.eid).toBe(0);
|
|
13
|
-
expect(b.eid).toBe(1);
|
|
14
|
-
expect(a.world).toBe(w);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("entity(id) returns the entity or undefined", () => {
|
|
18
|
-
const w = new World();
|
|
19
|
-
const e = w.createEntity();
|
|
20
|
-
expect(w.entity(e.eid)).toBe(e);
|
|
21
|
-
expect(w.entity(999)).toBeUndefined();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("getOrCreateEntity returns existing entity or creates a new one", () => {
|
|
25
|
-
const w = new World();
|
|
26
|
-
const a = w.getOrCreateEntity(42);
|
|
27
|
-
const b = w.getOrCreateEntity(42);
|
|
28
|
-
expect(a).toBe(b);
|
|
29
|
-
expect(a.eid).toBe(42);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("getOrCreateEntity invokes the create callback only on first creation", () => {
|
|
33
|
-
const w = new World();
|
|
34
|
-
let created = 0;
|
|
35
|
-
w.getOrCreateEntity(7, () => created++);
|
|
36
|
-
w.getOrCreateEntity(7, () => created++);
|
|
37
|
-
expect(created).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("setEntityIdRange shifts the auto-incrementing counter", () => {
|
|
41
|
-
const w = new World();
|
|
42
|
-
w.setEntityIdRange(1000);
|
|
43
|
-
expect(w.createEntity().eid).toBe(1000);
|
|
44
|
-
expect(w.createEntity().eid).toBe(1001);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("setEntityIdRange after start() throws", () => {
|
|
48
|
-
const w = new World();
|
|
49
|
-
w.start();
|
|
50
|
-
expect(() => w.setEntityIdRange(1000)).toThrow();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("setEntityIdRange before start() works even if components are registered", () => {
|
|
54
|
-
const w = new World();
|
|
55
|
-
w.registerComponent(A);
|
|
56
|
-
w.setEntityIdRange(500);
|
|
57
|
-
expect(w.createEntity().eid).toBe(500);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("clearAllEntities destroys every entity", () => {
|
|
61
|
-
const w = new World();
|
|
62
|
-
w.registerComponent(A);
|
|
63
|
-
const e1 = w.createEntity();
|
|
64
|
-
const e2 = w.createEntity();
|
|
65
|
-
e1.add(A);
|
|
66
|
-
e2.add(A);
|
|
67
|
-
w.clearAllEntities();
|
|
68
|
-
expect(w.entity(e1.eid)).toBeUndefined();
|
|
69
|
-
expect(w.entity(e2.eid)).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("World — component registration", () => {
|
|
74
|
-
it("auto-assigns local type ids starting at 256", () => {
|
|
75
|
-
const w = new World();
|
|
76
|
-
w.registerComponent(A);
|
|
77
|
-
expect(w.getComponentType(A)).toBe(256);
|
|
78
|
-
w.registerComponent(B);
|
|
79
|
-
expect(w.getComponentType(B)).toBe(257);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("accepts an explicit numeric type id", () => {
|
|
83
|
-
const w = new World();
|
|
84
|
-
w.registerComponent(A, 5);
|
|
85
|
-
expect(w.getComponentType(A)).toBe(5);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("accepts a custom display name", () => {
|
|
89
|
-
const w = new World();
|
|
90
|
-
w.registerComponent(A, "Apple");
|
|
91
|
-
expect(w.getComponentMeta(A).componentName).toBe("Apple");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("accepts both an explicit type id and a name", () => {
|
|
95
|
-
const w = new World();
|
|
96
|
-
w.registerComponent(A, 9, "Apple");
|
|
97
|
-
expect(w.getComponentType(A)).toBe(9);
|
|
98
|
-
expect(w.getComponentMeta(A).componentName).toBe("Apple");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("uses pre-registered name→type mapping when present", () => {
|
|
102
|
-
const w = new World();
|
|
103
|
-
w.registerComponentType("A", 10);
|
|
104
|
-
w.registerComponent(A);
|
|
105
|
-
expect(w.getComponentType(A)).toBe(10);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("throws when a class is registered twice", () => {
|
|
109
|
-
const w = new World();
|
|
110
|
-
w.registerComponent(A);
|
|
111
|
-
expect(() => w.registerComponent(A)).toThrow();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("registration is disabled after start()", () => {
|
|
115
|
-
const w = new World();
|
|
116
|
-
w.registerComponent(A);
|
|
117
|
-
w.start();
|
|
118
|
-
expect(() => w.registerComponent(B)).toThrow();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("disableComponentRegistration locks registration without starting", () => {
|
|
122
|
-
const w = new World();
|
|
123
|
-
w.registerComponent(A);
|
|
124
|
-
w.disableComponentRegistration();
|
|
125
|
-
expect(() => w.registerComponent(B)).toThrow();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("getComponentType passes through numeric ids unchanged", () => {
|
|
129
|
-
const w = new World();
|
|
130
|
-
w.registerComponent(A, 99);
|
|
131
|
-
expect(w.getComponentType(99)).toBe(99);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("getComponentMeta throws for an unknown type", () => {
|
|
135
|
-
const w = new World();
|
|
136
|
-
expect(() => w.getComponentMeta(A)).toThrow();
|
|
137
|
-
expect(() => w.getComponentMeta(123)).toThrow();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("World — phases", () => {
|
|
142
|
-
it("addPhase returns an IPhase keyed by name", () => {
|
|
143
|
-
const w = new World();
|
|
144
|
-
const p = w.addPhase("preupdate");
|
|
145
|
-
expect(p.name).toBe("preupdate");
|
|
146
|
-
expect(p.world).toBe(w);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("hook returns the same ComponentMeta object", () => {
|
|
150
|
-
const w = new World();
|
|
151
|
-
w.registerComponent(A);
|
|
152
|
-
const h1 = w.hook(A);
|
|
153
|
-
const h2 = w.hook(A);
|
|
154
|
-
expect(h1).toBe(h2);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("progress runs all phases in insertion order", () => {
|
|
158
|
-
const w = new World();
|
|
159
|
-
const order: string[] = [];
|
|
160
|
-
|
|
161
|
-
const pre = w.addPhase("pre");
|
|
162
|
-
const update = w.addPhase("update");
|
|
163
|
-
const post = w.addPhase("post");
|
|
164
|
-
|
|
165
|
-
w.system("s1").phase(pre).run(() => order.push("pre"));
|
|
166
|
-
w.system("s2").phase(update).run(() => order.push("update"));
|
|
167
|
-
w.system("s3").phase(post).run(() => order.push("post"));
|
|
168
|
-
|
|
169
|
-
w.start();
|
|
170
|
-
w.progress(0, 16);
|
|
171
|
-
|
|
172
|
-
expect(order).toEqual(["pre", "update", "post"]);
|
|
173
|
-
});
|
|
174
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"allowSyntheticDefaultImports": true,
|
|
5
|
-
"esModuleInterop": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"target": "ES2020",
|
|
10
|
-
"moduleResolution": "Node16",
|
|
11
|
-
"module": "ES2020",
|
|
12
|
-
"noImplicitOverride": true,
|
|
13
|
-
"composite": true,
|
|
14
|
-
"rootDir": "./src",
|
|
15
|
-
"outDir": "./dist",
|
|
16
|
-
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo",
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true
|
|
19
|
-
},
|
|
20
|
-
"include": ["src/**/*"]
|
|
21
|
-
}
|