@forgeax/engine-ecs 0.0.0-dev.8d955ade1c79
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/LICENSE +202 -0
- package/README.md +278 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__fixtures__/field-shape-fixture.d.ts +16 -0
- package/dist/__fixtures__/field-shape-fixture.d.ts.map +1 -0
- package/dist/__tests__/__fixtures__/inspect-scripts.snapshot.d.ts +3 -0
- package/dist/__tests__/__fixtures__/inspect-scripts.snapshot.d.ts.map +1 -0
- package/dist/__tests__/archetype.unit.test.d.ts +2 -0
- package/dist/__tests__/archetype.unit.test.d.ts.map +1 -0
- package/dist/__tests__/array-handle-element.test-d.d.ts +2 -0
- package/dist/__tests__/array-handle-element.test-d.d.ts.map +1 -0
- package/dist/__tests__/buffer-array-vocab.test-d.d.ts +2 -0
- package/dist/__tests__/buffer-array-vocab.test-d.d.ts.map +1 -0
- package/dist/__tests__/buffer-field-input-widen.unit.test.d.ts +2 -0
- package/dist/__tests__/buffer-field-input-widen.unit.test.d.ts.map +1 -0
- package/dist/__tests__/buffer-pool.test-d.d.ts +2 -0
- package/dist/__tests__/buffer-pool.test-d.d.ts.map +1 -0
- package/dist/__tests__/change-detection.unit.test.d.ts +2 -0
- package/dist/__tests__/change-detection.unit.test.d.ts.map +1 -0
- package/dist/__tests__/command-buffer.test.d.ts +2 -0
- package/dist/__tests__/command-buffer.test.d.ts.map +1 -0
- package/dist/__tests__/commands-deferred.unit.test.d.ts +2 -0
- package/dist/__tests__/commands-deferred.unit.test.d.ts.map +1 -0
- package/dist/__tests__/component-catalog.test.d.ts +2 -0
- package/dist/__tests__/component-catalog.test.d.ts.map +1 -0
- package/dist/__tests__/component-definition-identity.unit.test.d.ts +2 -0
- package/dist/__tests__/component-definition-identity.unit.test.d.ts.map +1 -0
- package/dist/__tests__/component-nan-preflight.unit.test.d.ts +2 -0
- package/dist/__tests__/component-nan-preflight.unit.test.d.ts.map +1 -0
- package/dist/__tests__/component-schema.test-d.d.ts +2 -0
- package/dist/__tests__/component-schema.test-d.d.ts.map +1 -0
- package/dist/__tests__/component-schema.test.d.ts +2 -0
- package/dist/__tests__/component-schema.test.d.ts.map +1 -0
- package/dist/__tests__/define-component-options.test-d.d.ts +2 -0
- package/dist/__tests__/define-component-options.test-d.d.ts.map +1 -0
- package/dist/__tests__/deprecated-vocab-rejection.unit.test.d.ts +2 -0
- package/dist/__tests__/deprecated-vocab-rejection.unit.test.d.ts.map +1 -0
- package/dist/__tests__/despawn-all.unit.test.d.ts +2 -0
- package/dist/__tests__/despawn-all.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ecs-core-reduction.characterization.test.d.ts +2 -0
- package/dist/__tests__/ecs-core-reduction.characterization.test.d.ts.map +1 -0
- package/dist/__tests__/ecs-core-reduction.perf.test.d.ts +2 -0
- package/dist/__tests__/ecs-core-reduction.perf.test.d.ts.map +1 -0
- package/dist/__tests__/ecs-error-code-31.test-d.d.ts +2 -0
- package/dist/__tests__/ecs-error-code-31.test-d.d.ts.map +1 -0
- package/dist/__tests__/entity-disabling.unit.test.d.ts +2 -0
- package/dist/__tests__/entity-disabling.unit.test.d.ts.map +1 -0
- package/dist/__tests__/entity-handle-codec-parity.unit.test.d.ts +2 -0
- package/dist/__tests__/entity-handle-codec-parity.unit.test.d.ts.map +1 -0
- package/dist/__tests__/errors.unit.test.d.ts +2 -0
- package/dist/__tests__/errors.unit.test.d.ts.map +1 -0
- package/dist/__tests__/execution-conflict-boundary.unit.test.d.ts +2 -0
- package/dist/__tests__/execution-conflict-boundary.unit.test.d.ts.map +1 -0
- package/dist/__tests__/execution-shared-storage.unit.test.d.ts +2 -0
- package/dist/__tests__/execution-shared-storage.unit.test.d.ts.map +1 -0
- package/dist/__tests__/externalization-portable-value.unit.test.d.ts +2 -0
- package/dist/__tests__/externalization-portable-value.unit.test.d.ts.map +1 -0
- package/dist/__tests__/externalization-projection.unit.test.d.ts +2 -0
- package/dist/__tests__/externalization-projection.unit.test.d.ts.map +1 -0
- package/dist/__tests__/externalization-render-read-lease.test-d.d.ts +2 -0
- package/dist/__tests__/externalization-render-read-lease.test-d.d.ts.map +1 -0
- package/dist/__tests__/externalization-render-read-lease.unit.test.d.ts +2 -0
- package/dist/__tests__/externalization-render-read-lease.unit.test.d.ts.map +1 -0
- package/dist/__tests__/externalization-root-surface.unit.test.d.ts +2 -0
- package/dist/__tests__/externalization-root-surface.unit.test.d.ts.map +1 -0
- package/dist/__tests__/field-enum-labels-reflection.test.d.ts +2 -0
- package/dist/__tests__/field-enum-labels-reflection.test.d.ts.map +1 -0
- package/dist/__tests__/field-shape-fixture.test.d.ts +2 -0
- package/dist/__tests__/field-shape-fixture.test.d.ts.map +1 -0
- package/dist/__tests__/field-transient-reflection.test.d.ts +2 -0
- package/dist/__tests__/field-transient-reflection.test.d.ts.map +1 -0
- package/dist/__tests__/field-value-type.test-d.d.ts +2 -0
- package/dist/__tests__/field-value-type.test-d.d.ts.map +1 -0
- package/dist/__tests__/fixed-update.unit.test.d.ts +2 -0
- package/dist/__tests__/fixed-update.unit.test.d.ts.map +1 -0
- package/dist/__tests__/handle.test-d.d.ts +2 -0
- package/dist/__tests__/handle.test-d.d.ts.map +1 -0
- package/dist/__tests__/hierarchy.unit.test.d.ts +2 -0
- package/dist/__tests__/hierarchy.unit.test.d.ts.map +1 -0
- package/dist/__tests__/managed-array-vocab.test-d.d.ts +2 -0
- package/dist/__tests__/managed-array-vocab.test-d.d.ts.map +1 -0
- package/dist/__tests__/minimal-example.test-d.d.ts +2 -0
- package/dist/__tests__/minimal-example.test-d.d.ts.map +1 -0
- package/dist/__tests__/name-read-types.test-d.d.ts +2 -0
- package/dist/__tests__/name-read-types.test-d.d.ts.map +1 -0
- package/dist/__tests__/plugin-service.test.d.ts +2 -0
- package/dist/__tests__/plugin-service.test.d.ts.map +1 -0
- package/dist/__tests__/query-combinations.unit.test.d.ts +2 -0
- package/dist/__tests__/query-combinations.unit.test.d.ts.map +1 -0
- package/dist/__tests__/query-light-extract-flat-column-ratio.perf.test.d.ts +2 -0
- package/dist/__tests__/query-light-extract-flat-column-ratio.perf.test.d.ts.map +1 -0
- package/dist/__tests__/query-storage-trends.perf.test.d.ts +2 -0
- package/dist/__tests__/query-storage-trends.perf.test.d.ts.map +1 -0
- package/dist/__tests__/query-trs-flat-column-ratio.perf.test.d.ts +2 -0
- package/dist/__tests__/query-trs-flat-column-ratio.perf.test.d.ts.map +1 -0
- package/dist/__tests__/query.unit.test.d.ts +2 -0
- package/dist/__tests__/query.unit.test.d.ts.map +1 -0
- package/dist/__tests__/relationship-index.perf.test.d.ts +2 -0
- package/dist/__tests__/relationship-index.perf.test.d.ts.map +1 -0
- package/dist/__tests__/relationship-index.test.d.ts +2 -0
- package/dist/__tests__/relationship-index.test.d.ts.map +1 -0
- package/dist/__tests__/scalar-field-type-owner.test-d.d.ts +2 -0
- package/dist/__tests__/scalar-field-type-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/schedule-determinism.unit.test.d.ts +2 -0
- package/dist/__tests__/schedule-determinism.unit.test.d.ts.map +1 -0
- package/dist/__tests__/schedule-inspection.unit.test.d.ts +2 -0
- package/dist/__tests__/schedule-inspection.unit.test.d.ts.map +1 -0
- package/dist/__tests__/schedule-scope-error.unit.test.d.ts +2 -0
- package/dist/__tests__/schedule-scope-error.unit.test.d.ts.map +1 -0
- package/dist/__tests__/schedule-token.unit.test.d.ts +2 -0
- package/dist/__tests__/schedule-token.unit.test.d.ts.map +1 -0
- package/dist/__tests__/schema-vocab.test-d.d.ts +2 -0
- package/dist/__tests__/schema-vocab.test-d.d.ts.map +1 -0
- package/dist/__tests__/serialization.unit.test.d.ts +2 -0
- package/dist/__tests__/serialization.unit.test.d.ts.map +1 -0
- package/dist/__tests__/shared-kernel-eligibility.test-d.d.ts +2 -0
- package/dist/__tests__/shared-kernel-eligibility.test-d.d.ts.map +1 -0
- package/dist/__tests__/shared-kernel-eligibility.unit.test.d.ts +2 -0
- package/dist/__tests__/shared-kernel-eligibility.unit.test.d.ts.map +1 -0
- package/dist/__tests__/shared-ref-store.unit.test.d.ts +2 -0
- package/dist/__tests__/shared-ref-store.unit.test.d.ts.map +1 -0
- package/dist/__tests__/sparse-tag.unit.test.d.ts +2 -0
- package/dist/__tests__/sparse-tag.unit.test.d.ts.map +1 -0
- package/dist/__tests__/spawn-field-error.test-d.d.ts +2 -0
- package/dist/__tests__/spawn-field-error.test-d.d.ts.map +1 -0
- package/dist/__tests__/stale-error.test-d.d.ts +2 -0
- package/dist/__tests__/stale-error.test-d.d.ts.map +1 -0
- package/dist/__tests__/string-view-symmetry.test-d.d.ts +2 -0
- package/dist/__tests__/string-view-symmetry.test-d.d.ts.map +1 -0
- package/dist/__tests__/string-vocab.test-d.d.ts +2 -0
- package/dist/__tests__/string-vocab.test-d.d.ts.map +1 -0
- package/dist/__tests__/structure-epoch-boundaries.unit.test.d.ts +2 -0
- package/dist/__tests__/structure-epoch-boundaries.unit.test.d.ts.map +1 -0
- package/dist/__tests__/structure-epoch.unit.test.d.ts +2 -0
- package/dist/__tests__/structure-epoch.unit.test.d.ts.map +1 -0
- package/dist/__tests__/table-archetype-mapping.unit.test.d.ts +2 -0
- package/dist/__tests__/table-archetype-mapping.unit.test.d.ts.map +1 -0
- package/dist/__tests__/time.unit.test.d.ts +2 -0
- package/dist/__tests__/time.unit.test.d.ts.map +1 -0
- package/dist/__tests__/types.test-d.d.ts +2 -0
- package/dist/__tests__/types.test-d.d.ts.map +1 -0
- package/dist/__tests__/unique-ref-store.unit.test.d.ts +2 -0
- package/dist/__tests__/unique-ref-store.unit.test.d.ts.map +1 -0
- package/dist/__tests__/utils/handle-numeric.d.ts +14 -0
- package/dist/__tests__/utils/handle-numeric.d.ts.map +1 -0
- package/dist/__tests__/validation-root-surface.unit.test.d.ts +2 -0
- package/dist/__tests__/validation-root-surface.unit.test.d.ts.map +1 -0
- package/dist/__tests__/visibility-atomic-write.unit.test.d.ts +2 -0
- package/dist/__tests__/visibility-atomic-write.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world-change-journal.unit.test.d.ts +2 -0
- package/dist/__tests__/world-change-journal.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world-characterization.unit.test.d.ts +2 -0
- package/dist/__tests__/world-characterization.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world-consumer-inference.test-d.d.ts +2 -0
- package/dist/__tests__/world-consumer-inference.test-d.d.ts.map +1 -0
- package/dist/__tests__/world-health.contract.test.d.ts +2 -0
- package/dist/__tests__/world-health.contract.test.d.ts.map +1 -0
- package/dist/__tests__/world-inspection.test.d.ts +2 -0
- package/dist/__tests__/world-inspection.test.d.ts.map +1 -0
- package/dist/__tests__/world-internal-identity.unit.test.d.ts +2 -0
- package/dist/__tests__/world-internal-identity.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world-managed-roundtrip.unit.test.d.ts +2 -0
- package/dist/__tests__/world-managed-roundtrip.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world-scheduling.m4.test.d.ts +2 -0
- package/dist/__tests__/world-scheduling.m4.test.d.ts.map +1 -0
- package/dist/__tests__/world-unique-roundtrip.unit.test.d.ts +2 -0
- package/dist/__tests__/world-unique-roundtrip.unit.test.d.ts.map +1 -0
- package/dist/__tests__/world.test-d.d.ts +2 -0
- package/dist/__tests__/world.test-d.d.ts.map +1 -0
- package/dist/buffer-pool.d.ts +109 -0
- package/dist/buffer-pool.d.ts.map +1 -0
- package/dist/commands.d.ts +93 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/component-default-fallback.d.ts +88 -0
- package/dist/component-default-fallback.d.ts.map +1 -0
- package/dist/component-schema.d.ts +34 -0
- package/dist/component-schema.d.ts.map +1 -0
- package/dist/component-value-validate.d.ts +29 -0
- package/dist/component-value-validate.d.ts.map +1 -0
- package/dist/component.d.ts +581 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/entity-handle.d.ts +68 -0
- package/dist/entity-handle.d.ts.map +1 -0
- package/dist/entity.d.ts +86 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/errors/query-and-component-errors.d.ts +132 -0
- package/dist/errors/query-and-component-errors.d.ts.map +1 -0
- package/dist/errors/relationship-errors.d.ts +112 -0
- package/dist/errors/relationship-errors.d.ts.map +1 -0
- package/dist/errors/sprite-and-shared-errors.d.ts +107 -0
- package/dist/errors/sprite-and-shared-errors.d.ts.map +1 -0
- package/dist/errors/validation-errors.d.ts +229 -0
- package/dist/errors/validation-errors.d.ts.map +1 -0
- package/dist/errors.d.ts +763 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/execution/shared-kernel.d.ts +106 -0
- package/dist/execution/shared-kernel.d.ts.map +1 -0
- package/dist/externalization/index.d.ts +31 -0
- package/dist/externalization/index.d.ts.map +1 -0
- package/dist/externalization/index.mjs +298 -0
- package/dist/externalization/index.mjs.map +1 -0
- package/dist/index.d.ts +261 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +7422 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal.mjs +479 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/plugin-service.d.ts +11 -0
- package/dist/plugin-service.d.ts.map +1 -0
- package/dist/projection/index.d.ts +103 -0
- package/dist/projection/index.d.ts.map +1 -0
- package/dist/projection/index.mjs +615 -0
- package/dist/projection/index.mjs.map +1 -0
- package/dist/query/query.d.ts +58 -0
- package/dist/query/query.d.ts.map +1 -0
- package/dist/relationship-index.d.ts +81 -0
- package/dist/relationship-index.d.ts.map +1 -0
- package/dist/resource.d.ts +70 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/schedule-token.d.ts +16 -0
- package/dist/schedule-token.d.ts.map +1 -0
- package/dist/schedule.d.ts +271 -0
- package/dist/schedule.d.ts.map +1 -0
- package/dist/shared-ref-store.d.ts +144 -0
- package/dist/shared-ref-store.d.ts.map +1 -0
- package/dist/shared.d.ts +3 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.mjs +364 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/storage/archetype-graph.d.ts +54 -0
- package/dist/storage/archetype-graph.d.ts.map +1 -0
- package/dist/storage/archetype.d.ts +23 -0
- package/dist/storage/archetype.d.ts.map +1 -0
- package/dist/storage/change-detection.d.ts +40 -0
- package/dist/storage/change-detection.d.ts.map +1 -0
- package/dist/storage/column.d.ts +111 -0
- package/dist/storage/column.d.ts.map +1 -0
- package/dist/storage/table.d.ts +29 -0
- package/dist/storage/table.d.ts.map +1 -0
- package/dist/time.d.ts +57 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/unique-ref-store.d.ts +105 -0
- package/dist/unique-ref-store.d.ts.map +1 -0
- package/dist/world-change-journal.d.ts +34 -0
- package/dist/world-change-journal.d.ts.map +1 -0
- package/dist/world-component-access.d.ts +265 -0
- package/dist/world-component-access.d.ts.map +1 -0
- package/dist/world-component-storage.d.ts +282 -0
- package/dist/world-component-storage.d.ts.map +1 -0
- package/dist/world-core.d.ts +39 -0
- package/dist/world-core.d.ts.map +1 -0
- package/dist/world-entity-lifecycle.d.ts +30 -0
- package/dist/world-entity-lifecycle.d.ts.map +1 -0
- package/dist/world-internal.d.ts +14 -0
- package/dist/world-internal.d.ts.map +1 -0
- package/dist/world-scheduling.d.ts +30 -0
- package/dist/world-scheduling.d.ts.map +1 -0
- package/dist/world.d.ts +620 -0
- package/dist/world.d.ts.map +1 -0
- package/package.json +77 -0
- package/src/__fixtures__/field-shape-fixture.ts +30 -0
- package/src/__tests__/__fixtures__/inspect-scripts.snapshot.ts +2 -0
- package/src/__tests__/archetype.unit.test.ts +1837 -0
- package/src/__tests__/array-handle-element.test-d.ts +34 -0
- package/src/__tests__/buffer-array-vocab.test-d.ts +53 -0
- package/src/__tests__/buffer-field-input-widen.unit.test.ts +99 -0
- package/src/__tests__/buffer-pool.test-d.ts +32 -0
- package/src/__tests__/change-detection.unit.test.ts +86 -0
- package/src/__tests__/command-buffer.test.ts +179 -0
- package/src/__tests__/commands-deferred.unit.test.ts +68 -0
- package/src/__tests__/component-catalog.test.ts +59 -0
- package/src/__tests__/component-definition-identity.unit.test.ts +24 -0
- package/src/__tests__/component-nan-preflight.unit.test.ts +186 -0
- package/src/__tests__/component-schema.test-d.ts +119 -0
- package/src/__tests__/component-schema.test.ts +55 -0
- package/src/__tests__/define-component-options.test-d.ts +35 -0
- package/src/__tests__/deprecated-vocab-rejection.unit.test.ts +59 -0
- package/src/__tests__/despawn-all.unit.test.ts +17 -0
- package/src/__tests__/ecs-core-reduction.characterization.test.ts +130 -0
- package/src/__tests__/ecs-core-reduction.perf.test.ts +260 -0
- package/src/__tests__/ecs-error-code-31.test-d.ts +42 -0
- package/src/__tests__/entity-disabling.unit.test.ts +37 -0
- package/src/__tests__/entity-handle-codec-parity.unit.test.ts +126 -0
- package/src/__tests__/errors.unit.test.ts +1456 -0
- package/src/__tests__/execution-conflict-boundary.unit.test.ts +123 -0
- package/src/__tests__/execution-shared-storage.unit.test.ts +40 -0
- package/src/__tests__/externalization-portable-value.unit.test.ts +275 -0
- package/src/__tests__/externalization-projection.unit.test.ts +325 -0
- package/src/__tests__/externalization-render-read-lease.test-d.ts +30 -0
- package/src/__tests__/externalization-render-read-lease.unit.test.ts +79 -0
- package/src/__tests__/externalization-root-surface.unit.test.ts +33 -0
- package/src/__tests__/field-enum-labels-reflection.test.ts +66 -0
- package/src/__tests__/field-shape-fixture.test.ts +61 -0
- package/src/__tests__/field-transient-reflection.test.ts +59 -0
- package/src/__tests__/field-value-type.test-d.ts +57 -0
- package/src/__tests__/fixed-update.unit.test.ts +78 -0
- package/src/__tests__/handle.test-d.ts +86 -0
- package/src/__tests__/hierarchy.unit.test.ts +2534 -0
- package/src/__tests__/managed-array-vocab.test-d.ts +137 -0
- package/src/__tests__/minimal-example.test-d.ts +42 -0
- package/src/__tests__/name-read-types.test-d.ts +72 -0
- package/src/__tests__/plugin-service.test.ts +13 -0
- package/src/__tests__/query-combinations.unit.test.ts +42 -0
- package/src/__tests__/query-light-extract-flat-column-ratio.perf.test.ts +252 -0
- package/src/__tests__/query-storage-trends.perf.test.ts +104 -0
- package/src/__tests__/query-trs-flat-column-ratio.perf.test.ts +194 -0
- package/src/__tests__/query.unit.test.ts +196 -0
- package/src/__tests__/relationship-index.perf.test.ts +126 -0
- package/src/__tests__/relationship-index.test.ts +70 -0
- package/src/__tests__/scalar-field-type-owner.test-d.ts +71 -0
- package/src/__tests__/schedule-determinism.unit.test.ts +36 -0
- package/src/__tests__/schedule-inspection.unit.test.ts +81 -0
- package/src/__tests__/schedule-scope-error.unit.test.ts +63 -0
- package/src/__tests__/schedule-token.unit.test.ts +54 -0
- package/src/__tests__/schema-vocab.test-d.ts +103 -0
- package/src/__tests__/serialization.unit.test.ts +2740 -0
- package/src/__tests__/shared-kernel-eligibility.test-d.ts +18 -0
- package/src/__tests__/shared-kernel-eligibility.unit.test.ts +78 -0
- package/src/__tests__/shared-ref-store.unit.test.ts +646 -0
- package/src/__tests__/sparse-tag.unit.test.ts +201 -0
- package/src/__tests__/spawn-field-error.test-d.ts +41 -0
- package/src/__tests__/stale-error.test-d.ts +208 -0
- package/src/__tests__/string-view-symmetry.test-d.ts +26 -0
- package/src/__tests__/string-vocab.test-d.ts +49 -0
- package/src/__tests__/structure-epoch-boundaries.unit.test.ts +39 -0
- package/src/__tests__/structure-epoch.unit.test.ts +48 -0
- package/src/__tests__/table-archetype-mapping.unit.test.ts +78 -0
- package/src/__tests__/time.unit.test.ts +79 -0
- package/src/__tests__/types.test-d.ts +38 -0
- package/src/__tests__/unique-ref-store.unit.test.ts +348 -0
- package/src/__tests__/utils/handle-numeric.ts +30 -0
- package/src/__tests__/validation-root-surface.unit.test.ts +15 -0
- package/src/__tests__/visibility-atomic-write.unit.test.ts +82 -0
- package/src/__tests__/world-change-journal.unit.test.ts +97 -0
- package/src/__tests__/world-characterization.unit.test.ts +408 -0
- package/src/__tests__/world-consumer-inference.test-d.ts +16 -0
- package/src/__tests__/world-health.contract.test.ts +87 -0
- package/src/__tests__/world-inspection.test.ts +37 -0
- package/src/__tests__/world-internal-identity.unit.test.ts +17 -0
- package/src/__tests__/world-managed-roundtrip.unit.test.ts +98 -0
- package/src/__tests__/world-scheduling.m4.test.ts +52 -0
- package/src/__tests__/world-unique-roundtrip.unit.test.ts +357 -0
- package/src/__tests__/world.test-d.ts +156 -0
- package/src/buffer-pool.ts +357 -0
- package/src/commands.ts +644 -0
- package/src/component-default-fallback.ts +236 -0
- package/src/component-schema.ts +92 -0
- package/src/component-value-validate.ts +135 -0
- package/src/component.ts +1268 -0
- package/src/entity-handle.ts +104 -0
- package/src/entity.ts +140 -0
- package/src/errors/query-and-component-errors.ts +200 -0
- package/src/errors/relationship-errors.ts +198 -0
- package/src/errors/sprite-and-shared-errors.ts +231 -0
- package/src/errors/validation-errors.ts +506 -0
- package/src/errors.ts +1464 -0
- package/src/execution/shared-kernel.ts +392 -0
- package/src/externalization/index.ts +170 -0
- package/src/index.ts +414 -0
- package/src/plugin-service.ts +35 -0
- package/src/projection/index.ts +318 -0
- package/src/query/query.ts +606 -0
- package/src/relationship-index.ts +175 -0
- package/src/resource.ts +106 -0
- package/src/schedule-token.ts +40 -0
- package/src/schedule.ts +846 -0
- package/src/shared-ref-store.ts +418 -0
- package/src/shared.ts +23 -0
- package/src/storage/archetype-graph.ts +166 -0
- package/src/storage/archetype.ts +78 -0
- package/src/storage/change-detection.ts +231 -0
- package/src/storage/column.ts +247 -0
- package/src/storage/table.ts +153 -0
- package/src/time.ts +122 -0
- package/src/unique-ref-store.ts +278 -0
- package/src/world-change-journal.ts +84 -0
- package/src/world-component-access.ts +1421 -0
- package/src/world-component-storage.ts +1178 -0
- package/src/world-core.ts +74 -0
- package/src/world-entity-lifecycle.ts +539 -0
- package/src/world-internal.ts +75 -0
- package/src/world-scheduling.ts +499 -0
- package/src/world.ts +1399 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
// @forgeax/engine-ecs -- World schedule and resource orchestration.
|
|
2
|
+
|
|
3
|
+
import type { Handle } from '@forgeax/engine-types';
|
|
4
|
+
import { err, ok, type Result } from '@forgeax/engine-types';
|
|
5
|
+
import type { CommandBufferImpl } from './commands';
|
|
6
|
+
import {
|
|
7
|
+
CommandFailedError,
|
|
8
|
+
CyclicDependencyError,
|
|
9
|
+
ProtectedResourceError,
|
|
10
|
+
ScheduleScopeMismatchError,
|
|
11
|
+
SystemFailedError,
|
|
12
|
+
type SystemSetNotRegisteredError,
|
|
13
|
+
TimeConfigInvalidError,
|
|
14
|
+
TimeDeltaInvalidError,
|
|
15
|
+
} from './errors';
|
|
16
|
+
import {
|
|
17
|
+
SHARED_KERNEL_EXECUTOR_RESOURCE_KEY,
|
|
18
|
+
type SharedKernelDispatch,
|
|
19
|
+
type SharedKernelExecutor,
|
|
20
|
+
SharedKernelFailureError,
|
|
21
|
+
WorldPoisonedError,
|
|
22
|
+
} from './execution/shared-kernel';
|
|
23
|
+
import type { QueryDescriptor } from './query/query';
|
|
24
|
+
import {
|
|
25
|
+
getResource as resGet,
|
|
26
|
+
hasResource as resHas,
|
|
27
|
+
insertResource as resInsert,
|
|
28
|
+
removeResource as resRemove,
|
|
29
|
+
} from './resource';
|
|
30
|
+
import {
|
|
31
|
+
buildSchedule,
|
|
32
|
+
runSchedule,
|
|
33
|
+
type Schedule,
|
|
34
|
+
type SystemDescriptor,
|
|
35
|
+
type SystemSet,
|
|
36
|
+
addSystem as scheduleAddSystem,
|
|
37
|
+
addSystems as scheduleAddSystems,
|
|
38
|
+
removeSystem as scheduleRemoveSystem,
|
|
39
|
+
replaceSystem as scheduleReplaceSystem,
|
|
40
|
+
} from './schedule';
|
|
41
|
+
import { FixedUpdate, isScheduleToken, type ScheduleToken, Update } from './schedule-token';
|
|
42
|
+
import type { ArchetypeGraph } from './storage/archetype-graph';
|
|
43
|
+
import { FIXED_TIME_RESOURCE_KEY, type MutableFixedTimeResource, TIME_RESOURCE_KEY } from './time';
|
|
44
|
+
import type {
|
|
45
|
+
World,
|
|
46
|
+
WorldInspection,
|
|
47
|
+
WorldScheduleData,
|
|
48
|
+
WorldScheduleQueryData,
|
|
49
|
+
WorldScheduleSystemData,
|
|
50
|
+
} from './world';
|
|
51
|
+
import { worldInternal } from './world-internal';
|
|
52
|
+
|
|
53
|
+
const FIXED_ANCHOR_NAME = FixedUpdate.name;
|
|
54
|
+
type ResourceKey = string | { readonly name: string };
|
|
55
|
+
|
|
56
|
+
function resourceName(key: ResourceKey): string {
|
|
57
|
+
return typeof key === 'string' ? key : key.name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function warmSharedKernel(world: World, descriptor: unknown): void {
|
|
61
|
+
if (
|
|
62
|
+
(descriptor as { readonly kind?: string }).kind !== 'shared-kernel' ||
|
|
63
|
+
!world.hasResource(SHARED_KERNEL_EXECUTOR_RESOURCE_KEY)
|
|
64
|
+
)
|
|
65
|
+
return;
|
|
66
|
+
world
|
|
67
|
+
.getResource<SharedKernelExecutor>(SHARED_KERNEL_EXECUTOR_RESOURCE_KEY)
|
|
68
|
+
.warmup?.(descriptor as SharedKernelDispatch);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function scheduleFor(
|
|
72
|
+
world: World,
|
|
73
|
+
token: ScheduleToken,
|
|
74
|
+
): Result<Schedule, ScheduleScopeMismatchError> {
|
|
75
|
+
const schedule = isScheduleToken(token) ? world[worldInternal].getSchedule(token) : undefined;
|
|
76
|
+
if (schedule) return ok(schedule);
|
|
77
|
+
return err(new ScheduleScopeMismatchError(token?.name ?? 'Unknown', Update.name));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function setOwner(world: World, set: SystemSet): ScheduleToken | undefined {
|
|
81
|
+
for (const [token, schedule] of world[worldInternal].getSchedules()) {
|
|
82
|
+
if (schedule.sets.has(set.name)) return token;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function scopeError(
|
|
88
|
+
source: ScheduleToken,
|
|
89
|
+
target: ScheduleToken,
|
|
90
|
+
reference?: string,
|
|
91
|
+
): Result<never, ScheduleScopeMismatchError> {
|
|
92
|
+
return err(new ScheduleScopeMismatchError(source.name, target.name, reference));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function worldAddSystem<const Qs extends ReadonlyArray<QueryDescriptor>>(
|
|
96
|
+
world: World,
|
|
97
|
+
token: ScheduleToken,
|
|
98
|
+
descriptor: SystemDescriptor<Qs>,
|
|
99
|
+
): Result<void, ScheduleScopeMismatchError> {
|
|
100
|
+
const target = scheduleFor(world, token);
|
|
101
|
+
if (!target.ok) return target;
|
|
102
|
+
scheduleAddSystem(target.value, descriptor);
|
|
103
|
+
warmSharedKernel(world, descriptor);
|
|
104
|
+
return ok(undefined);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function worldRemoveSystem(
|
|
108
|
+
world: World,
|
|
109
|
+
token: ScheduleToken,
|
|
110
|
+
name: string,
|
|
111
|
+
): ReturnType<typeof scheduleRemoveSystem> | Result<never, ScheduleScopeMismatchError> {
|
|
112
|
+
const target = scheduleFor(world, token);
|
|
113
|
+
if (!target.ok) return target;
|
|
114
|
+
return scheduleRemoveSystem(target.value, name);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function worldReplaceSystem<const Qs extends ReadonlyArray<QueryDescriptor>>(
|
|
118
|
+
world: World,
|
|
119
|
+
token: ScheduleToken,
|
|
120
|
+
name: string,
|
|
121
|
+
descriptor: SystemDescriptor<Qs>,
|
|
122
|
+
): ReturnType<typeof scheduleReplaceSystem> | Result<never, ScheduleScopeMismatchError> {
|
|
123
|
+
const target = scheduleFor(world, token);
|
|
124
|
+
if (!target.ok) return target;
|
|
125
|
+
const replaced = scheduleReplaceSystem(target.value, name, descriptor);
|
|
126
|
+
if (replaced.ok) warmSharedKernel(world, descriptor);
|
|
127
|
+
return replaced;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function worldAddSystems<const Qs extends ReadonlyArray<QueryDescriptor>>(
|
|
131
|
+
world: World,
|
|
132
|
+
token: ScheduleToken,
|
|
133
|
+
set: SystemSet,
|
|
134
|
+
systems: ReadonlyArray<SystemDescriptor<Qs>>,
|
|
135
|
+
): Result<void, SystemSetNotRegisteredError | ScheduleScopeMismatchError> {
|
|
136
|
+
const target = scheduleFor(world, token);
|
|
137
|
+
if (!target.ok) return target;
|
|
138
|
+
const owner = setOwner(world, set);
|
|
139
|
+
if (owner && owner !== token) return scopeError(token, owner, set.name);
|
|
140
|
+
const added = scheduleAddSystems(target.value, set, systems);
|
|
141
|
+
if (added.ok) {
|
|
142
|
+
for (const system of systems) warmSharedKernel(world, system);
|
|
143
|
+
}
|
|
144
|
+
return added;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function validateScheduleReferences(
|
|
148
|
+
world: World,
|
|
149
|
+
token: ScheduleToken,
|
|
150
|
+
schedule: Schedule,
|
|
151
|
+
): ScheduleScopeMismatchError | undefined {
|
|
152
|
+
for (const record of schedule.systems.values()) {
|
|
153
|
+
for (const reference of [
|
|
154
|
+
...(record.descriptor.before ?? []),
|
|
155
|
+
...(record.descriptor.after ?? []),
|
|
156
|
+
]) {
|
|
157
|
+
if (isScheduleToken(reference)) {
|
|
158
|
+
const isFixedAnchor = token === Update && reference === FixedUpdate;
|
|
159
|
+
if (reference !== token && !isFixedAnchor) {
|
|
160
|
+
return new ScheduleScopeMismatchError(token.name, reference.name, reference.name);
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (typeof reference === 'string') {
|
|
165
|
+
for (const [otherToken, other] of world[worldInternal].getSchedules()) {
|
|
166
|
+
if (otherToken !== token && other.systems.has(reference)) {
|
|
167
|
+
return new ScheduleScopeMismatchError(token.name, otherToken.name, reference);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function runFixed(
|
|
177
|
+
world: World,
|
|
178
|
+
fixed: MutableFixedTimeResource,
|
|
179
|
+
accumulator: { value: number },
|
|
180
|
+
): void {
|
|
181
|
+
const fixedSchedule = world[worldInternal].getSchedule(FixedUpdate) as Schedule | undefined;
|
|
182
|
+
if (!fixedSchedule) return;
|
|
183
|
+
if (fixedSchedule.systems.size === 0) {
|
|
184
|
+
discardFixedOverflow(fixed, accumulator);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
let steps = 0;
|
|
188
|
+
while (accumulator.value >= fixed.delta && steps < fixed.maxStepsPerUpdate) {
|
|
189
|
+
accumulator.value = Math.round((accumulator.value - fixed.delta) * 1e12) / 1e12;
|
|
190
|
+
fixed.overstep = accumulator.value;
|
|
191
|
+
fixed.tick += 1;
|
|
192
|
+
runSchedule(fixedSchedule, world);
|
|
193
|
+
steps += 1;
|
|
194
|
+
}
|
|
195
|
+
if (steps === fixed.maxStepsPerUpdate && accumulator.value >= fixed.delta) {
|
|
196
|
+
const remainder = accumulator.value % fixed.delta;
|
|
197
|
+
const dropped = accumulator.value - remainder;
|
|
198
|
+
accumulator.value = remainder;
|
|
199
|
+
fixed.droppedSeconds += dropped;
|
|
200
|
+
fixed.droppedUpdates += 1;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function discardFixedOverflow(
|
|
205
|
+
fixed: MutableFixedTimeResource,
|
|
206
|
+
accumulator: { value: number },
|
|
207
|
+
): void {
|
|
208
|
+
if (accumulator.value < fixed.delta) return;
|
|
209
|
+
const remainder = accumulator.value % fixed.delta;
|
|
210
|
+
const dropped = accumulator.value - remainder;
|
|
211
|
+
accumulator.value = remainder;
|
|
212
|
+
fixed.droppedSeconds += dropped;
|
|
213
|
+
fixed.droppedUpdates += 1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function worldUpdate(
|
|
217
|
+
world: World,
|
|
218
|
+
deltaSeconds = 0,
|
|
219
|
+
): Result<
|
|
220
|
+
void,
|
|
221
|
+
| TimeDeltaInvalidError
|
|
222
|
+
| TimeConfigInvalidError
|
|
223
|
+
| ScheduleScopeMismatchError
|
|
224
|
+
| WorldPoisonedError
|
|
225
|
+
| CommandFailedError
|
|
226
|
+
| SystemFailedError
|
|
227
|
+
| CyclicDependencyError
|
|
228
|
+
| SharedKernelFailureError
|
|
229
|
+
> {
|
|
230
|
+
if (world.execution.health === 'poisoned') {
|
|
231
|
+
return err(new WorldPoisonedError(world.identity, world.execution.fault));
|
|
232
|
+
}
|
|
233
|
+
if (!Number.isFinite(deltaSeconds) || deltaSeconds < 0)
|
|
234
|
+
return err(new TimeDeltaInvalidError(deltaSeconds));
|
|
235
|
+
|
|
236
|
+
const writer = world[worldInternal].getClockWriter();
|
|
237
|
+
const time = writer.time;
|
|
238
|
+
const fixed = writer.fixed;
|
|
239
|
+
if (time.maxDeltaSeconds < (fixed.maxStepsPerUpdate + 1) * fixed.delta) {
|
|
240
|
+
return err(
|
|
241
|
+
new TimeConfigInvalidError({
|
|
242
|
+
fixedDeltaSeconds: fixed.delta,
|
|
243
|
+
maxStepsPerUpdate: fixed.maxStepsPerUpdate,
|
|
244
|
+
maxDeltaSeconds: time.maxDeltaSeconds,
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (const [token, schedule] of world[worldInternal].getSchedules()) {
|
|
250
|
+
const mismatch = validateScheduleReferences(world, token, schedule);
|
|
251
|
+
if (mismatch) return err(mismatch);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const measured = Math.min(deltaSeconds, time.maxDeltaSeconds);
|
|
255
|
+
time.delta = measured;
|
|
256
|
+
time.elapsed += measured;
|
|
257
|
+
// Accumulate the measured frame delta. maxDeltaSeconds bounds Time's public
|
|
258
|
+
// delta, while the fixed cap makes oversized host gaps observable via metrics.
|
|
259
|
+
const accumulator = { value: world[worldInternal].getFixedAccumulator() + measured };
|
|
260
|
+
const update = world[worldInternal].getSchedule(Update) as Schedule | undefined;
|
|
261
|
+
if (!update) return err(new ScheduleScopeMismatchError('World', Update.name));
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
if (update.dirty) buildSchedule(update);
|
|
265
|
+
const order = update.sortedOrder;
|
|
266
|
+
const anchor = order.indexOf(FIXED_ANCHOR_NAME);
|
|
267
|
+
const fixedSchedule = world[worldInternal].getSchedule(FixedUpdate) as Schedule | undefined;
|
|
268
|
+
const hasFixedSystems = (fixedSchedule?.systems.size ?? 0) > 0;
|
|
269
|
+
if (anchor < 0 || !hasFixedSystems) {
|
|
270
|
+
runSchedule(
|
|
271
|
+
update,
|
|
272
|
+
world,
|
|
273
|
+
order.filter((name) => name !== FIXED_ANCHOR_NAME),
|
|
274
|
+
);
|
|
275
|
+
if (measured > 0) discardFixedOverflow(fixed, accumulator);
|
|
276
|
+
} else {
|
|
277
|
+
const updateCommands = new Map<string, CommandBufferImpl>();
|
|
278
|
+
runSchedule(update, world, order.slice(0, anchor), updateCommands, false);
|
|
279
|
+
if (measured > 0) runFixed(world, fixed, accumulator);
|
|
280
|
+
runSchedule(update, world, order.slice(anchor + 1), updateCommands);
|
|
281
|
+
}
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (error instanceof CommandFailedError || error instanceof SystemFailedError) {
|
|
284
|
+
return err(error);
|
|
285
|
+
}
|
|
286
|
+
if (error instanceof CyclicDependencyError || error instanceof SharedKernelFailureError) {
|
|
287
|
+
return err(error);
|
|
288
|
+
}
|
|
289
|
+
if (world.execution.health === 'healthy') {
|
|
290
|
+
world[worldInternal].poisonExecution({
|
|
291
|
+
code: 'shared-kernel-failed',
|
|
292
|
+
kernelName: `schedule:${Update.name}`,
|
|
293
|
+
cause: error,
|
|
294
|
+
partialWrite: true,
|
|
295
|
+
retryable: false,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return err(new SystemFailedError('<schedule>', Update.name, error));
|
|
299
|
+
}
|
|
300
|
+
world[worldInternal].setFixedAccumulator(accumulator.value);
|
|
301
|
+
fixed.overstep = accumulator.value;
|
|
302
|
+
return ok(undefined);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function worldInsertResource<T>(world: World, key: ResourceKey, value: T): void {
|
|
306
|
+
const name = resourceName(key);
|
|
307
|
+
if (name === TIME_RESOURCE_KEY || name === FIXED_TIME_RESOURCE_KEY) {
|
|
308
|
+
throw new ProtectedResourceError(name, 'insert');
|
|
309
|
+
}
|
|
310
|
+
resInsert(
|
|
311
|
+
world[worldInternal].getResources(),
|
|
312
|
+
name,
|
|
313
|
+
value,
|
|
314
|
+
world[worldInternal].nextMutationEpoch(),
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function worldGetResource<T>(world: World, key: ResourceKey): T {
|
|
319
|
+
return resGet<T>(world[worldInternal].getResources(), resourceName(key));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function worldHasResource(world: World, key: ResourceKey): boolean {
|
|
323
|
+
return resHas(world[worldInternal].getResources(), resourceName(key));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function worldRemoveResource(world: World, key: ResourceKey): void {
|
|
327
|
+
const name = resourceName(key);
|
|
328
|
+
if (name === TIME_RESOURCE_KEY || name === FIXED_TIME_RESOURCE_KEY) {
|
|
329
|
+
throw new ProtectedResourceError(name, 'remove');
|
|
330
|
+
}
|
|
331
|
+
if (resHas(world[worldInternal].getResources(), name)) {
|
|
332
|
+
resRemove(world[worldInternal].getResources(), name);
|
|
333
|
+
world[worldInternal].nextMutationEpoch();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function worldInspect(world: World): WorldInspection {
|
|
338
|
+
const graph = world[worldInternal].getGraph() as ArchetypeGraph;
|
|
339
|
+
const resources = world[worldInternal].getResources();
|
|
340
|
+
let entityCount = 0;
|
|
341
|
+
const archetypes: WorldInspection['archetypes'] = [];
|
|
342
|
+
const activeComponentSet = new Set<string>();
|
|
343
|
+
for (const arch of graph.archetypes) {
|
|
344
|
+
if (!arch) continue;
|
|
345
|
+
entityCount += arch.size;
|
|
346
|
+
const componentNames = arch.components.map((component) => component.name);
|
|
347
|
+
archetypes.push({
|
|
348
|
+
key: arch.key,
|
|
349
|
+
componentNames,
|
|
350
|
+
entityCount: arch.size,
|
|
351
|
+
tableId: arch.tableId,
|
|
352
|
+
});
|
|
353
|
+
if (arch.size > 0) for (const name of componentNames) activeComponentSet.add(name);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const schedules = [
|
|
357
|
+
...(world[worldInternal].getSchedules() as ReadonlyMap<ScheduleToken, Schedule>),
|
|
358
|
+
].map(([token, schedule]) => {
|
|
359
|
+
const systems = [...schedule.systems.entries()]
|
|
360
|
+
.filter(([name]) => name !== FIXED_ANCHOR_NAME)
|
|
361
|
+
.map(([name]) => ({
|
|
362
|
+
name,
|
|
363
|
+
sets: [...schedule.sets].flatMap(([setName, record]) =>
|
|
364
|
+
record.members.has(name) ? [setName] : [],
|
|
365
|
+
),
|
|
366
|
+
}));
|
|
367
|
+
return { schedule: token, systems };
|
|
368
|
+
});
|
|
369
|
+
const systems = schedules.flatMap((entry) => entry.systems);
|
|
370
|
+
const tables = graph.tables.map((table) => ({
|
|
371
|
+
id: table.id,
|
|
372
|
+
key: table.key,
|
|
373
|
+
componentNames: table.components.map((component) => component.name),
|
|
374
|
+
entityCount: table.size,
|
|
375
|
+
capacity: table.capacity,
|
|
376
|
+
}));
|
|
377
|
+
return {
|
|
378
|
+
entityCount,
|
|
379
|
+
archetypeCount: archetypes.length,
|
|
380
|
+
archetypes,
|
|
381
|
+
tableCount: tables.length,
|
|
382
|
+
tables,
|
|
383
|
+
activeComponents: [...activeComponentSet],
|
|
384
|
+
systemCount: systems.length,
|
|
385
|
+
systems,
|
|
386
|
+
resourceKeys: [...resources.entries.keys()],
|
|
387
|
+
schedules,
|
|
388
|
+
scheduleSystemCount(token: ScheduleToken): number {
|
|
389
|
+
return schedules.find((entry) => entry.schedule === token)?.systems.length ?? 0;
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function referenceName(reference: string | ScheduleToken): string {
|
|
395
|
+
return typeof reference === 'string' ? reference : reference.name;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function componentNames(components: readonly { readonly name: string }[] | undefined): string[] {
|
|
399
|
+
return (components ?? []).map((component) => component.name);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function queryData(query: QueryDescriptor): WorldScheduleQueryData {
|
|
403
|
+
return {
|
|
404
|
+
with: componentNames(query.with),
|
|
405
|
+
without: componentNames(query.without),
|
|
406
|
+
optional: componentNames(query.optional),
|
|
407
|
+
changed: componentNames(query.changed),
|
|
408
|
+
added: componentNames(query.added),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** Project schedule registration into a JSON-safe graph for tooling and AI inspection. */
|
|
413
|
+
export function worldScheduleData(world: World): ReadonlyArray<WorldScheduleData> {
|
|
414
|
+
return [...(world[worldInternal].getSchedules() as ReadonlyMap<ScheduleToken, Schedule>)].map(
|
|
415
|
+
([token, schedule]) => {
|
|
416
|
+
if (schedule.dirty) buildSchedule(schedule);
|
|
417
|
+
|
|
418
|
+
const systems: WorldScheduleSystemData[] = [...schedule.systems.entries()]
|
|
419
|
+
.filter(([name]) => name !== FIXED_ANCHOR_NAME)
|
|
420
|
+
.map(([name, record]) => {
|
|
421
|
+
const descriptor = record.descriptor;
|
|
422
|
+
const queries = descriptor.queries.map(queryData);
|
|
423
|
+
return {
|
|
424
|
+
name,
|
|
425
|
+
sets: [...schedule.sets].flatMap(([setName, set]) =>
|
|
426
|
+
set.members.has(name) ? [setName] : [],
|
|
427
|
+
),
|
|
428
|
+
before: (descriptor.before ?? []).map((reference) => referenceName(reference)),
|
|
429
|
+
after: (descriptor.after ?? []).map((reference) => referenceName(reference)),
|
|
430
|
+
queries,
|
|
431
|
+
resources: [],
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const systemSets = [...schedule.sets].map(([name, set]) => ({
|
|
436
|
+
name,
|
|
437
|
+
members: [...set.members].filter((member) => schedule.systems.has(member)),
|
|
438
|
+
before: [],
|
|
439
|
+
after: [],
|
|
440
|
+
chained: set.chained,
|
|
441
|
+
}));
|
|
442
|
+
const dependencies = [...schedule.predecessors].flatMap(([target, predecessors]) =>
|
|
443
|
+
[...predecessors].map((source) => [source, target] as const),
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
return { name: token.name, systems, systemSets, dependencies };
|
|
447
|
+
},
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function queryUsesComponent(query: QueryDescriptor, component: object): boolean {
|
|
452
|
+
return [
|
|
453
|
+
query.read,
|
|
454
|
+
query.write,
|
|
455
|
+
query.optional,
|
|
456
|
+
query.with,
|
|
457
|
+
query.without,
|
|
458
|
+
query.changed,
|
|
459
|
+
query.added,
|
|
460
|
+
].some((items) => items?.includes(component as never) === true);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Control-plane guard used before releasing a World-local component registration. */
|
|
464
|
+
export function worldScheduleUsesComponent(world: World, component: object): boolean {
|
|
465
|
+
for (const schedule of (
|
|
466
|
+
world[worldInternal].getSchedules() as ReadonlyMap<ScheduleToken, Schedule>
|
|
467
|
+
).values()) {
|
|
468
|
+
for (const record of schedule.systems.values()) {
|
|
469
|
+
if (record.descriptor.queries.some((query) => queryUsesComponent(query, component)))
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export function worldAllocUniqueRef<Target extends string, T>(
|
|
477
|
+
world: World,
|
|
478
|
+
target: Target,
|
|
479
|
+
payload: T,
|
|
480
|
+
onRelease?: (payload: T) => void,
|
|
481
|
+
): Handle<Target, 'unique'> {
|
|
482
|
+
return world[worldInternal].getUniqueRefs().alloc(target, payload, onRelease);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export function worldAllocSharedRef<Target extends string, T>(
|
|
486
|
+
world: World,
|
|
487
|
+
target: Target,
|
|
488
|
+
payload: T,
|
|
489
|
+
): Handle<Target, 'shared'> {
|
|
490
|
+
return world[worldInternal].getSharedRefs().alloc(target, payload);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export function worldInternSharedRef<Target extends string, T extends object>(
|
|
494
|
+
world: World,
|
|
495
|
+
target: Target,
|
|
496
|
+
payload: T,
|
|
497
|
+
): Handle<Target, 'shared'> {
|
|
498
|
+
return world[worldInternal].getSharedRefs().intern(target, payload);
|
|
499
|
+
}
|