@oasys/oecs 0.3.1 → 0.5.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/CHANGELOG.md +553 -0
- package/README.md +207 -267
- package/dist/core/ecs/access_check.d.cts +77 -0
- package/dist/core/ecs/access_check.d.ts +77 -0
- package/dist/core/ecs/access_check.d.ts.map +1 -0
- package/dist/core/ecs/archetype.d.cts +486 -0
- package/dist/core/ecs/archetype.d.ts +486 -0
- package/dist/core/ecs/archetype.d.ts.map +1 -0
- package/dist/core/ecs/archetype_graph.d.cts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts.map +1 -0
- package/dist/core/ecs/builtin_relations.d.cts +43 -0
- package/dist/core/ecs/builtin_relations.d.ts +43 -0
- package/dist/core/ecs/builtin_relations.d.ts.map +1 -0
- package/dist/core/ecs/command_log.d.cts +116 -0
- package/dist/core/ecs/command_log.d.ts +116 -0
- package/dist/core/ecs/command_log.d.ts.map +1 -0
- package/dist/core/ecs/component.d.cts +176 -0
- package/dist/core/ecs/component.d.ts +176 -0
- package/dist/core/ecs/component.d.ts.map +1 -0
- package/dist/core/ecs/compute_backend.d.cts +37 -0
- package/dist/core/ecs/compute_backend.d.ts +37 -0
- package/dist/core/ecs/compute_backend.d.ts.map +1 -0
- package/dist/core/ecs/debug_names.d.cts +7 -0
- package/dist/core/ecs/debug_names.d.ts +7 -0
- package/dist/core/ecs/debug_names.d.ts.map +1 -0
- package/dist/core/ecs/deferred_commands.d.cts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
- package/dist/core/ecs/dispatch_trace.d.cts +93 -0
- package/dist/core/ecs/dispatch_trace.d.ts +93 -0
- package/dist/core/ecs/dispatch_trace.d.ts.map +1 -0
- package/dist/core/ecs/ecs.d.cts +562 -0
- package/dist/core/ecs/ecs.d.ts +562 -0
- package/dist/core/ecs/ecs.d.ts.map +1 -0
- package/dist/core/ecs/ecs_memory.d.cts +179 -0
- package/dist/core/ecs/ecs_memory.d.ts +179 -0
- package/dist/core/ecs/ecs_memory.d.ts.map +1 -0
- package/dist/core/ecs/entity.d.cts +34 -0
- package/dist/core/ecs/entity.d.ts +34 -0
- package/dist/core/ecs/entity.d.ts.map +1 -0
- package/dist/core/ecs/entity_allocator.d.cts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
- package/dist/core/ecs/event.d.cts +79 -0
- package/dist/core/ecs/event.d.ts +79 -0
- package/dist/core/ecs/event.d.ts.map +1 -0
- package/dist/core/ecs/event_registry.d.cts +22 -0
- package/dist/core/ecs/event_registry.d.ts +22 -0
- package/dist/core/ecs/event_registry.d.ts.map +1 -0
- package/dist/core/ecs/facades.d.cts +158 -0
- package/dist/core/ecs/facades.d.ts +158 -0
- package/dist/core/ecs/facades.d.ts.map +1 -0
- package/dist/core/ecs/frame_stepper.d.cts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
- package/dist/core/ecs/frame_trace.d.cts +133 -0
- package/dist/core/ecs/frame_trace.d.ts +133 -0
- package/dist/core/ecs/frame_trace.d.ts.map +1 -0
- package/dist/core/ecs/host_commands.d.cts +274 -0
- package/dist/core/ecs/host_commands.d.ts +274 -0
- package/dist/core/ecs/host_commands.d.ts.map +1 -0
- package/dist/core/ecs/index.d.cts +46 -0
- package/dist/core/ecs/index.d.ts +46 -0
- package/dist/core/ecs/index.d.ts.map +1 -0
- package/dist/core/ecs/observer.d.cts +173 -0
- package/dist/core/ecs/observer.d.ts +173 -0
- package/dist/core/ecs/observer.d.ts.map +1 -0
- package/dist/core/ecs/query.d.cts +718 -0
- package/dist/core/ecs/query.d.ts +718 -0
- package/dist/core/ecs/query.d.ts.map +1 -0
- package/dist/core/ecs/ref.d.cts +31 -0
- package/dist/core/ecs/ref.d.ts +31 -0
- package/dist/core/ecs/ref.d.ts.map +1 -0
- package/dist/core/ecs/relation.d.cts +243 -0
- package/dist/core/ecs/relation.d.ts +243 -0
- package/dist/core/ecs/relation.d.ts.map +1 -0
- package/dist/core/ecs/relation_service.d.cts +235 -0
- package/dist/core/ecs/relation_service.d.ts +235 -0
- package/dist/core/ecs/relation_service.d.ts.map +1 -0
- package/dist/core/ecs/resource.d.cts +53 -0
- package/dist/core/ecs/resource.d.ts +53 -0
- package/dist/core/ecs/resource.d.ts.map +1 -0
- package/dist/core/ecs/resource_registry.d.cts +20 -0
- package/dist/core/ecs/resource_registry.d.ts +20 -0
- package/dist/core/ecs/resource_registry.d.ts.map +1 -0
- package/dist/core/ecs/resume.d.cts +85 -0
- package/dist/core/ecs/resume.d.ts +85 -0
- package/dist/core/ecs/resume.d.ts.map +1 -0
- package/dist/core/ecs/run_condition.d.cts +81 -0
- package/dist/core/ecs/run_condition.d.ts +81 -0
- package/dist/core/ecs/run_condition.d.ts.map +1 -0
- package/dist/core/ecs/schedule.d.cts +142 -0
- package/dist/core/ecs/schedule.d.ts +142 -0
- package/dist/core/ecs/schedule.d.ts.map +1 -0
- package/dist/core/ecs/snapshot_service.d.cts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
- package/dist/core/ecs/sparse_store.d.cts +110 -0
- package/dist/core/ecs/sparse_store.d.ts +110 -0
- package/dist/core/ecs/sparse_store.d.ts.map +1 -0
- package/dist/core/ecs/store.d.cts +950 -0
- package/dist/core/ecs/store.d.ts +950 -0
- package/dist/core/ecs/store.d.ts.map +1 -0
- package/dist/core/ecs/store_layout_listener.d.cts +23 -0
- package/dist/core/ecs/store_layout_listener.d.ts +23 -0
- package/dist/core/ecs/store_layout_listener.d.ts.map +1 -0
- package/dist/core/ecs/system.d.cts +250 -0
- package/dist/core/ecs/system.d.ts +250 -0
- package/dist/core/ecs/system.d.ts.map +1 -0
- package/dist/core/ecs/utils/arrays.d.cts +7 -0
- package/dist/{utils → core/ecs/utils}/arrays.d.ts +2 -1
- package/dist/core/ecs/utils/arrays.d.ts.map +1 -0
- package/dist/core/ecs/utils/constants.d.ts +12 -0
- package/dist/core/ecs/utils/constants.d.ts.map +1 -0
- package/dist/core/ecs/utils/error.d.cts +61 -0
- package/dist/core/ecs/utils/error.d.ts +61 -0
- package/dist/core/ecs/utils/error.d.ts.map +1 -0
- package/dist/core/store/action_ring.d.cts +136 -0
- package/dist/core/store/action_ring.d.ts +136 -0
- package/dist/core/store/action_ring.d.ts.map +1 -0
- package/dist/core/store/allocator.d.cts +238 -0
- package/dist/core/store/allocator.d.ts +238 -0
- package/dist/core/store/allocator.d.ts.map +1 -0
- package/dist/core/store/buffer_backed_column.d.cts +69 -0
- package/dist/core/store/buffer_backed_column.d.ts +69 -0
- package/dist/core/store/buffer_backed_column.d.ts.map +1 -0
- package/dist/core/store/column_store.d.cts +273 -0
- package/dist/core/store/column_store.d.ts +273 -0
- package/dist/core/store/column_store.d.ts.map +1 -0
- package/dist/core/store/command_dispatch.d.cts +52 -0
- package/dist/core/store/command_dispatch.d.ts +52 -0
- package/dist/core/store/command_dispatch.d.ts.map +1 -0
- package/dist/core/store/command_ring.d.cts +107 -0
- package/dist/core/store/command_ring.d.ts +107 -0
- package/dist/core/store/command_ring.d.ts.map +1 -0
- package/dist/core/store/descriptor.d.cts +80 -0
- package/dist/core/store/descriptor.d.ts +80 -0
- package/dist/core/store/descriptor.d.ts.map +1 -0
- package/dist/core/store/entity_index.d.cts +108 -0
- package/dist/core/store/entity_index.d.ts +108 -0
- package/dist/core/store/entity_index.d.ts.map +1 -0
- package/dist/core/store/event_ring.d.cts +95 -0
- package/dist/core/store/event_ring.d.ts +95 -0
- package/dist/core/store/event_ring.d.ts.map +1 -0
- package/dist/core/store/extend.d.cts +39 -0
- package/dist/core/store/extend.d.ts +39 -0
- package/dist/core/store/extend.d.ts.map +1 -0
- package/dist/core/store/grow.d.cts +34 -0
- package/dist/core/store/grow.d.ts +34 -0
- package/dist/core/store/grow.d.ts.map +1 -0
- package/dist/core/store/header.d.cts +64 -0
- package/dist/core/store/header.d.ts +64 -0
- package/dist/core/store/header.d.ts.map +1 -0
- package/dist/core/store/index.d.cts +17 -0
- package/dist/core/store/index.d.ts +17 -0
- package/dist/core/store/index.d.ts.map +1 -0
- package/dist/core/store/layout_ops.d.cts +152 -0
- package/dist/core/store/layout_ops.d.ts +152 -0
- package/dist/core/store/layout_ops.d.ts.map +1 -0
- package/dist/core/store/region_table.d.cts +74 -0
- package/dist/core/store/region_table.d.ts +74 -0
- package/dist/core/store/region_table.d.ts.map +1 -0
- package/dist/core/store/snapshot.d.cts +43 -0
- package/dist/core/store/snapshot.d.ts +43 -0
- package/dist/core/store/snapshot.d.ts.map +1 -0
- package/dist/core/store/state_hash.d.cts +38 -0
- package/dist/core/store/state_hash.d.ts +38 -0
- package/dist/core/store/state_hash.d.ts.map +1 -0
- package/dist/core/store/store_regions.d.cts +38 -0
- package/dist/core/store/store_regions.d.ts +38 -0
- package/dist/core/store/store_regions.d.ts.map +1 -0
- package/dist/core/store/vendored_abi/abi.d.cts +43 -0
- package/dist/core/store/vendored_abi/abi.d.ts +43 -0
- package/dist/core/store/vendored_abi/abi.d.ts.map +1 -0
- package/dist/dev_flag.d.cts +17 -0
- package/dist/dev_flag.d.ts +17 -0
- package/dist/dev_flag.d.ts.map +1 -0
- package/dist/extensions/editor/editor.d.cts +170 -0
- package/dist/extensions/editor/editor.d.ts +170 -0
- package/dist/extensions/editor/editor.d.ts.map +1 -0
- package/dist/extensions/editor/field_handle.d.cts +40 -0
- package/dist/extensions/editor/field_handle.d.ts +40 -0
- package/dist/extensions/editor/field_handle.d.ts.map +1 -0
- package/dist/extensions/editor/index.cjs +1 -0
- package/dist/extensions/editor/index.d.cts +21 -0
- package/dist/extensions/editor/index.d.ts +21 -0
- package/dist/extensions/editor/index.d.ts.map +1 -0
- package/dist/extensions/editor/index.js +237 -0
- package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
- package/dist/extensions/reactive/ecs_sync.d.ts +214 -0
- package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -0
- package/dist/extensions/reactive/index.cjs +1 -0
- package/dist/extensions/reactive/index.d.cts +23 -0
- package/dist/extensions/reactive/index.d.ts +23 -0
- package/dist/extensions/reactive/index.d.ts.map +1 -0
- package/dist/extensions/reactive/index.js +215 -0
- package/dist/extensions/solid/index.cjs +1 -0
- package/dist/extensions/solid/index.d.cts +6 -0
- package/dist/extensions/solid/index.d.ts +6 -0
- package/dist/extensions/solid/index.d.ts.map +1 -0
- package/dist/extensions/solid/index.js +36 -0
- package/dist/extensions/solid/kernel_solid.d.cts +45 -0
- package/dist/extensions/solid/kernel_solid.d.ts +45 -0
- package/dist/extensions/solid/kernel_solid.d.ts.map +1 -0
- package/dist/host_commands-BF8QMi3c.cjs +1 -0
- package/dist/host_commands-i4cAeyL5.js +2318 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +65 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7080 -1289
- package/dist/internal.cjs +2 -0
- package/dist/internal.d.cts +20 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +141 -0
- package/dist/interop-CT-REx0W.cjs +1 -0
- package/dist/interop-CcY6ASQc.js +18 -0
- package/dist/kernel-DgyrLFjW.js +227 -0
- package/dist/kernel-yWV3XnAb.cjs +1 -0
- package/dist/primitives.cjs +1 -0
- package/dist/primitives.d.cts +18 -0
- package/dist/primitives.d.ts +18 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +45 -0
- package/dist/reactive/array.d.cts +24 -0
- package/dist/reactive/array.d.ts +24 -0
- package/dist/reactive/array.d.ts.map +1 -0
- package/dist/reactive/index.cjs +1 -0
- package/dist/reactive/index.d.cts +11 -0
- package/dist/reactive/index.d.ts +11 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/index.js +18 -0
- package/dist/reactive/interop.d.cts +19 -0
- package/dist/reactive/interop.d.ts +19 -0
- package/dist/reactive/interop.d.ts.map +1 -0
- package/dist/reactive/kernel.d.cts +73 -0
- package/dist/reactive/kernel.d.ts +73 -0
- package/dist/reactive/kernel.d.ts.map +1 -0
- package/dist/reactive/map.d.cts +16 -0
- package/dist/reactive/map.d.ts +16 -0
- package/dist/reactive/map.d.ts.map +1 -0
- package/dist/reactive/shallow.d.cts +11 -0
- package/dist/reactive/shallow.d.ts +11 -0
- package/dist/reactive/shallow.d.ts.map +1 -0
- package/dist/reactive/struct.d.cts +10 -0
- package/dist/reactive/struct.d.ts +10 -0
- package/dist/reactive/struct.d.ts.map +1 -0
- package/dist/shallow-DQ8aG51_.cjs +1 -0
- package/dist/shallow-DfnAm9vG.js +150 -0
- package/dist/shared-BU1Cd40h.js +103 -0
- package/dist/shared-BymrGTyR.cjs +1 -0
- package/dist/shared.cjs +1 -0
- package/dist/shared.d.cts +22 -0
- package/dist/shared.d.ts +22 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +7 -0
- package/dist/topological_sort-BDvEyb9W.cjs +1 -0
- package/dist/topological_sort-DK6EjpWa.js +135 -0
- package/dist/type_primitives/assertions.d.cts +32 -0
- package/dist/type_primitives/assertions.d.ts +25 -9
- package/dist/type_primitives/assertions.d.ts.map +1 -1
- package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
- package/dist/type_primitives/binary_heap/binary_heap.d.ts +6 -2
- package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -1
- package/dist/type_primitives/bitset/bitset.d.cts +54 -0
- package/dist/type_primitives/bitset/bitset.d.ts +16 -4
- package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
- package/dist/type_primitives/brand.d.cts +23 -0
- package/dist/type_primitives/brand.d.ts +6 -1
- package/dist/type_primitives/brand.d.ts.map +1 -1
- package/dist/type_primitives/error.d.cts +16 -0
- package/dist/type_primitives/error.d.ts +8 -3
- package/dist/type_primitives/error.d.ts.map +1 -1
- package/dist/type_primitives/index.d.cts +13 -0
- package/dist/type_primitives/index.d.ts +12 -9
- package/dist/type_primitives/index.d.ts.map +1 -1
- package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
- package/dist/type_primitives/sparse_map/sparse_map.d.ts +7 -3
- package/dist/type_primitives/sparse_map/sparse_map.d.ts.map +1 -1
- package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
- package/dist/type_primitives/sparse_set/sparse_set.d.ts +4 -0
- package/dist/type_primitives/sparse_set/sparse_set.d.ts.map +1 -1
- package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
- package/dist/type_primitives/topological_sort/topological_sort.d.ts +7 -3
- package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -1
- package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +53 -16
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
- package/dist/typed_arrays-BcXcnzB4.js +258 -0
- package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
- package/dist/utils/error.d.cts +6 -0
- package/dist/utils/error.d.ts +2 -20
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/version.d.cts +10 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +115 -5
- package/dist/archetype.d.ts +0 -108
- package/dist/archetype.d.ts.map +0 -1
- package/dist/component.d.ts +0 -45
- package/dist/component.d.ts.map +0 -1
- package/dist/ecs.d.ts +0 -104
- package/dist/ecs.d.ts.map +0 -1
- package/dist/entity.d.ts +0 -11
- package/dist/entity.d.ts.map +0 -1
- package/dist/event.d.ts +0 -30
- package/dist/event.d.ts.map +0 -1
- package/dist/query.d.ts +0 -94
- package/dist/query.d.ts.map +0 -1
- package/dist/ref.d.ts +0 -23
- package/dist/ref.d.ts.map +0 -1
- package/dist/resource.d.ts +0 -23
- package/dist/resource.d.ts.map +0 -1
- package/dist/schedule.d.ts +0 -45
- package/dist/schedule.d.ts.map +0 -1
- package/dist/store.d.ts +0 -118
- package/dist/store.d.ts.map +0 -1
- package/dist/system.d.ts +0 -16
- package/dist/system.d.ts.map +0 -1
- package/dist/utils/arrays.d.ts.map +0 -1
- package/dist/utils/constants.d.ts.map +0 -1
- /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { Brand, AnyTypedArray, ColumnBacking, TypedArrayTag, BitSet } from '../../type_primitives/index.cjs';
|
|
2
|
+
import { ColumnStore } from '../store/column_store.cjs';
|
|
3
|
+
import { ComponentID, ComponentDef, ComponentSchema, SchemaOf, DeclaredQueryTerm, TagToTypedArray, ColumnsForSchema, MutableColumnsForSchema, ReadonlyColumn } from './component.cjs';
|
|
4
|
+
import { EntityID, ReadonlyEntityIdArray } from './entity.cjs';
|
|
5
|
+
export type ArchetypeID = Brand<number, "archetype_id">;
|
|
6
|
+
export declare const asArchetypeId: (value: number) => ArchetypeID;
|
|
7
|
+
export interface ArchetypeEdge {
|
|
8
|
+
add: ArchetypeID | null;
|
|
9
|
+
remove: ArchetypeID | null;
|
|
10
|
+
/** Pre-computed column mapping for add direction: this → add target. */
|
|
11
|
+
addMap: Int16Array | null;
|
|
12
|
+
/** Pre-computed column mapping for remove direction: this → remove target. */
|
|
13
|
+
removeMap: Int16Array | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cached resolution of a *multi*-component add out of this archetype: the
|
|
17
|
+
* target archetype the union lands in, plus the pre-built src→target batch
|
|
18
|
+
* transition map. Keyed (on the source archetype) by an exact N-tagged pack of
|
|
19
|
+
* the added component ids — see `Store.addComponents` (#659).
|
|
20
|
+
*
|
|
21
|
+
* Where `ArchetypeEdge` is the per-*component* edge the single-add path indexes
|
|
22
|
+
* by `edges[component_id]`, this is the per-*set* edge the plural-add path looks
|
|
23
|
+
* up by packed key — folding the mask hash, `archLookup`, and batch-map fetch
|
|
24
|
+
* the final-mask resolve repeats every call into one `Map.get`. Never
|
|
25
|
+
* invalidated: the archetype graph is monotonic (archetypes outlive the Store).
|
|
26
|
+
*/
|
|
27
|
+
export interface CompositeAddEdge {
|
|
28
|
+
target: ArchetypeID;
|
|
29
|
+
map: Int16Array;
|
|
30
|
+
}
|
|
31
|
+
export interface ArchetypeColumnLayout {
|
|
32
|
+
componentId: ComponentID;
|
|
33
|
+
fieldNames: string[];
|
|
34
|
+
fieldIndex: Record<string, number>;
|
|
35
|
+
fieldTypes: TypedArrayTag[];
|
|
36
|
+
}
|
|
37
|
+
interface ArchetypeColumnGroup {
|
|
38
|
+
layout: ArchetypeColumnLayout;
|
|
39
|
+
columns: ColumnBacking<AnyTypedArray>[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Per-column allocator. Returns a `ColumnBacking` for the field at
|
|
43
|
+
* `fieldIdx` of component `component_id`. The default factory (when none
|
|
44
|
+
* is supplied to the constructor) allocates a `GrowableTypedArray` on the
|
|
45
|
+
* heap; `fromColumnStore` supplies a factory that wraps SAB views instead.
|
|
46
|
+
*/
|
|
47
|
+
export type ColumnFactory = (componentId: ComponentID, fieldIdx: number, tag: TypedArrayTag) => ColumnBacking<AnyTypedArray>;
|
|
48
|
+
/**
|
|
49
|
+
* Hook the host installs on every SAB-backed archetype so the Archetype
|
|
50
|
+
* can request a SAB grow + refresh from the host BEFORE the insertion
|
|
51
|
+
* that would otherwise throw `StoreColumnOverflowError`. The host (Store)
|
|
52
|
+
* is responsible for running `growColumnStore` and `refreshViews`
|
|
53
|
+
* across every SAB-backed archetype; after the handler returns,
|
|
54
|
+
* `arch._flatColumns[i].buf.length` is guaranteed to be `>= arch.length +
|
|
55
|
+
* additional`. Heap-backed archetypes leave this unset — their
|
|
56
|
+
* `GrowableTypedArray` grows in place. (#171 §6.1.9 Phase 3)
|
|
57
|
+
*/
|
|
58
|
+
export type ArchetypeGrowHandler = (arch: Archetype, additional: number) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Public, read-only window onto an archetype's rows. This is the ONLY
|
|
61
|
+
* surface `Query.archetypes`, `Query.forEach`, and `ChangedQuery.forEach`
|
|
62
|
+
* hand to callers — the concrete `Archetype` (with its structural mutators
|
|
63
|
+
* `removeEntity`, `moveEntityFrom`, `writeFields`, `setEdge`, and the
|
|
64
|
+
* mutable `getColumn`) stays internal so query iteration can't bypass the
|
|
65
|
+
* deferred-flush path that prevents iterator invalidation. This is the same
|
|
66
|
+
* back door PR #163 closed for `Store`; issue #378 closed it again for
|
|
67
|
+
* `Query`.
|
|
68
|
+
*
|
|
69
|
+
* `id` is the archetype's opaque identity (not a mutator) — exposed so the
|
|
70
|
+
* public `ECS.batchAddComponent`/`batchRemoveComponent` API can target an
|
|
71
|
+
* archetype without the caller holding a concrete `Archetype` reference.
|
|
72
|
+
*/
|
|
73
|
+
export interface ArchetypeView<out Defs extends readonly ComponentDef<any>[] = readonly ComponentDef<any>[]> {
|
|
74
|
+
/** Opaque archetype identity. Pass to `ECS.batch_*_component`. */
|
|
75
|
+
readonly id: ArchetypeID;
|
|
76
|
+
/** Number of **enabled** entities — the default-iteration bound (#577). Rows
|
|
77
|
+
* `0..entityCount-1` are enabled; disabled rows (if any) sit contiguously at
|
|
78
|
+
* `entityCount..totalCount-1`. `forEach` SoA loops read this, so they skip
|
|
79
|
+
* disabled rows for free. Use `totalCount` to span disabled rows too. */
|
|
80
|
+
readonly entityCount: number;
|
|
81
|
+
/** Total live rows, enabled + disabled (#577). Equal to `entityCount` unless
|
|
82
|
+
* some rows are disabled. Use for full-state work (serialization, snapshot,
|
|
83
|
+
* determinism) that must see every entity regardless of enabled state. */
|
|
84
|
+
readonly totalCount: number;
|
|
85
|
+
/** Number of disabled rows = `totalCount - entityCount` (#577). */
|
|
86
|
+
readonly disabledCount: number;
|
|
87
|
+
/** Raw entity ID buffer (packed `EntityID`s). Valid data at indices
|
|
88
|
+
* 0..totalCount-1 (enabled rows first, then disabled). */
|
|
89
|
+
readonly entityIds: ReadonlyEntityIdArray;
|
|
90
|
+
/** True if this archetype's mask includes the given component. */
|
|
91
|
+
hasComponent(id: ComponentID): boolean;
|
|
92
|
+
/** Get a single field's column (read-only). Valid data: indices
|
|
93
|
+
* 0..entityCount-1. `def` must be a term of the iterating query
|
|
94
|
+
* (POLISH_AUDIT #6); the bare-`ArchetypeView` default stays permissive. */
|
|
95
|
+
getColumnRead<D extends ComponentDef<any>, K extends string & keyof SchemaOf<D>>(def: D & DeclaredQueryTerm<Defs, D>, field: K): ReadonlyColumn;
|
|
96
|
+
/** Tuple fetch of several of one component's columns —
|
|
97
|
+
* `const [q, r] = arch.getColumnsRead(HexPos, "q", "r")`. One small
|
|
98
|
+
* array allocation per call; see the class doc on `Archetype`. */
|
|
99
|
+
getColumnsRead<D extends ComponentDef<any>, const K extends readonly (string & keyof SchemaOf<D>)[]>(def: D & DeclaredQueryTerm<Defs, D>, ...fields: K): {
|
|
100
|
+
[I in keyof K]: ReadonlyColumn;
|
|
101
|
+
};
|
|
102
|
+
/** Get a single field's column **if this archetype has the component**,
|
|
103
|
+
* else `undefined` — the optional-query fetch-if-present accessor (#575).
|
|
104
|
+
* The absent branch is expected (resolve the column pointer per archetype
|
|
105
|
+
* span: present ⇒ column, absent ⇒ `undefined`), not an error. Same
|
|
106
|
+
* advisory-readonly view and `reads`-access-check as `getColumnRead`. */
|
|
107
|
+
getOptionalColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn | undefined;
|
|
108
|
+
}
|
|
109
|
+
export declare class Archetype implements ArchetypeView {
|
|
110
|
+
readonly id: ArchetypeID;
|
|
111
|
+
readonly mask: BitSet;
|
|
112
|
+
readonly hasColumns: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Whether a member entity occupies a real row here. True for every archetype
|
|
115
|
+
* except the **empty archetype** (the one with no components), where a
|
|
116
|
+
* component-less entity is "alive but unplaced" — it points here via
|
|
117
|
+
* `entityArchetype` but carries `entityRow === UNASSIGNED` and holds no
|
|
118
|
+
* row, exactly like a freshly `createEntity`'d one. Keeping the empty
|
|
119
|
+
* archetype rowless gives a component-less entity a single canonical form
|
|
120
|
+
* regardless of how it got there (created bare vs. lost its last component),
|
|
121
|
+
* so `stateHash` and zero-require query iteration don't depend on add/remove
|
|
122
|
+
* history. The row-materialising methods below honour this flag.
|
|
123
|
+
*/
|
|
124
|
+
readonly materializesRows: boolean;
|
|
125
|
+
private readonly _entityIds;
|
|
126
|
+
length: number;
|
|
127
|
+
/**
|
|
128
|
+
* Enabled/disabled row partition (#577 — entity enable/disable). Rows
|
|
129
|
+
* `[0, enabled_count)` are enabled, `[enabled_count, length)` are disabled.
|
|
130
|
+
* `enabled_count === length` (no disabled rows) is the common case — every
|
|
131
|
+
* fast path below short-circuits on it, so an archetype that never disables
|
|
132
|
+
* an entity pays nothing. Disable/enable swap a row across the boundary
|
|
133
|
+
* (`disableRow`/`enableRow`); appends place enabled rows in front of the
|
|
134
|
+
* disabled tail (`_placeTail`). `entityCount` (the query/iteration bound)
|
|
135
|
+
* returns this; `length`/`totalCount` span disabled rows too. Folded into
|
|
136
|
+
* `stateHash` and published to the SAB descriptor so the WASM sim and
|
|
137
|
+
* snapshot/restore honour it.
|
|
138
|
+
*/
|
|
139
|
+
enabledCount: number;
|
|
140
|
+
/**
|
|
141
|
+
* Flush-epoch stamp + captured pre-counts for the Store's per-entity flush
|
|
142
|
+
* 0-crossing detector (#328, #812): `_flushAdds`/`_flushRemoves` stamp each
|
|
143
|
+
* archetype on first sight per flush (a few field accesses) instead of probing
|
|
144
|
+
* a `Map<archetype_id, pre_count>` per entity — the same per-entity Map
|
|
145
|
+
* cost the destroy drain shed in #457. Both `_flushPreLen` and
|
|
146
|
+
* `_flushPreEnabled` are recorded so the settle pass can detect a 0-crossing
|
|
147
|
+
* on either the total (`length`) or the enabled partition (`enabledCount`) —
|
|
148
|
+
* an enabled append into an all-disabled archetype crosses only the latter
|
|
149
|
+
* (#812). Owned by Store; pure scheduling bookkeeping, never folded into
|
|
150
|
+
* `stateHash`/snapshot.
|
|
151
|
+
*/
|
|
152
|
+
_flushSeenEpoch: number;
|
|
153
|
+
_flushPreLen: number;
|
|
154
|
+
_flushPreEnabled: number;
|
|
155
|
+
/**
|
|
156
|
+
* DEV-only iteration guard: >0 while a dense query iterator (`forEach` /
|
|
157
|
+
* `eachChunk` / `forEachUntil` / `ChangedQuery.forEach`) is delivering this
|
|
158
|
+
* archetype to a user callback. The row-removing/reordering primitives
|
|
159
|
+
* (`removeRow` / `disableRow` / `enableRow`) check it so an immediate
|
|
160
|
+
* structural mutation from inside the walk — which would swap-remove under
|
|
161
|
+
* the iterator and silently skip or repeat entities — throws instead.
|
|
162
|
+
* Production builds never read or write it.
|
|
163
|
+
*/
|
|
164
|
+
_iterDepth: number;
|
|
165
|
+
private readonly edges;
|
|
166
|
+
/**
|
|
167
|
+
* Cache of pre-computed transition maps for multi-component transitions
|
|
168
|
+
* (this → target). Single-component edges live on `edges[].addMap`/`removeMap`;
|
|
169
|
+
* multi-component pairs land here. Entries never need invalidation —
|
|
170
|
+
* archetypes live for the Store's lifetime.
|
|
171
|
+
*/
|
|
172
|
+
private readonly batchTransitionMaps;
|
|
173
|
+
/**
|
|
174
|
+
* Per-set add-edge cache for `Store.addComponents` (#659), keyed by an
|
|
175
|
+
* exact pack of the added component ids. Lazily allocated: most archetypes
|
|
176
|
+
* never originate a plural add, so the Map stays `null` until the first one
|
|
177
|
+
* is resolved — the single-add `edges[]` path never touches it.
|
|
178
|
+
*/
|
|
179
|
+
private compositeAddEdges;
|
|
180
|
+
readonly _flatColumns: ColumnBacking<AnyTypedArray>[];
|
|
181
|
+
/** Set by `fromColumnStore` to record which SAB archetype this Archetype
|
|
182
|
+
* draws its column views from. `null` for the default heap-backed path
|
|
183
|
+
* (no SAB linkage; `refreshViews` would be a no-op there and so
|
|
184
|
+
* isn't supported). */
|
|
185
|
+
private _storeArchetypeId;
|
|
186
|
+
readonly _colOffset: number[];
|
|
187
|
+
readonly _fieldCount: number[];
|
|
188
|
+
private readonly _fieldIndex;
|
|
189
|
+
private readonly _fieldNames;
|
|
190
|
+
readonly columnGroups: (ArchetypeColumnGroup | undefined)[];
|
|
191
|
+
readonly _columnIds: number[];
|
|
192
|
+
readonly _changedTick: number[];
|
|
193
|
+
private readonly _mutGroupCache;
|
|
194
|
+
private readonly _readGroupCache;
|
|
195
|
+
/** Host-installed grow hook. Set by `Store` on every SAB-backed
|
|
196
|
+
* archetype during construction; `null` on heap-backed archetypes (the
|
|
197
|
+
* default `GrowableTypedArray` grows in place). Insertion methods call
|
|
198
|
+
* `_invoke_grow(...)` below before any push that would overflow the
|
|
199
|
+
* current SAB row capacity. (#171 §6.1.9 Phase 3) */
|
|
200
|
+
growHandler: ArchetypeGrowHandler | null;
|
|
201
|
+
constructor(id: ArchetypeID, mask: BitSet, layouts?: ArchetypeColumnLayout[], initialCapacity?: number, columnFactory?: ColumnFactory);
|
|
202
|
+
/**
|
|
203
|
+
* Build an Archetype whose columns are TypedArray views into a single
|
|
204
|
+
* `ColumnStore`-managed `SharedArrayBuffer`. The store must contain an
|
|
205
|
+
* archetype entry whose id equals `storeArchetypeId` and whose columns
|
|
206
|
+
* cover every `(component_id, fieldIdx)` pair declared by `layouts`.
|
|
207
|
+
*
|
|
208
|
+
* The resulting archetype is fixed-capacity at the SAB row capacity —
|
|
209
|
+
* any operation that would push past it throws `StoreColumnOverflowError`.
|
|
210
|
+
* To grow capacity, call `growColumnStore(...)` between ticks and then
|
|
211
|
+
* `refreshViews(newStore)` on this archetype (#171 §6.1.4 / §8.1).
|
|
212
|
+
*/
|
|
213
|
+
static fromColumnStore(id: ArchetypeID, mask: BitSet, layouts: ArchetypeColumnLayout[], columnStore: ColumnStore, storeArchetypeId: number): Archetype;
|
|
214
|
+
/** True iff this archetype was constructed via `fromColumnStore` and its
|
|
215
|
+
* `_flatColumns` are SAB-backed. Heap-backed archetypes return `false`
|
|
216
|
+
* and cannot be refreshed (their columns grow in place). */
|
|
217
|
+
get isBufferBacked(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Repoint every column at the matching SAB view in `newColumnStore` after
|
|
220
|
+
* a host-side `growColumnStore` realloc. The archetype keeps its row
|
|
221
|
+
* count; each column's logical length is preserved. Caller is responsible
|
|
222
|
+
* for ensuring `newColumnStore` was built by `growColumnStore` over the
|
|
223
|
+
* SAB this archetype was originally drawn from — the matching
|
|
224
|
+
* `storeArchetypeId` was recorded in `fromColumnStore` and is reused here.
|
|
225
|
+
*
|
|
226
|
+
* Throws `ECSError` if this archetype is not SAB-backed, or if the new
|
|
227
|
+
* store lacks the recorded archetype id or any column the archetype
|
|
228
|
+
* expects.
|
|
229
|
+
*/
|
|
230
|
+
refreshViews(newColumnStore: ColumnStore): void;
|
|
231
|
+
/** Enabled-row count — the default iteration bound (#577). See `enabled_count`.
|
|
232
|
+
* Equals `length` whenever no entity is disabled (the common case).
|
|
233
|
+
*
|
|
234
|
+
* During an `includeDisabled()` query's `forEach`, the module flag
|
|
235
|
+
* `_iterAllRows` is set so this returns `length` (enabled + disabled) — the
|
|
236
|
+
* user's `for i < arch.entityCount` loop then spans disabled rows
|
|
237
|
+
* transparently, with no change to the loop. Outside such iteration the flag is
|
|
238
|
+
* false and this is `enabled_count`. */
|
|
239
|
+
get entityCount(): number;
|
|
240
|
+
/** Total live rows incl. disabled (#577). */
|
|
241
|
+
get totalCount(): number;
|
|
242
|
+
/** Disabled-row count (#577). */
|
|
243
|
+
get disabledCount(): number;
|
|
244
|
+
/** Raw entity ID buffer (packed `EntityID`s). Valid data at indices
|
|
245
|
+
* 0..totalCount-1 (enabled rows first, then disabled). */
|
|
246
|
+
get entityIds(): ReadonlyEntityIdArray;
|
|
247
|
+
/**
|
|
248
|
+
* Swap the two rows `a` and `b` — entity ids and every column. Does NOT touch
|
|
249
|
+
* `entityRow`; the caller updates the entity→row map for whichever rows it
|
|
250
|
+
* cares about (it knows the two `entityIds` after the swap). The partition
|
|
251
|
+
* primitives (`disableRow`/`enableRow`/`removeRow`/`_placeTail`) build on
|
|
252
|
+
* this. Writes through each column's live backing buffer (`buf`), so it works
|
|
253
|
+
* for both heap- and SAB-backed columns. No-op when `a === b`. (#577) */
|
|
254
|
+
swapRows(a: number, b: number): void;
|
|
255
|
+
/**
|
|
256
|
+
* Place a freshly-appended ENABLED entity (currently at the tail row `tail`,
|
|
257
|
+
* already pushed, `length` already incremented) into the enabled region, and
|
|
258
|
+
* bump `enabled_count`. Returns its final row.
|
|
259
|
+
*
|
|
260
|
+
* Common case — no disabled rows (`enabled_count === tail`): the tail row IS
|
|
261
|
+
* the next enabled slot, so this is just `enabled_count++` and returns `tail`
|
|
262
|
+
* (byte-for-byte the pre-#577 behaviour, `entityRow` untouched). Rare case —
|
|
263
|
+
* disabled rows occupy `[enabled_count, tail)`: swap the appended row into the
|
|
264
|
+
* first disabled slot and push that disabled occupant to the tail, updating
|
|
265
|
+
* its `entityRow`. Requires `entityRow` in that case (a `DEV` guard fires
|
|
266
|
+
* if a caller appends into a disabled-bearing archetype without passing it). (#577) */
|
|
267
|
+
private _placeTail;
|
|
268
|
+
/**
|
|
269
|
+
* Bulk analog of `_placeTail` for `count` freshly-appended enabled rows at
|
|
270
|
+
* `[start, start+count)`. Common case (no disabled rows, `enabled_count ===
|
|
271
|
+
* start`): `enabled_count += count`, return `start`. The bulk callers
|
|
272
|
+
* (`spawnMany`, batch ops) fall back to a per-entity append loop when the
|
|
273
|
+
* target already has disabled rows, so the rare branch is a `DEV` guard
|
|
274
|
+
* rather than a block-rotation. (#577) */
|
|
275
|
+
private _placeTailBulk;
|
|
276
|
+
/**
|
|
277
|
+
* Disable the entity at `row` (precondition: enabled, `row < enabled_count`).
|
|
278
|
+
* Swaps it to the end of the enabled region and shrinks the region, so it
|
|
279
|
+
* lands in the disabled tail with its data intact — no archetype transition,
|
|
280
|
+
* O(1)+one row swap. Updates `entityRow` for both rows touched. (#577) */
|
|
281
|
+
disableRow(row: number, entityRow: Int32Array): void;
|
|
282
|
+
/**
|
|
283
|
+
* Enable the entity at `row` (precondition: disabled, `row >= enabled_count`).
|
|
284
|
+
* Swaps it to the front of the disabled region and grows the enabled region.
|
|
285
|
+
* Updates `entityRow` for both rows touched. (#577) */
|
|
286
|
+
enableRow(row: number, entityRow: Int32Array): void;
|
|
287
|
+
/**
|
|
288
|
+
* Partition-aware swap-remove that owns its `entityRow` updates (#577). The
|
|
289
|
+
* Store's destroy/move paths call this instead of `removeEntity`; it keeps the
|
|
290
|
+
* enabled prefix contiguous in every case:
|
|
291
|
+
* - disabled row (`row >= enabled_count`): swap-remove within the disabled
|
|
292
|
+
* tail (the last row is disabled) — `enabled_count` unchanged.
|
|
293
|
+
* - last enabled row: swap-remove with the global last; `enabled_count--`.
|
|
294
|
+
* - middle enabled row: move the last enabled row into the hole (so the
|
|
295
|
+
* enabled prefix stays packed), then swap-remove that vacated enabled slot
|
|
296
|
+
* with the global last; `enabled_count--`.
|
|
297
|
+
* Updates `entityRow` for every relocated entity (never for the removed one —
|
|
298
|
+
* the caller frees/repoints it). */
|
|
299
|
+
removeRow(row: number, entityRow: Int32Array): void;
|
|
300
|
+
/** @internal — cold partition-aware tail of `removeRow` (#577): the
|
|
301
|
+
* disabled-bearing archetype case. Split out so the no-disabled fast path
|
|
302
|
+
* above stays small enough to inline (#649); see the doc on `removeRow`. */
|
|
303
|
+
private _removeRowPartitioned;
|
|
304
|
+
get entityList(): Uint32Array;
|
|
305
|
+
hasComponent(id: ComponentID): boolean;
|
|
306
|
+
matches(required: BitSet): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Get a single field's column (read-only — use when not mutating). Valid
|
|
309
|
+
* data: indices 0..entityCount-1. The `ReadonlyColumn` return is an
|
|
310
|
+
* *advisory* compile-time barrier: it is the live mutable backing buffer,
|
|
311
|
+
* so the `readonly` index signature blocks writes at the type layer only
|
|
312
|
+
* (a §10c-policed cast can still write through). For writes use the
|
|
313
|
+
* mutable `getColumn` (tick-bumping) below.
|
|
314
|
+
*/
|
|
315
|
+
getColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn;
|
|
316
|
+
/**
|
|
317
|
+
* Tuple fetch of several of one component's columns —
|
|
318
|
+
* `const [q, r] = arch.getColumnsRead(HexPos, "q", "r")` collapses the
|
|
319
|
+
* per-field `getColumnRead` preamble at the top of an iteration callback
|
|
320
|
+
* to one line. Same advisory-readonly views and `reads` access-check as
|
|
321
|
+
* `getColumnRead`. Allocates one small array per call — fine once per
|
|
322
|
+
* archetype per tick; in a per-row loop fetch columns individually.
|
|
323
|
+
*/
|
|
324
|
+
getColumnsRead<S extends ComponentSchema, const K extends readonly (string & keyof S)[]>(def: ComponentDef<S>, ...fields: K): {
|
|
325
|
+
[I in keyof K]: ReadonlyColumn;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Get a single field's column **if this archetype has the component**, else
|
|
329
|
+
* `undefined` — the fetch-if-present accessor for optional query terms (#575,
|
|
330
|
+
* Bevy `Option<&T>` / flecs `?`). An optional query (`q.optional(T)`) spans
|
|
331
|
+
* archetypes both with and without `T`; the caller branches once per
|
|
332
|
+
* archetype span on the return:
|
|
333
|
+
*
|
|
334
|
+
* q.forEach((arch) => {
|
|
335
|
+
* const vx = arch.getOptionalColumnRead(Vel, "vx");
|
|
336
|
+
* for (let i = 0; i < arch.entityCount; i++) {
|
|
337
|
+
* px[i] += vx ? vx[i] : 0; // absent span ⇒ vx === undefined
|
|
338
|
+
* }
|
|
339
|
+
* });
|
|
340
|
+
*
|
|
341
|
+
* Unlike `getColumnRead`, a component the archetype lacks is the expected
|
|
342
|
+
* **absent** branch, not a thrown error. The `DEV` checks still run
|
|
343
|
+
* **first** (before the absent short-circuit), so the requirements don't
|
|
344
|
+
* depend on whether the current span happens to hold `T`. Two checks fire:
|
|
345
|
+
* (1) `accessCheck.checkRead` — an optional read needs `reads:[T]` coverage
|
|
346
|
+
* exactly as a required read does; (2) `accessCheck.checkOptionalFetch` —
|
|
347
|
+
* the iterating query must have declared `.optional(T)` (#592), the read-side
|
|
348
|
+
* analog that makes the query term the fetch's authorization rather than inert
|
|
349
|
+
* decoration. The return is the same advisory-readonly view `getColumnRead`
|
|
350
|
+
* hands back.
|
|
351
|
+
*/
|
|
352
|
+
getOptionalColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn | undefined;
|
|
353
|
+
/** Get a single field's column (mutable — the default). Marks the component as changed at the given tick. */
|
|
354
|
+
getColumn<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K, tick: number): TagToTypedArray[S[K]];
|
|
355
|
+
/** Mutable field-keyed column group; stamps the change tick once. */
|
|
356
|
+
columnGroupMut<S extends ComponentSchema>(def: ComponentDef<S>, tick: number): MutableColumnsForSchema<S>;
|
|
357
|
+
/** Read-only field-keyed column group (no tick bump). */
|
|
358
|
+
columnGroupRead<S extends ComponentSchema>(def: ComponentDef<S>): ColumnsForSchema<S>;
|
|
359
|
+
writeFields(row: number, componentId: ComponentID, values: Record<string, number>, tick: number): void;
|
|
360
|
+
/**
|
|
361
|
+
* Bulk variant of `writeFields` — fills `count` consecutive rows starting
|
|
362
|
+
* at `dstStart` with the same field values via per-field `TypedArray.fill`.
|
|
363
|
+
* For N rows of an F-field component, this is F native fill calls instead
|
|
364
|
+
* of N×F per-row JS writes. The change-tick is bumped once for the range,
|
|
365
|
+
* not once per row. Used by `Store.batchAddComponent` after a bulk move,
|
|
366
|
+
* where every freshly-added row shares the same field values.
|
|
367
|
+
*/
|
|
368
|
+
bulkWriteFields(dstStart: number, count: number, componentId: ComponentID, values: Record<string, number>, tick: number): void;
|
|
369
|
+
/** Fast positional write: values[i] → field[i] in declaration order. No string lookup. */
|
|
370
|
+
writeFieldsPositional(row: number, componentId: ComponentID, values: ArrayLike<number>, tick: number): void;
|
|
371
|
+
readField(row: number, componentId: ComponentID, field: string): number;
|
|
372
|
+
/** Copy all shared component columns from source archetype at srcRow into dstRow. */
|
|
373
|
+
copySharedFrom(source: Archetype, srcRow: number, dstRow: number, tick: number): void;
|
|
374
|
+
/**
|
|
375
|
+
* Add an entity. Pushes zeroes into all columns and returns the assigned row.
|
|
376
|
+
* Store is responsible for tracking entityIndex → row.
|
|
377
|
+
*/
|
|
378
|
+
addEntity(entityId: EntityID, entityRow?: Int32Array): number;
|
|
379
|
+
/**
|
|
380
|
+
* Remove entity at row via swap-and-pop. Swaps the last entity into the
|
|
381
|
+
* vacated row to keep data dense. Returns the entityIndex of the swapped
|
|
382
|
+
* entity (so Store can update its row), or NO_SWAP if no swap was needed.
|
|
383
|
+
*/
|
|
384
|
+
removeEntity(row: number): number;
|
|
385
|
+
/** Tag-optimized add: skip column push entirely (no data to store). */
|
|
386
|
+
addEntityTag(entityId: EntityID, entityRow?: Int32Array): number;
|
|
387
|
+
/**
|
|
388
|
+
* Bulk add `count` entities, zero-initialising all columns. Returns the
|
|
389
|
+
* starting dstRow for the batch. Caller is responsible for tracking
|
|
390
|
+
* entityIndex → row for every entity in the batch.
|
|
391
|
+
*
|
|
392
|
+
* Collapses the N×C `push(0)` cost of N sequential `addEntity` calls
|
|
393
|
+
* into C `bulkAppendZeroes(count)` calls — the same pattern
|
|
394
|
+
* `bulkMoveAllFrom` (`:580`) uses for the move-with-data case (#330).
|
|
395
|
+
*/
|
|
396
|
+
addEntities(entityIds: Uint32Array, count?: number): number;
|
|
397
|
+
/** Tag-optimized bulk add: skip the per-column zero-fill entirely. */
|
|
398
|
+
addEntitiesTag(entityIds: Uint32Array, count?: number): number;
|
|
399
|
+
/** Grow column capacity to fit `additional` more rows if the next append
|
|
400
|
+
* would overflow — the exact grow trigger the `addEntityWithValues` /
|
|
401
|
+
* `addEntitiesWithValues` appends run internally, lifted out so the spawn
|
|
402
|
+
* path can pre-reserve capacity BEFORE it commits an entity slot. A SAB-cap
|
|
403
|
+
* grow throws here (with the world untouched) instead of mid-append after the
|
|
404
|
+
* slot is already live — see `Store.spawn`/`spawnMany` (#775). No-op for a
|
|
405
|
+
* tag-only archetype (no SAB columns) or when no grow handler is installed. */
|
|
406
|
+
ensureRowCapacity(additional: number): void;
|
|
407
|
+
/** Append one entity, writing `flatValues[i]` straight into column `i`
|
|
408
|
+
* (in `_flatColumns` order) — no zero-fill-then-overwrite. Bumps every
|
|
409
|
+
* column's change tick once. Returns the assigned row. */
|
|
410
|
+
addEntityWithValues(entityId: EntityID, flatValues: number[], tick: number, entityRow?: Int32Array): number;
|
|
411
|
+
/** Bulk append `count` entities, filling column `i` with `flatValues[i]`
|
|
412
|
+
* in a single `TypedArray.fill` per column (no zero pass). Returns the
|
|
413
|
+
* starting row. */
|
|
414
|
+
addEntitiesWithValues(entityIds: Uint32Array, count: number, flatValues: number[], tick: number): number;
|
|
415
|
+
/** Tag-optimized remove via swap-and-pop: skip column swap/pop entirely. */
|
|
416
|
+
removeEntityTag(row: number): number;
|
|
417
|
+
/**
|
|
418
|
+
* Move an entity from src archetype into this archetype in a single pass.
|
|
419
|
+
* Combines addEntity + copySharedFrom + removeEntity(src).
|
|
420
|
+
* Uses a pre-computed transition map for branchless column copy.
|
|
421
|
+
* Writes dstRow to _moveResult[0], swapped entity index to _moveResult[1].
|
|
422
|
+
*/
|
|
423
|
+
moveEntityFrom(src: Archetype, srcRow: number, entityId: EntityID, transitionMap: Int16Array, tick: number, entityRow: Int32Array): void;
|
|
424
|
+
/**
|
|
425
|
+
* Move an entity from src into this archetype (tag-only: no columns to copy).
|
|
426
|
+
* Writes dstRow to _moveResult[0]; _moveResult[1] is always NO_SWAP (the
|
|
427
|
+
* partition-aware src/dst updates are owned internally, #577).
|
|
428
|
+
*/
|
|
429
|
+
moveEntityFromTag(src: Archetype, srcRow: number, entityId: EntityID, entityRow: Int32Array): void;
|
|
430
|
+
/**
|
|
431
|
+
* Bulk-move ALL entities from src into this archetype using TypedArray.set().
|
|
432
|
+
* Much faster than per-entity moveEntityFrom when the entire source is moving.
|
|
433
|
+
* After this call, src is empty. Returns the starting dstRow for the batch.
|
|
434
|
+
*/
|
|
435
|
+
bulkMoveAllFrom(src: Archetype, transitionMap: Int16Array, tick: number): number;
|
|
436
|
+
/**
|
|
437
|
+
* Drop every row at once — length → 0, entity-id list and all columns
|
|
438
|
+
* cleared — without copying into a destination. Used when an archetype's
|
|
439
|
+
* entire population leaves in one move: `bulkMoveAllFrom` clears the
|
|
440
|
+
* source this way, and `Store.batchRemoveComponent` calls it directly when
|
|
441
|
+
* the destination is the rowless empty archetype (batch-removing the last
|
|
442
|
+
* component), where there is nothing to copy into.
|
|
443
|
+
*/
|
|
444
|
+
clearRows(): void;
|
|
445
|
+
/**
|
|
446
|
+
* Re-derive the host-side row bookkeeping after a snapshot is mounted onto a
|
|
447
|
+
* live world (#789, `Store.restoreInto`). A snapshot reloads the column bytes
|
|
448
|
+
* (dense SAB) but NOT the host-side `length` / `enabledCount` / `_entityIds`
|
|
449
|
+
* back-reference — those are reconstructed here. `refreshViews` must have
|
|
450
|
+
* already repointed the columns at the restored SAB.
|
|
451
|
+
*
|
|
452
|
+
* The caller scans the restored entity-index region to learn which entity
|
|
453
|
+
* occupies each row and passes them in row order (`rowEntityIds[r]` is the
|
|
454
|
+
* packed `EntityID` at row `r`; rows `[0, length)` are dense, enabled rows
|
|
455
|
+
* first then disabled per the #577 partition). `enabledCount` is the restored
|
|
456
|
+
* partition boundary. This is the inverse of the per-row `addEntity` /
|
|
457
|
+
* `disableRow` bookkeeping the live run accumulated.
|
|
458
|
+
*/
|
|
459
|
+
restoreHostRows(rowEntityIds: readonly number[], enabledCount: number): void;
|
|
460
|
+
getEdge(componentId: ComponentID): ArchetypeEdge | undefined;
|
|
461
|
+
setEdge(componentId: ComponentID, edge: ArchetypeEdge): void;
|
|
462
|
+
/**
|
|
463
|
+
* Get the transition map from this archetype to `target`, building and caching
|
|
464
|
+
* it on miss. Used by Store.addComponents / removeComponents — the per-edge
|
|
465
|
+
* cache only covers single-component steps.
|
|
466
|
+
*/
|
|
467
|
+
getBatchTransitionMap(target: Archetype): Int16Array;
|
|
468
|
+
/** Look up a cached plural-add transition by its packed key (#659). Returns
|
|
469
|
+
* `undefined` until the first composite add out of this archetype plants the
|
|
470
|
+
* lazy Map — the common case for archetypes that only ever see single adds. */
|
|
471
|
+
getCompositeAddEdge(key: number): CompositeAddEdge | undefined;
|
|
472
|
+
/** Cache a resolved plural-add transition (target + src→target map) under its
|
|
473
|
+
* packed key (#659), allocating the backing Map on first use. */
|
|
474
|
+
cacheCompositeAddEdge(key: number, target: ArchetypeID, map: Int16Array): void;
|
|
475
|
+
}
|
|
476
|
+
/** Reusable result buffer for move_entity_from/move_entity_from_tag. [dstRow, swapped_index] */
|
|
477
|
+
export declare const _moveResult: [number, number];
|
|
478
|
+
export declare function _setIterAllRows(value: boolean): boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Build a transition map from src archetype to dst archetype.
|
|
481
|
+
* For each column in dst, stores the index of the corresponding column in src,
|
|
482
|
+
* or -1 if the column is new (no source).
|
|
483
|
+
*/
|
|
484
|
+
export declare function buildTransitionMap(src: Archetype, dst: Archetype): Int16Array;
|
|
485
|
+
export {};
|
|
486
|
+
//# sourceMappingURL=archetype.d.ts.map
|