archetype-ecs 1.3.1 → 2.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.md +97 -11
- package/bench/allocations-1m.js +1 -1
- package/bench/multi-ecs-bench.js +1 -1
- package/bench/typed-vs-bitecs-1m.js +1 -1
- package/bench/typed-vs-untyped.js +81 -81
- package/bench/vs-bitecs.js +31 -56
- package/dist/src/ComponentRegistry.d.ts +13 -0
- package/dist/src/ComponentRegistry.js +29 -0
- package/dist/src/EntityManager.d.ts +52 -0
- package/dist/src/EntityManager.js +787 -0
- package/dist/src/Profiler.d.ts +12 -0
- package/dist/src/Profiler.js +38 -0
- package/dist/src/System.d.ts +37 -0
- package/dist/src/System.js +139 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +29 -0
- package/dist/tests/EntityManager.test.d.ts +1 -0
- package/dist/tests/EntityManager.test.js +499 -0
- package/dist/tests/System.test.d.ts +1 -0
- package/dist/tests/System.test.js +630 -0
- package/dist/tests/types.d.ts +1 -0
- package/dist/tests/types.js +129 -0
- package/package.json +8 -7
- package/src/ComponentRegistry.ts +45 -0
- package/src/EntityManager.ts +909 -0
- package/src/{Profiler.js → Profiler.ts} +18 -5
- package/src/System.ts +201 -0
- package/src/index.ts +38 -0
- package/tests/{EntityManager.test.js → EntityManager.test.ts} +182 -57
- package/tests/System.test.ts +546 -0
- package/tests/types.ts +69 -68
- package/tsconfig.json +8 -5
- package/src/ComponentRegistry.js +0 -21
- package/src/EntityManager.js +0 -578
- package/src/index.d.ts +0 -118
- package/src/index.js +0 -37
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ComponentDef } from './ComponentRegistry.js';
|
|
2
|
+
export type EntityId = number;
|
|
3
|
+
export interface FieldRef {
|
|
4
|
+
readonly _sym: symbol;
|
|
5
|
+
readonly _field: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ArchetypeView {
|
|
8
|
+
readonly id: number;
|
|
9
|
+
readonly entityIds: EntityId[];
|
|
10
|
+
readonly count: number;
|
|
11
|
+
readonly snapshotEntityIds: EntityId[] | null;
|
|
12
|
+
readonly snapshotCount: number;
|
|
13
|
+
field(ref: FieldRef): any;
|
|
14
|
+
fieldStride(ref: FieldRef): number;
|
|
15
|
+
snapshot(ref: FieldRef): any;
|
|
16
|
+
}
|
|
17
|
+
export interface SerializedData {
|
|
18
|
+
nextId: number;
|
|
19
|
+
entities: EntityId[];
|
|
20
|
+
components: Record<string, Record<string, unknown>>;
|
|
21
|
+
}
|
|
22
|
+
export interface EntityManager {
|
|
23
|
+
createEntity(): EntityId;
|
|
24
|
+
destroyEntity(id: EntityId): void;
|
|
25
|
+
addComponent(entityId: EntityId, type: ComponentDef, data?: any): void;
|
|
26
|
+
removeComponent(entityId: EntityId, type: ComponentDef): void;
|
|
27
|
+
getComponent(entityId: EntityId, type: ComponentDef): any;
|
|
28
|
+
get(entityId: EntityId, fieldRef: FieldRef): any;
|
|
29
|
+
set(entityId: EntityId, fieldRef: FieldRef, value: any): void;
|
|
30
|
+
hasComponent(entityId: EntityId, type: ComponentDef): boolean;
|
|
31
|
+
query(include: ComponentDef[], exclude?: ComponentDef[]): EntityId[];
|
|
32
|
+
getAllEntities(): EntityId[];
|
|
33
|
+
createEntityWith(...args: unknown[]): EntityId;
|
|
34
|
+
count(include: ComponentDef[], exclude?: ComponentDef[]): number;
|
|
35
|
+
forEach(include: ComponentDef[], callback: (view: ArchetypeView) => void, exclude?: ComponentDef[]): void;
|
|
36
|
+
onAdd(type: ComponentDef, callback: (entityId: EntityId) => void): () => void;
|
|
37
|
+
onRemove(type: ComponentDef, callback: (entityId: EntityId) => void): () => void;
|
|
38
|
+
flushHooks(): void;
|
|
39
|
+
enableTracking(filterComponent: ComponentDef): void;
|
|
40
|
+
flushChanges(): {
|
|
41
|
+
created: Set<EntityId>;
|
|
42
|
+
destroyed: Set<EntityId>;
|
|
43
|
+
};
|
|
44
|
+
flushSnapshots(): void;
|
|
45
|
+
serialize(symbolToName: Map<symbol, string>, stripComponents?: ComponentDef[], skipEntitiesWith?: ComponentDef[], options?: {
|
|
46
|
+
serializers?: Map<string, (data: unknown) => unknown>;
|
|
47
|
+
}): SerializedData;
|
|
48
|
+
deserialize(data: SerializedData, nameToSymbol: Record<string, ComponentDef>, options?: {
|
|
49
|
+
deserializers?: Map<string, (data: unknown) => unknown>;
|
|
50
|
+
}): void;
|
|
51
|
+
}
|
|
52
|
+
export declare function createEntityManager(): EntityManager;
|