@codehz/ecs 0.5.0 → 0.5.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 +57 -0
- package/{world.d.mts → builder.d.mts} +111 -444
- package/index.d.mts +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/testing.d.mts +2 -2
- package/testing.mjs +2 -2
- package/testing.mjs.map +1 -1
- package/world.mjs +1239 -1485
- package/world.mjs.map +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/entity.d.ts
|
|
1
|
+
//#region src/core/entity-types.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Unique symbol brand for associating component type information with EntityId
|
|
4
4
|
*/
|
|
@@ -23,17 +23,6 @@ type EntityRelationId<T = void> = EntityId<T, "entity-relation">;
|
|
|
23
23
|
type ComponentRelationId<T = void> = EntityId<T, "component-relation">;
|
|
24
24
|
type WildcardRelationId<T = void> = EntityId<T, "wildcard-relation">;
|
|
25
25
|
type RelationId<T = void> = EntityRelationId<T> | ComponentRelationId<T> | WildcardRelationId<T>;
|
|
26
|
-
/**
|
|
27
|
-
* Type for relation ID based on component and target types
|
|
28
|
-
*/
|
|
29
|
-
type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T> : R extends EntityId<any> ? EntityRelationId<T> : never;
|
|
30
|
-
/**
|
|
31
|
-
* Create a relation ID by associating a component with another ID (entity or component)
|
|
32
|
-
* @param componentId The component ID (0-1023)
|
|
33
|
-
* @param targetId The target ID (entity, component, or '*' for wildcard)
|
|
34
|
-
*/
|
|
35
|
-
declare function relation<T>(componentId: ComponentId<T>, targetId: "*"): WildcardRelationId<T>;
|
|
36
|
-
declare function relation<T, R extends EntityId<any>>(componentId: ComponentId<T>, targetId: R): RelationIdType<T, R>;
|
|
37
26
|
/**
|
|
38
27
|
* Check if an ID is a component ID
|
|
39
28
|
*/
|
|
@@ -46,6 +35,19 @@ declare function isEntityId<T>(id: EntityId<T>): id is EntityId<T>;
|
|
|
46
35
|
* Check if an ID is a relation ID
|
|
47
36
|
*/
|
|
48
37
|
declare function isRelationId<T>(id: EntityId<T>): id is RelationId<T>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/core/entity-relation.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Type for relation ID based on component and target types
|
|
42
|
+
*/
|
|
43
|
+
type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T> : R extends EntityId<any> ? EntityRelationId<T> : never;
|
|
44
|
+
/**
|
|
45
|
+
* Create a relation ID by associating a component with another ID (entity or component)
|
|
46
|
+
* @param componentId The component ID (0-1023)
|
|
47
|
+
* @param targetId The target ID (entity, component, or '*' for wildcard)
|
|
48
|
+
*/
|
|
49
|
+
declare function relation<T>(componentId: ComponentId<T>, targetId: "*"): WildcardRelationId<T>;
|
|
50
|
+
declare function relation<T, R extends EntityId<any>>(componentId: ComponentId<T>, targetId: R): RelationIdType<T, R>;
|
|
49
51
|
/**
|
|
50
52
|
* Check if an ID is a wildcard relation id
|
|
51
53
|
*/
|
|
@@ -60,6 +62,8 @@ declare function decodeRelationId(relationId: RelationId<any>): {
|
|
|
60
62
|
targetId: EntityId<any>;
|
|
61
63
|
type: "entity" | "component" | "wildcard";
|
|
62
64
|
};
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/core/component-registry.d.ts
|
|
63
67
|
/**
|
|
64
68
|
* Component options that define intrinsic properties
|
|
65
69
|
*/
|
|
@@ -117,7 +121,57 @@ declare function getComponentIdByName(name: string): ComponentId<any> | undefine
|
|
|
117
121
|
*/
|
|
118
122
|
declare function getComponentNameById(id: ComponentId<any>): string | undefined;
|
|
119
123
|
//#endregion
|
|
120
|
-
//#region src/
|
|
124
|
+
//#region src/commands/changeset.d.ts
|
|
125
|
+
/**
|
|
126
|
+
* @internal Represents a set of component changes to be applied to an entity
|
|
127
|
+
*/
|
|
128
|
+
declare class ComponentChangeset {
|
|
129
|
+
readonly adds: Map<EntityId<any>, any>;
|
|
130
|
+
readonly removes: Set<EntityId<any>>;
|
|
131
|
+
/**
|
|
132
|
+
* Add a component to the changeset
|
|
133
|
+
*/
|
|
134
|
+
set<T>(componentType: EntityId<T>, component: T): void;
|
|
135
|
+
/**
|
|
136
|
+
* Remove a component from the changeset
|
|
137
|
+
*/
|
|
138
|
+
delete<T>(componentType: EntityId<T>): void;
|
|
139
|
+
/**
|
|
140
|
+
* Check if the changeset has any changes
|
|
141
|
+
*/
|
|
142
|
+
hasChanges(): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Clear all changes
|
|
145
|
+
*/
|
|
146
|
+
clear(): void;
|
|
147
|
+
/**
|
|
148
|
+
* Merge another changeset into this one
|
|
149
|
+
*/
|
|
150
|
+
merge(other: ComponentChangeset): void;
|
|
151
|
+
/**
|
|
152
|
+
* Apply the changeset to existing components and return the final state
|
|
153
|
+
*/
|
|
154
|
+
applyTo(existingComponents: Map<EntityId<any>, any>): Map<EntityId<any>, any>;
|
|
155
|
+
/**
|
|
156
|
+
* Get the final component types after applying the changeset
|
|
157
|
+
* @param existingComponentTypes - The current component types on the entity
|
|
158
|
+
* @returns The final component types or undefined if no changes
|
|
159
|
+
*/
|
|
160
|
+
getFinalComponentTypes(existingComponentTypes: EntityId<any>[]): EntityId<any>[] | undefined;
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/commands/command-buffer.d.ts
|
|
164
|
+
/**
|
|
165
|
+
* Command for deferred execution
|
|
166
|
+
*/
|
|
167
|
+
interface Command {
|
|
168
|
+
type: "set" | "delete" | "destroy";
|
|
169
|
+
entityId: EntityId;
|
|
170
|
+
componentType?: EntityId<any>;
|
|
171
|
+
component?: any;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/core/types.d.ts
|
|
121
175
|
/**
|
|
122
176
|
* Hook types for component lifecycle events
|
|
123
177
|
*/
|
|
@@ -135,6 +189,11 @@ interface LifecycleHook<T = unknown> {
|
|
|
135
189
|
*/
|
|
136
190
|
on_remove?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
|
|
137
191
|
}
|
|
192
|
+
interface MultiLifecycleHook<T extends readonly ComponentType<any>[]> {
|
|
193
|
+
on_init?: (entityId: EntityId, componentTypes: T, components: ComponentTuple<T>) => void;
|
|
194
|
+
on_set?: (entityId: EntityId, componentTypes: T, components: ComponentTuple<T>) => void;
|
|
195
|
+
on_remove?: (entityId: EntityId, componentTypes: T, components: ComponentTuple<T>) => void;
|
|
196
|
+
}
|
|
138
197
|
type ComponentType<T> = EntityId<T> | OptionalEntityId<T>;
|
|
139
198
|
type OptionalEntityId<T> = {
|
|
140
199
|
optional: EntityId<T>;
|
|
@@ -149,7 +208,7 @@ type ComponentTypeToData<T> = T extends {
|
|
|
149
208
|
*/
|
|
150
209
|
type ComponentTuple<T extends readonly ComponentType<any>[]> = { readonly [K in keyof T]: ComponentTypeToData<T[K]> };
|
|
151
210
|
//#endregion
|
|
152
|
-
//#region src/archetype.d.ts
|
|
211
|
+
//#region src/core/archetype.d.ts
|
|
153
212
|
/**
|
|
154
213
|
* Archetype class for ECS architecture
|
|
155
214
|
* Represents a group of entities that share the same set of components
|
|
@@ -181,224 +240,46 @@ declare class Archetype {
|
|
|
181
240
|
private dontFragmentRelations;
|
|
182
241
|
/**
|
|
183
242
|
* Cache for pre-computed component data sources to avoid repeated calculations
|
|
184
|
-
* For regular components: data array
|
|
185
|
-
* For wildcards: matching relation types array
|
|
186
243
|
*/
|
|
187
244
|
private componentDataSourcesCache;
|
|
188
|
-
/**
|
|
189
|
-
* Create a new archetype with the specified component types
|
|
190
|
-
* @param componentTypes The component types that define this archetype
|
|
191
|
-
* @param dontFragmentRelations Reference to the World's dontFragmentRelations storage
|
|
192
|
-
*/
|
|
193
245
|
constructor(componentTypes: EntityId<any>[], dontFragmentRelations: Map<EntityId, Map<EntityId<any>, any>>);
|
|
194
|
-
/**
|
|
195
|
-
* Get the number of entities in this archetype
|
|
196
|
-
*/
|
|
197
246
|
get size(): number;
|
|
198
|
-
/**
|
|
199
|
-
* Check if this archetype matches the given component types
|
|
200
|
-
* @param componentTypes The component types to check
|
|
201
|
-
*/
|
|
202
247
|
matches(componentTypes: EntityId<any>[]): boolean;
|
|
203
|
-
/**
|
|
204
|
-
* Add an entity to this archetype with initial component data
|
|
205
|
-
* @param entityId The entity to add
|
|
206
|
-
* @param componentData Map of component type to component data (includes both regular and dontFragment components)
|
|
207
|
-
*/
|
|
208
248
|
addEntity(entityId: EntityId, componentData: Map<EntityId<any>, any>): void;
|
|
209
|
-
|
|
210
|
-
* Get all component data for a specific entity
|
|
211
|
-
* @param entityId The entity to get data for
|
|
212
|
-
* @returns Map of component type to component data (includes both regular and dontFragment components)
|
|
213
|
-
*/
|
|
249
|
+
private addDontFragmentRelations;
|
|
214
250
|
getEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
|
|
215
|
-
/**
|
|
216
|
-
* Dump all entities and their component data in this archetype
|
|
217
|
-
* @returns Array of objects with entity and component data (includes both regular and dontFragment components)
|
|
218
|
-
*/
|
|
219
251
|
dump(): Array<{
|
|
220
252
|
entity: EntityId;
|
|
221
253
|
components: Map<EntityId<any>, any>;
|
|
222
254
|
}>;
|
|
223
|
-
/**
|
|
224
|
-
* Remove an entity from this archetype
|
|
225
|
-
* @param entityId The entity to remove
|
|
226
|
-
* @returns The component data of the removed entity (includes both regular and dontFragment components)
|
|
227
|
-
*/
|
|
228
255
|
removeEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
|
|
229
|
-
/**
|
|
230
|
-
* Check if an entity is in this archetype
|
|
231
|
-
* @param entityId The entity to check
|
|
232
|
-
*/
|
|
233
256
|
exists(entityId: EntityId): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Get component data for a specific entity and wildcard relation type
|
|
236
|
-
* Returns an array of all matching relation instances
|
|
237
|
-
* @param entityId The entity
|
|
238
|
-
* @param componentType The wildcard relation type
|
|
239
|
-
*/
|
|
240
257
|
get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, any][];
|
|
241
|
-
/**
|
|
242
|
-
* Get component data for a specific entity and component type
|
|
243
|
-
* @param entityId The entity
|
|
244
|
-
* @param componentType The component type
|
|
245
|
-
*/
|
|
246
258
|
get<T>(entityId: EntityId, componentType: EntityId<T>): T;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
* @param entityId The entity
|
|
250
|
-
* @param componentType The component type
|
|
251
|
-
* @returns { value: T } if component exists, undefined otherwise
|
|
252
|
-
*/
|
|
259
|
+
private getWildcardRelations;
|
|
260
|
+
private getRegularComponent;
|
|
253
261
|
getOptional<T>(entityId: EntityId, componentType: EntityId<T>): {
|
|
254
262
|
value: T;
|
|
255
263
|
} | undefined;
|
|
256
|
-
/**
|
|
257
|
-
* Set component data for a specific entity and component type
|
|
258
|
-
* @param entityId The entity
|
|
259
|
-
* @param componentType The component type
|
|
260
|
-
* @param data The component data
|
|
261
|
-
*/
|
|
262
264
|
set<T>(entityId: EntityId, componentType: EntityId<T>, data: T): void;
|
|
263
|
-
/**
|
|
264
|
-
* Get all entities in this archetype
|
|
265
|
-
*/
|
|
266
265
|
getEntities(): EntityId[];
|
|
267
|
-
/**
|
|
268
|
-
* Get the mapping of entities to their indices in this archetype
|
|
269
|
-
*/
|
|
270
266
|
getEntityToIndexMap(): Map<EntityId, number>;
|
|
271
|
-
/**
|
|
272
|
-
* Get component data for all entities of a specific component type
|
|
273
|
-
* @param componentType The component type
|
|
274
|
-
*/
|
|
275
267
|
getComponentData<T>(componentType: EntityId<T>): T[];
|
|
276
|
-
/**
|
|
277
|
-
* Get optional component data for all entities of a specific component type
|
|
278
|
-
* @param componentType The component type
|
|
279
|
-
* @returns An array of component data or undefined if not present
|
|
280
|
-
*/
|
|
281
268
|
getOptionalComponentData<T>(componentType: EntityId<T>): T[] | undefined;
|
|
282
|
-
/**
|
|
283
|
-
* Helper: compute or return cached data sources for provided componentTypes
|
|
284
|
-
*/
|
|
285
269
|
private getCachedComponentDataSources;
|
|
286
|
-
/**
|
|
287
|
-
* Build cache key for component types
|
|
288
|
-
*/
|
|
289
|
-
private buildCacheKey;
|
|
290
|
-
/**
|
|
291
|
-
* Get data source for a single component type
|
|
292
|
-
*/
|
|
293
270
|
private getComponentDataSource;
|
|
294
|
-
/**
|
|
295
|
-
* Get data source for wildcard relations
|
|
296
|
-
*/
|
|
297
|
-
private getWildcardRelationDataSource;
|
|
298
|
-
/**
|
|
299
|
-
* Helper: build component tuples for a specific entity index using precomputed data sources
|
|
300
|
-
*/
|
|
301
271
|
private buildComponentsForIndex;
|
|
302
|
-
/**
|
|
303
|
-
* Build a single component value from its data source
|
|
304
|
-
*/
|
|
305
|
-
private buildSingleComponent;
|
|
306
|
-
/**
|
|
307
|
-
* Build wildcard relation value from matching relations
|
|
308
|
-
*/
|
|
309
|
-
private buildWildcardRelationValue;
|
|
310
|
-
/**
|
|
311
|
-
* Build regular component value from data source
|
|
312
|
-
*/
|
|
313
|
-
private buildRegularComponentValue;
|
|
314
|
-
/**
|
|
315
|
-
* Get entities with their component data for specified component types
|
|
316
|
-
* Optimized for bulk component access with pre-computed indices
|
|
317
|
-
* @param componentTypes Array of component types to retrieve
|
|
318
|
-
* @returns Array of objects with entity and component data
|
|
319
|
-
*/
|
|
320
272
|
getEntitiesWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): Array<{
|
|
321
273
|
entity: EntityId;
|
|
322
274
|
components: ComponentTuple<T>;
|
|
323
275
|
}>;
|
|
324
|
-
/**
|
|
325
|
-
* Iterate over entities with their component data for specified component types
|
|
326
|
-
* implemented as a generator returning each entity/components pair lazily
|
|
327
|
-
* @param componentTypes Array of component types to retrieve
|
|
328
|
-
*/
|
|
329
276
|
iterateWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): IterableIterator<[EntityId, ...ComponentTuple<T>]>;
|
|
330
|
-
/**
|
|
331
|
-
* Iterate over entities with their component data for specified component types
|
|
332
|
-
* Optimized for bulk component access
|
|
333
|
-
* @param componentTypes Array of component types to retrieve
|
|
334
|
-
* @param callback Function called for each entity with its components
|
|
335
|
-
*/
|
|
336
277
|
forEachWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T, callback: (entity: EntityId, ...components: ComponentTuple<T>) => void): void;
|
|
337
|
-
/**
|
|
338
|
-
* Iterate over all entities with their component data
|
|
339
|
-
* @param callback Function called for each entity with its component data
|
|
340
|
-
*/
|
|
341
278
|
forEach(callback: (entityId: EntityId, components: Map<EntityId<any>, any>) => void): void;
|
|
342
|
-
/**
|
|
343
|
-
* Check if any entity in this archetype has a relation matching the given component ID
|
|
344
|
-
* This includes both regular relations in componentTypes and dontFragment relations
|
|
345
|
-
* @param componentId The component ID to match
|
|
346
|
-
* @returns true if any entity has a matching relation
|
|
347
|
-
*/
|
|
348
279
|
hasRelationWithComponentId(componentId: EntityId<any>): boolean;
|
|
349
280
|
}
|
|
350
281
|
//#endregion
|
|
351
|
-
//#region src/
|
|
352
|
-
/**
|
|
353
|
-
* @internal Represents a set of component changes to be applied to an entity
|
|
354
|
-
*/
|
|
355
|
-
declare class ComponentChangeset {
|
|
356
|
-
readonly adds: Map<EntityId<any>, any>;
|
|
357
|
-
readonly removes: Set<EntityId<any>>;
|
|
358
|
-
/**
|
|
359
|
-
* Add a component to the changeset
|
|
360
|
-
*/
|
|
361
|
-
set<T>(componentType: EntityId<T>, component: T): void;
|
|
362
|
-
/**
|
|
363
|
-
* Remove a component from the changeset
|
|
364
|
-
*/
|
|
365
|
-
delete<T>(componentType: EntityId<T>): void;
|
|
366
|
-
/**
|
|
367
|
-
* Check if the changeset has any changes
|
|
368
|
-
*/
|
|
369
|
-
hasChanges(): boolean;
|
|
370
|
-
/**
|
|
371
|
-
* Clear all changes
|
|
372
|
-
*/
|
|
373
|
-
clear(): void;
|
|
374
|
-
/**
|
|
375
|
-
* Merge another changeset into this one
|
|
376
|
-
*/
|
|
377
|
-
merge(other: ComponentChangeset): void;
|
|
378
|
-
/**
|
|
379
|
-
* Apply the changeset to existing components and return the final state
|
|
380
|
-
*/
|
|
381
|
-
applyTo(existingComponents: Map<EntityId<any>, any>): Map<EntityId<any>, any>;
|
|
382
|
-
/**
|
|
383
|
-
* Get the final component types after applying the changeset
|
|
384
|
-
* @param existingComponentTypes - The current component types on the entity
|
|
385
|
-
* @returns The final component types or undefined if no changes
|
|
386
|
-
*/
|
|
387
|
-
getFinalComponentTypes(existingComponentTypes: EntityId<any>[]): EntityId<any>[] | undefined;
|
|
388
|
-
}
|
|
389
|
-
//#endregion
|
|
390
|
-
//#region src/command-buffer.d.ts
|
|
391
|
-
/**
|
|
392
|
-
* Command for deferred execution
|
|
393
|
-
*/
|
|
394
|
-
interface Command {
|
|
395
|
-
type: "set" | "delete" | "destroy";
|
|
396
|
-
entityId: EntityId;
|
|
397
|
-
componentType?: EntityId<any>;
|
|
398
|
-
component?: any;
|
|
399
|
-
}
|
|
400
|
-
//#endregion
|
|
401
|
-
//#region src/query-filter.d.ts
|
|
282
|
+
//#region src/query/filter.d.ts
|
|
402
283
|
/**
|
|
403
284
|
* Filter options for queries
|
|
404
285
|
*/
|
|
@@ -406,7 +287,7 @@ interface QueryFilter {
|
|
|
406
287
|
negativeComponentTypes?: EntityId<any>[];
|
|
407
288
|
}
|
|
408
289
|
//#endregion
|
|
409
|
-
//#region src/query.d.ts
|
|
290
|
+
//#region src/query/query.d.ts
|
|
410
291
|
/**
|
|
411
292
|
* Query class for efficient entity queries with cached archetypes
|
|
412
293
|
*/
|
|
@@ -416,6 +297,8 @@ declare class Query {
|
|
|
416
297
|
private filter;
|
|
417
298
|
private cachedArchetypes;
|
|
418
299
|
private isDisposed;
|
|
300
|
+
/** Cached wildcard component types for faster entity filtering */
|
|
301
|
+
private wildcardTypes;
|
|
419
302
|
constructor(world: World, componentTypes: EntityId<any>[], filter?: QueryFilter);
|
|
420
303
|
/**
|
|
421
304
|
* Check if query is disposed and throw error if so
|
|
@@ -425,6 +308,10 @@ declare class Query {
|
|
|
425
308
|
* Get all entities matching the query
|
|
426
309
|
*/
|
|
427
310
|
getEntities(): EntityId[];
|
|
311
|
+
/**
|
|
312
|
+
* Check if entity has all required wildcard relations
|
|
313
|
+
*/
|
|
314
|
+
private entityHasAllWildcards;
|
|
428
315
|
/**
|
|
429
316
|
* Get entities with their component data
|
|
430
317
|
* @param componentTypes Array of component types to retrieve
|
|
@@ -464,9 +351,6 @@ declare class Query {
|
|
|
464
351
|
* Remove an archetype from the cached archetypes
|
|
465
352
|
*/
|
|
466
353
|
removeArchetype(archetype: Archetype): void;
|
|
467
|
-
/**
|
|
468
|
-
* Dispose the query and disconnect from world
|
|
469
|
-
*/
|
|
470
354
|
/**
|
|
471
355
|
* Request disposal of this query.
|
|
472
356
|
* This will decrement the world's reference count for the query.
|
|
@@ -487,307 +371,90 @@ declare class Query {
|
|
|
487
371
|
get disposed(): boolean;
|
|
488
372
|
}
|
|
489
373
|
//#endregion
|
|
490
|
-
//#region src/
|
|
374
|
+
//#region src/core/serialization.d.ts
|
|
491
375
|
type SerializedEntityId = number | string | {
|
|
492
376
|
component: string;
|
|
493
377
|
target: number | string | "*";
|
|
494
378
|
};
|
|
379
|
+
type SerializedWorld = {
|
|
380
|
+
version: number;
|
|
381
|
+
entityManager: any;
|
|
382
|
+
entities: SerializedEntity[];
|
|
383
|
+
};
|
|
384
|
+
type SerializedEntity = {
|
|
385
|
+
id: SerializedEntityId;
|
|
386
|
+
components: SerializedComponent[];
|
|
387
|
+
};
|
|
388
|
+
type SerializedComponent = {
|
|
389
|
+
type: SerializedEntityId;
|
|
390
|
+
value: any;
|
|
391
|
+
};
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/core/world.d.ts
|
|
495
394
|
/**
|
|
496
395
|
* World class for ECS architecture
|
|
497
396
|
* Manages entities and components
|
|
498
397
|
*/
|
|
499
398
|
declare class World {
|
|
500
|
-
/** Manages allocation and deallocation of entity IDs */
|
|
501
399
|
private entityIdManager;
|
|
502
|
-
/** Array of all archetypes in the world */
|
|
503
400
|
private archetypes;
|
|
504
|
-
/** Maps archetype signatures (component type signatures) to archetype instances */
|
|
505
401
|
private archetypeBySignature;
|
|
506
|
-
/** Maps entity IDs to their current archetype */
|
|
507
402
|
private entityToArchetype;
|
|
508
|
-
/** Maps component types to arrays of archetypes that contain them */
|
|
509
403
|
private archetypesByComponent;
|
|
510
|
-
/** Tracks which entities reference each entity as a component type */
|
|
511
404
|
private entityReferences;
|
|
512
|
-
/** Storage for dontFragment relations - maps entity ID to a map of relation type to component data */
|
|
513
405
|
private dontFragmentRelations;
|
|
514
|
-
/** Array of all active queries for archetype change notifications */
|
|
515
406
|
private queries;
|
|
516
|
-
/** Cache for queries keyed by component types and filter signatures */
|
|
517
407
|
private queryCache;
|
|
518
|
-
/** Buffers structural changes for deferred execution */
|
|
519
408
|
private commandBuffer;
|
|
520
|
-
/** Stores lifecycle hooks for component and relation events */
|
|
521
409
|
private hooks;
|
|
522
|
-
|
|
523
|
-
* Create a new World.
|
|
524
|
-
* If an optional snapshot object is provided (previously produced by `world.serialize()`),
|
|
525
|
-
* the world will be restored from that snapshot. The snapshot may contain non-JSON values.
|
|
526
|
-
*/
|
|
410
|
+
private multiHooks;
|
|
527
411
|
constructor(snapshot?: SerializedWorld);
|
|
528
|
-
|
|
529
|
-
* Generate a signature string for component types array
|
|
530
|
-
* @returns A string signature for the component types
|
|
531
|
-
*/
|
|
412
|
+
private deserializeSnapshot;
|
|
532
413
|
private createArchetypeSignature;
|
|
533
|
-
/**
|
|
534
|
-
* Create a new entity
|
|
535
|
-
* @returns The ID of the newly created entity
|
|
536
|
-
*/
|
|
537
414
|
new<T = void>(): EntityId<T>;
|
|
538
|
-
/**
|
|
539
|
-
* Destroy an entity and remove all its components (immediate execution)
|
|
540
|
-
*/
|
|
541
415
|
private destroyEntityImmediate;
|
|
542
|
-
/**
|
|
543
|
-
* Check if an entity exists
|
|
544
|
-
*/
|
|
545
416
|
exists(entityId: EntityId): boolean;
|
|
546
|
-
/**
|
|
547
|
-
* Add a component to an entity (deferred)
|
|
548
|
-
*/
|
|
549
417
|
set(entityId: EntityId, componentType: EntityId<void>): void;
|
|
550
418
|
set<T>(entityId: EntityId, componentType: EntityId<T>, component: NoInfer<T>): void;
|
|
551
|
-
/**
|
|
552
|
-
* Remove a component from an entity (deferred)
|
|
553
|
-
*/
|
|
554
419
|
remove<T>(entityId: EntityId, componentType: EntityId<T>): void;
|
|
555
|
-
/**
|
|
556
|
-
* Destroy an entity and remove all its components (deferred)
|
|
557
|
-
*/
|
|
558
420
|
delete(entityId: EntityId): void;
|
|
559
|
-
/**
|
|
560
|
-
* Check if an entity has a specific component
|
|
561
|
-
*/
|
|
562
421
|
has<T>(entityId: EntityId, componentType: EntityId<T>): boolean;
|
|
563
|
-
/**
|
|
564
|
-
* Get component data for a specific entity and wildcard relation type
|
|
565
|
-
* Returns an array of all matching relation instances
|
|
566
|
-
* @param entityId The entity
|
|
567
|
-
* @param componentType The wildcard relation type
|
|
568
|
-
* @returns Array of [targetEntityId, componentData] pairs for all matching relations
|
|
569
|
-
*/
|
|
570
422
|
get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, T][];
|
|
571
|
-
/**
|
|
572
|
-
* Get component data for a specific entity and component type
|
|
573
|
-
* @param entityId The entity
|
|
574
|
-
* @param componentType The component type
|
|
575
|
-
* @returns The component data
|
|
576
|
-
*/
|
|
577
423
|
get<T>(entityId: EntityId, componentType: EntityId<T>): T;
|
|
578
|
-
/**
|
|
579
|
-
* Get optional component data for a specific entity and component type
|
|
580
|
-
* @param entityId The entity
|
|
581
|
-
* @param componentType The component type
|
|
582
|
-
* @returns { value: T } if component exists, undefined otherwise
|
|
583
|
-
*/
|
|
584
424
|
getOptional<T>(entityId: EntityId, componentType: EntityId<T>): {
|
|
585
425
|
value: T;
|
|
586
426
|
} | undefined;
|
|
587
|
-
/**
|
|
588
|
-
* Register a lifecycle hook for component or wildcard relation events
|
|
589
|
-
*/
|
|
590
427
|
hook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
|
|
591
|
-
|
|
592
|
-
* Unregister a lifecycle hook for component or wildcard relation events
|
|
593
|
-
*/
|
|
428
|
+
hook<const T extends readonly ComponentType<any>[]>(componentTypes: T, hook: MultiLifecycleHook<T>): void;
|
|
594
429
|
unhook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
|
|
595
|
-
|
|
596
|
-
* Execute all deferred commands immediately
|
|
597
|
-
*/
|
|
430
|
+
unhook<const T extends readonly ComponentType<any>[]>(componentTypes: T, hook: MultiLifecycleHook<T>): void;
|
|
598
431
|
sync(): void;
|
|
599
|
-
/**
|
|
600
|
-
* Create a cached query for efficient entity lookups
|
|
601
|
-
* @returns A Query object for the specified component types and filter
|
|
602
|
-
*/
|
|
603
432
|
createQuery(componentTypes: EntityId<any>[], filter?: QueryFilter): Query;
|
|
604
|
-
/**
|
|
605
|
-
* Create an EntityBuilder for convenient entity creation.
|
|
606
|
-
* @returns EntityBuilder
|
|
607
|
-
*/
|
|
608
433
|
spawn(): EntityBuilder;
|
|
609
|
-
/**
|
|
610
|
-
* Spawn multiple entities using an EntityBuilder configuration callback
|
|
611
|
-
* @param count number of entities
|
|
612
|
-
* @param configure builder configuration callback
|
|
613
|
-
* @returns Created entity IDs
|
|
614
|
-
*/
|
|
615
434
|
spawnMany(count: number, configure: (builder: EntityBuilder, index: number) => EntityBuilder): EntityId[];
|
|
616
|
-
/**
|
|
617
|
-
* @internal Register a query for archetype update notifications
|
|
618
|
-
*/
|
|
619
435
|
_registerQuery(query: Query): void;
|
|
620
|
-
/**
|
|
621
|
-
* @internal Unregister a query
|
|
622
|
-
*/
|
|
623
436
|
_unregisterQuery(query: Query): void;
|
|
624
|
-
/**
|
|
625
|
-
* Release a query reference obtained from createQuery.
|
|
626
|
-
* Decrements the refCount and fully disposes the query when it reaches zero.
|
|
627
|
-
*/
|
|
628
437
|
releaseQuery(query: Query): void;
|
|
629
|
-
/**
|
|
630
|
-
* @internal Get archetypes that match specific component types (for internal use by queries)
|
|
631
|
-
*/
|
|
632
438
|
getMatchingArchetypes(componentTypes: EntityId<any>[]): Archetype[];
|
|
633
|
-
|
|
634
|
-
* Query entities with specific components
|
|
635
|
-
* @returns Array of entity IDs that have all the specified components
|
|
636
|
-
*/
|
|
439
|
+
private getArchetypesWithComponents;
|
|
637
440
|
query(componentTypes: EntityId<any>[]): EntityId[];
|
|
638
441
|
query<const T extends readonly EntityId<any>[]>(componentTypes: T, includeComponents: true): Array<{
|
|
639
442
|
entity: EntityId;
|
|
640
443
|
components: ComponentTuple<T>;
|
|
641
444
|
}>;
|
|
642
|
-
/**
|
|
643
|
-
* @internal Execute commands for a single entity (for internal use by CommandBuffer)
|
|
644
|
-
* @returns ComponentChangeset describing the changes made
|
|
645
|
-
*/
|
|
646
445
|
executeEntityCommands(entityId: EntityId, commands: Command[]): ComponentChangeset;
|
|
647
|
-
|
|
648
|
-
* Process commands and populate the changeset
|
|
649
|
-
*/
|
|
650
|
-
private processCommands;
|
|
651
|
-
/**
|
|
652
|
-
* Process a set command, handling exclusive relations
|
|
653
|
-
*/
|
|
654
|
-
private processSetCommand;
|
|
655
|
-
/**
|
|
656
|
-
* Remove all relations with the same base component (for exclusive relations)
|
|
657
|
-
*/
|
|
658
|
-
private removeExclusiveRelations;
|
|
659
|
-
private isRelationWithComponent;
|
|
660
|
-
/**
|
|
661
|
-
* Process a delete command, handling wildcard relations
|
|
662
|
-
*/
|
|
663
|
-
private processDeleteCommand;
|
|
664
|
-
/**
|
|
665
|
-
* Remove all relations matching a wildcard component ID
|
|
666
|
-
*/
|
|
667
|
-
private removeWildcardRelations;
|
|
668
|
-
/**
|
|
669
|
-
* Remove a single component from an entity immediately, handling dontFragment relations correctly.
|
|
670
|
-
* Used by destroyEntityImmediate for non-cascade relation cleanup.
|
|
671
|
-
*/
|
|
446
|
+
private createHooksContext;
|
|
672
447
|
private removeComponentImmediate;
|
|
673
|
-
/**
|
|
674
|
-
* Apply changeset to entity, moving to new archetype if needed
|
|
675
|
-
* @returns Map of removed components with their data
|
|
676
|
-
*/
|
|
677
|
-
private applyChangeset;
|
|
678
|
-
/**
|
|
679
|
-
* Move entity to a new archetype with updated components
|
|
680
|
-
*/
|
|
681
|
-
private moveEntityToNewArchetype;
|
|
682
|
-
/**
|
|
683
|
-
* Update entity in same archetype (no archetype change needed)
|
|
684
|
-
*/
|
|
685
|
-
private updateEntityInSameArchetype;
|
|
686
|
-
/**
|
|
687
|
-
* Apply dontFragment relation changes directly to World's storage
|
|
688
|
-
* This is much more efficient than the removeEntity + addEntity approach
|
|
689
|
-
*/
|
|
690
|
-
private applyDontFragmentChanges;
|
|
691
|
-
/**
|
|
692
|
-
* Update entity reference tracking based on changeset
|
|
693
|
-
*/
|
|
694
448
|
private updateEntityReferences;
|
|
695
|
-
/**
|
|
696
|
-
* Get or create an archetype for the given component types
|
|
697
|
-
* Filters out dontFragment relations from the archetype signature
|
|
698
|
-
* @returns The archetype for the given component types (excluding dontFragment relations)
|
|
699
|
-
*/
|
|
700
449
|
private ensureArchetype;
|
|
701
|
-
/**
|
|
702
|
-
* Compare two arrays of component types for equality (order-independent)
|
|
703
|
-
*/
|
|
704
|
-
private areComponentTypesEqual;
|
|
705
|
-
/**
|
|
706
|
-
* Filter out dontFragment relations from component types, but keep wildcard markers
|
|
707
|
-
*/
|
|
708
|
-
private filterRegularComponentTypes;
|
|
709
|
-
/**
|
|
710
|
-
* Create a new archetype and register it with all tracking structures
|
|
711
|
-
*/
|
|
712
450
|
private createNewArchetype;
|
|
713
|
-
/**
|
|
714
|
-
* Register archetype in the component-to-archetype index
|
|
715
|
-
*/
|
|
716
|
-
private registerArchetypeInComponentIndex;
|
|
717
|
-
/**
|
|
718
|
-
* Notify all queries to check the new archetype
|
|
719
|
-
*/
|
|
720
|
-
private notifyQueriesOfNewArchetype;
|
|
721
|
-
/**
|
|
722
|
-
* Add a component reference to the reverse index when an entity is used as a component type
|
|
723
|
-
* @param sourceEntityId The entity that has the component
|
|
724
|
-
* @param componentType The component type (which may be an entity ID used as component type)
|
|
725
|
-
* @param targetEntityId The entity being used as component type
|
|
726
|
-
*/
|
|
727
|
-
private trackEntityReference;
|
|
728
|
-
/**
|
|
729
|
-
* Remove a component reference from the reverse index
|
|
730
|
-
* @param sourceEntityId The entity that has the component
|
|
731
|
-
* @param componentType The component type
|
|
732
|
-
* @param targetEntityId The entity being used as component type
|
|
733
|
-
*/
|
|
734
|
-
private untrackEntityReference;
|
|
735
|
-
/**
|
|
736
|
-
* Get all component references where a target entity is used as a component type
|
|
737
|
-
* @param targetEntityId The target entity
|
|
738
|
-
* @returns A MultiMap of sourceEntityId to componentTypes that reference the target entity
|
|
739
|
-
*/
|
|
740
|
-
private getEntityReferences;
|
|
741
|
-
/**
|
|
742
|
-
* Check if an archetype's signature references a specific entity
|
|
743
|
-
* (via entity-relation targeting the entity, or using entity as component type)
|
|
744
|
-
*/
|
|
745
451
|
private archetypeReferencesEntity;
|
|
746
|
-
/**
|
|
747
|
-
* Cleanup empty archetypes that reference a specific deleted entity
|
|
748
|
-
* Only removes archetypes whose component types reference the entity
|
|
749
|
-
*/
|
|
750
452
|
private cleanupArchetypesReferencingEntity;
|
|
751
|
-
|
|
752
|
-
* Remove archetype from the main archetypes list
|
|
753
|
-
*/
|
|
754
|
-
private removeArchetypeFromList;
|
|
755
|
-
/**
|
|
756
|
-
* Remove archetype from the signature-to-archetype map
|
|
757
|
-
*/
|
|
758
|
-
private removeArchetypeFromSignatureMap;
|
|
759
|
-
/**
|
|
760
|
-
* Remove archetype from the component-to-archetypes index
|
|
761
|
-
*/
|
|
762
|
-
private removeArchetypeFromComponentIndex;
|
|
763
|
-
/**
|
|
764
|
-
* Remove archetype from all queries
|
|
765
|
-
*/
|
|
766
|
-
private removeArchetypeFromQueries;
|
|
767
|
-
/**
|
|
768
|
-
* Execute component lifecycle hooks for added and removed components
|
|
769
|
-
*/
|
|
770
|
-
private triggerLifecycleHooks;
|
|
771
|
-
/**
|
|
772
|
-
* Convert the world into a plain snapshot object.
|
|
773
|
-
* This returns an in-memory structure and does not perform JSON stringification.
|
|
774
|
-
* Component values are stored as-is (they may be non-JSON-serializable).
|
|
775
|
-
*/
|
|
453
|
+
private removeArchetype;
|
|
776
454
|
serialize(): SerializedWorld;
|
|
777
455
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
entityManager: any;
|
|
781
|
-
entities: SerializedEntity[];
|
|
782
|
-
};
|
|
783
|
-
type SerializedEntity = {
|
|
784
|
-
id: SerializedEntityId;
|
|
785
|
-
components: SerializedComponent[];
|
|
786
|
-
};
|
|
787
|
-
type SerializedComponent = {
|
|
788
|
-
type: SerializedEntityId;
|
|
789
|
-
value: any;
|
|
790
|
-
};
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/core/builder.d.ts
|
|
791
458
|
/**
|
|
792
459
|
* A component definition for entity building, supporting both regular components and relations
|
|
793
460
|
*/
|
|
@@ -818,5 +485,5 @@ declare class EntityBuilder {
|
|
|
818
485
|
build(): EntityId;
|
|
819
486
|
}
|
|
820
487
|
//#endregion
|
|
821
|
-
export {
|
|
822
|
-
//# sourceMappingURL=
|
|
488
|
+
export { RelationId as C, isRelationId as D, isEntityId as E, EntityRelationId as S, isComponentId as T, isWildcardRelationId as _, SerializedEntity as a, ComponentRelationId as b, Query as c, LifecycleHook as d, ComponentOptions as f, decodeRelationId as g, getComponentNameById as h, SerializedComponent as i, ComponentTuple as l, getComponentIdByName as m, EntityBuilder as n, SerializedEntityId as o, component as p, World as r, SerializedWorld as s, ComponentDef as t, ComponentType as u, relation as v, WildcardRelationId as w, EntityId as x, ComponentId as y };
|
|
489
|
+
//# sourceMappingURL=builder.d.mts.map
|