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