archetype-ecs 1.3.1 → 1.3.2
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 +104 -34
- 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/ComponentRegistry.d.ts +18 -0
- package/dist/ComponentRegistry.js +29 -0
- package/dist/EntityManager.d.ts +52 -0
- package/dist/EntityManager.js +891 -0
- package/dist/Profiler.d.ts +12 -0
- package/dist/Profiler.js +38 -0
- package/dist/System.d.ts +41 -0
- package/dist/System.js +159 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +29 -0
- package/dist/src/ComponentRegistry.d.ts +18 -0
- package/dist/src/ComponentRegistry.js +29 -0
- package/dist/src/EntityManager.d.ts +49 -0
- package/dist/src/EntityManager.js +853 -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 +14 -0
- package/dist/src/index.js +29 -0
- package/dist/tests/EntityManager.test.d.ts +1 -0
- package/dist/tests/EntityManager.test.js +651 -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 +9 -7
- package/src/ComponentRegistry.ts +49 -0
- package/src/EntityManager.ts +1018 -0
- package/src/{Profiler.js → Profiler.ts} +18 -5
- package/src/System.ts +226 -0
- package/src/index.ts +44 -0
- package/tests/{EntityManager.test.js → EntityManager.test.ts} +338 -70
- package/tests/System.test.ts +730 -0
- package/tests/types.ts +67 -66
- package/tsconfig.json +8 -5
- package/tsconfig.test.json +13 -0
- 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,29 @@
|
|
|
1
|
+
export const TYPED = Symbol('typed');
|
|
2
|
+
export const TYPE_MAP = {
|
|
3
|
+
'f32': Float32Array,
|
|
4
|
+
'f64': Float64Array,
|
|
5
|
+
'i8': Int8Array,
|
|
6
|
+
'i16': Int16Array,
|
|
7
|
+
'i32': Int32Array,
|
|
8
|
+
'u8': Uint8Array,
|
|
9
|
+
'u16': Uint16Array,
|
|
10
|
+
'u32': Uint32Array,
|
|
11
|
+
'string': Array,
|
|
12
|
+
};
|
|
13
|
+
export function parseTypeSpec(typeStr) {
|
|
14
|
+
const match = typeStr.match(/^(\w+)\[(\d+)\]$/);
|
|
15
|
+
if (match) {
|
|
16
|
+
const Ctor = TYPE_MAP[match[1]];
|
|
17
|
+
if (!Ctor)
|
|
18
|
+
throw new Error(`Unknown base type "${match[1]}"`);
|
|
19
|
+
return [Ctor, parseInt(match[2])];
|
|
20
|
+
}
|
|
21
|
+
const Ctor = TYPE_MAP[typeStr];
|
|
22
|
+
if (!Ctor)
|
|
23
|
+
throw new Error(`Unknown type "${typeStr}"`);
|
|
24
|
+
return Ctor;
|
|
25
|
+
}
|
|
26
|
+
export const componentSchemas = new Map();
|
|
27
|
+
export function toSym(type) {
|
|
28
|
+
return type._sym || type;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ComponentDef, type FieldRef } from './ComponentRegistry.js';
|
|
2
|
+
export type { FieldRef } from './ComponentRegistry.js';
|
|
3
|
+
export type EntityId = number;
|
|
4
|
+
export type SoAArrayValue = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | unknown[];
|
|
5
|
+
export interface ArchetypeView {
|
|
6
|
+
readonly id: number;
|
|
7
|
+
readonly entityIds: EntityId[];
|
|
8
|
+
readonly count: number;
|
|
9
|
+
readonly snapshotEntityIds: EntityId[] | null;
|
|
10
|
+
readonly snapshotCount: number;
|
|
11
|
+
field(ref: FieldRef): SoAArrayValue | undefined;
|
|
12
|
+
fieldStride(ref: FieldRef): number;
|
|
13
|
+
snapshot(ref: FieldRef): SoAArrayValue | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface SerializedData {
|
|
16
|
+
nextId: number;
|
|
17
|
+
entities: EntityId[];
|
|
18
|
+
components: Record<string, Record<string, unknown>>;
|
|
19
|
+
}
|
|
20
|
+
export type ComponentData = Record<string, number | string | ArrayLike<number>> | null | undefined;
|
|
21
|
+
export interface EntityManager {
|
|
22
|
+
createEntity(): EntityId;
|
|
23
|
+
destroyEntity(id: EntityId): void;
|
|
24
|
+
addComponent(entityId: EntityId, type: ComponentDef, data?: ComponentData): void;
|
|
25
|
+
removeComponent(entityId: EntityId, type: ComponentDef): void;
|
|
26
|
+
getComponent(entityId: EntityId, type: ComponentDef): Record<string, number | string | number[]> | undefined;
|
|
27
|
+
get(entityId: EntityId, fieldRef: FieldRef): number | string | undefined;
|
|
28
|
+
set(entityId: EntityId, fieldRef: FieldRef, value: number | string | ArrayLike<number>): void;
|
|
29
|
+
hasComponent(entityId: EntityId, type: ComponentDef): boolean;
|
|
30
|
+
query(include: ComponentDef[], exclude?: ComponentDef[]): EntityId[];
|
|
31
|
+
getAllEntities(): EntityId[];
|
|
32
|
+
createEntityWith(...args: unknown[]): EntityId;
|
|
33
|
+
count(include: ComponentDef[], exclude?: ComponentDef[]): number;
|
|
34
|
+
forEach(include: ComponentDef[], callback: (view: ArchetypeView) => void, exclude?: ComponentDef[]): void;
|
|
35
|
+
onAdd(type: ComponentDef, callback: (entityId: EntityId) => void): () => void;
|
|
36
|
+
onRemove(type: ComponentDef, callback: (entityId: EntityId) => void): () => void;
|
|
37
|
+
flushHooks(): void;
|
|
38
|
+
commitRemovals(): 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;
|