@forgeax/engine-ecs 0.1.20 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -16
- package/dist/__tests__/changed-block-summary.candidate.test.d.ts +2 -0
- package/dist/__tests__/changed-block-summary.candidate.test.d.ts.map +1 -0
- package/dist/__tests__/component-requirements.unit.test.d.ts +2 -0
- package/dist/__tests__/component-requirements.unit.test.d.ts.map +1 -0
- package/dist/__tests__/component-version-surface.test.d.ts +2 -0
- package/dist/__tests__/component-version-surface.test.d.ts.map +1 -0
- package/dist/__tests__/derived-range-writer.contract.test-d.d.ts +2 -0
- package/dist/__tests__/derived-range-writer.contract.test-d.d.ts.map +1 -0
- package/dist/__tests__/derived-range-writer.contract.test.d.ts +2 -0
- package/dist/__tests__/derived-range-writer.contract.test.d.ts.map +1 -0
- package/dist/__tests__/structural-evidence.contract.test-d.d.ts +2 -0
- package/dist/__tests__/structural-evidence.contract.test-d.d.ts.map +1 -0
- package/dist/__tests__/structural-evidence.contract.test.d.ts +2 -0
- package/dist/__tests__/structural-evidence.contract.test.d.ts.map +1 -0
- package/dist/component-schema.d.ts +17 -0
- package/dist/component-schema.d.ts.map +1 -1
- package/dist/component.d.ts +7 -1
- package/dist/component.d.ts.map +1 -1
- package/dist/errors/query-and-component-errors.d.ts +1 -1
- package/dist/errors/query-and-component-errors.d.ts.map +1 -1
- package/dist/errors/validation-errors.d.ts +24 -0
- package/dist/errors/validation-errors.d.ts.map +1 -1
- package/dist/errors.d.ts +14 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/externalization/index.mjs.map +1 -1
- package/dist/index.mjs +415 -128
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +16 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.mjs +15 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/projection/index.d.ts +27 -52
- package/dist/projection/index.d.ts.map +1 -1
- package/dist/projection/index.mjs +66 -76
- package/dist/projection/index.mjs.map +1 -1
- package/dist/query/derived-range-writer.d.ts +48 -0
- package/dist/query/derived-range-writer.d.ts.map +1 -0
- package/dist/query/query.d.ts +1 -1
- package/dist/query/query.d.ts.map +1 -1
- package/dist/relationship-index.d.ts +8 -0
- package/dist/relationship-index.d.ts.map +1 -1
- package/dist/shared-ref-store.d.ts +5 -9
- package/dist/shared-ref-store.d.ts.map +1 -1
- package/dist/shared.mjs.map +1 -1
- package/dist/storage/change-detection.d.ts +1 -3
- package/dist/storage/change-detection.d.ts.map +1 -1
- package/dist/storage/structural-evidence.d.ts +30 -0
- package/dist/storage/structural-evidence.d.ts.map +1 -0
- package/dist/world-component-access.d.ts +4 -3
- package/dist/world-component-access.d.ts.map +1 -1
- package/dist/world-core.d.ts +2 -2
- package/dist/world-core.d.ts.map +1 -1
- package/dist/world-entity-lifecycle.d.ts.map +1 -1
- package/dist/world-internal.d.ts +1 -1
- package/dist/world-internal.d.ts.map +1 -1
- package/dist/world.d.ts +10 -14
- package/dist/world.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/changed-block-summary.candidate.test.ts +57 -0
- package/src/__tests__/component-requirements.unit.test.ts +76 -0
- package/src/__tests__/component-version-surface.test.ts +45 -0
- package/src/__tests__/derived-range-writer.contract.test-d.ts +35 -0
- package/src/__tests__/derived-range-writer.contract.test.ts +339 -0
- package/src/__tests__/errors.unit.test.ts +21 -5
- package/src/__tests__/externalization-render-read-lease.test-d.ts +1 -1
- package/src/__tests__/externalization-render-read-lease.unit.test.ts +15 -15
- package/src/__tests__/query-storage-trends.perf.test.ts +19 -0
- package/src/__tests__/query.unit.test.ts +10 -6
- package/src/__tests__/shared-ref-store.unit.test.ts +3 -8
- package/src/__tests__/structural-evidence.contract.test-d.ts +6 -0
- package/src/__tests__/structural-evidence.contract.test.ts +49 -0
- package/src/component-schema.ts +51 -0
- package/src/component.ts +12 -2
- package/src/errors/query-and-component-errors.ts +1 -1
- package/src/errors/validation-errors.ts +30 -0
- package/src/errors.ts +29 -5
- package/src/internal.ts +56 -0
- package/src/projection/index.ts +68 -149
- package/src/query/derived-range-writer.ts +332 -0
- package/src/query/query.ts +89 -15
- package/src/relationship-index.ts +13 -1
- package/src/shared-ref-store.ts +16 -24
- package/src/storage/change-detection.ts +0 -15
- package/src/storage/structural-evidence.ts +64 -0
- package/src/world-component-access.ts +53 -5
- package/src/world-core.ts +2 -2
- package/src/world-entity-lifecycle.ts +10 -1
- package/src/world-internal.ts +5 -5
- package/src/world.ts +45 -50
- package/dist/.tsbuildinfo +0 -1
- package/dist/__tests__/world-change-journal.unit.test.d.ts +0 -2
- package/dist/__tests__/world-change-journal.unit.test.d.ts.map +0 -1
- package/dist/__tests__/world-internal-identity.unit.test.d.ts +0 -2
- package/dist/__tests__/world-internal-identity.unit.test.d.ts.map +0 -1
- package/dist/world-change-journal.d.ts +0 -34
- package/dist/world-change-journal.d.ts.map +0 -1
- package/src/__tests__/world-change-journal.unit.test.ts +0 -97
- package/src/__tests__/world-internal-identity.unit.test.ts +0 -17
- package/src/world-change-journal.ts +0 -84
|
@@ -2,35 +2,12 @@ import type { Result } from '@forgeax/engine-types';
|
|
|
2
2
|
import type { Component } from '../component';
|
|
3
3
|
import type { EntityHandle } from '../entity-handle';
|
|
4
4
|
import type { SharedRefMutationRead } from '../shared-ref-store';
|
|
5
|
-
import type {
|
|
5
|
+
import type { StructuralEvidenceRead } from '../storage/structural-evidence';
|
|
6
6
|
import type { EcsError, World } from '../world';
|
|
7
7
|
export { fillComponentDefaults } from '../component-default-fallback';
|
|
8
8
|
export { ComponentNotDefinedError, InstanceTransformsStrideMismatchError, ManagedBufferOutOfBoundsError, ResourceInvalidValueError, SpawnLightInvalidBoundsError, SpriteAnimationInvalidError, SpriteInstancesCountMismatchError, SpriteInstancesMutuallyExclusiveWithInstancesError, SpriteInstancesRequiresSpriteShaderError, StaleEntityError, } from '../errors';
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
readonly entity: EntityHandle;
|
|
12
|
-
readonly kind: ProjectionChangeKind;
|
|
13
|
-
/** Token identity is the owner-facing component discriminator. */
|
|
14
|
-
readonly component?: Component;
|
|
15
|
-
/** Numeric id remains journal evidence for ECS-internal consumers. */
|
|
16
|
-
readonly componentId?: number;
|
|
17
|
-
}
|
|
18
|
-
export type ProjectionRead = {
|
|
19
|
-
readonly status: 'delta';
|
|
20
|
-
readonly cursor: number;
|
|
21
|
-
readonly changes: readonly ProjectionChange[];
|
|
22
|
-
} | {
|
|
23
|
-
readonly status: 'rebuild';
|
|
24
|
-
readonly cursor: number;
|
|
25
|
-
readonly reason: 'journal-overflow';
|
|
26
|
-
};
|
|
27
|
-
export interface WorldProjection {
|
|
28
|
-
readonly cursor: number;
|
|
29
|
-
poll(): ProjectionRead;
|
|
30
|
-
}
|
|
31
|
-
export interface WorldProjectionOptions {
|
|
32
|
-
readonly components?: readonly Component[];
|
|
33
|
-
}
|
|
9
|
+
/** Read producer-owned typed structural facts without inferring from a World scan. */
|
|
10
|
+
export declare function readStructuralEvidence(world: World, cursor: number): StructuralEvidenceRead;
|
|
34
11
|
export interface RenderProjectionComponentRequest {
|
|
35
12
|
readonly component: Component;
|
|
36
13
|
readonly fields: readonly string[];
|
|
@@ -49,29 +26,30 @@ export interface RenderProjectionSpans {
|
|
|
49
26
|
}
|
|
50
27
|
export interface RenderChangeBatchOk {
|
|
51
28
|
readonly status: 'ok';
|
|
52
|
-
readonly
|
|
53
|
-
readonly world:
|
|
54
|
-
|
|
55
|
-
}>;
|
|
56
|
-
readonly sharedRefs: Extract<SharedRefMutationRead, {
|
|
57
|
-
readonly status: 'ok';
|
|
58
|
-
}>;
|
|
29
|
+
readonly version: RenderReadVersion;
|
|
30
|
+
readonly world: RenderWorldChanges;
|
|
31
|
+
readonly sharedRefs: SharedRefMutationRead;
|
|
59
32
|
}
|
|
60
|
-
export interface
|
|
61
|
-
readonly status: '
|
|
62
|
-
readonly
|
|
33
|
+
export interface RenderChangeBatchRebuild {
|
|
34
|
+
readonly status: 'rebuild';
|
|
35
|
+
readonly version: RenderReadVersion;
|
|
63
36
|
readonly resync: true;
|
|
64
|
-
readonly
|
|
65
|
-
readonly world:
|
|
37
|
+
readonly reason: 'structure-changed';
|
|
38
|
+
readonly world: RenderWorldChanges;
|
|
66
39
|
readonly sharedRefs: SharedRefMutationRead;
|
|
67
40
|
}
|
|
68
|
-
export
|
|
41
|
+
export interface RenderWorldChanges {
|
|
42
|
+
readonly fromEpoch: number;
|
|
43
|
+
readonly toEpoch: number;
|
|
44
|
+
readonly changedComponentIds: readonly number[];
|
|
45
|
+
}
|
|
46
|
+
export type RenderChangeBatch = RenderChangeBatchOk | RenderChangeBatchRebuild;
|
|
69
47
|
export interface RenderReadLease {
|
|
70
48
|
readonly worldIdentity: string;
|
|
71
49
|
readonly generation: number;
|
|
72
|
-
readChanges(
|
|
50
|
+
readChanges(version: RenderReadVersion): RenderChangeBatch;
|
|
73
51
|
querySpans(request: RenderProjectionRequest): RenderProjectionSpans;
|
|
74
|
-
|
|
52
|
+
captureVersion(): RenderReadVersion;
|
|
75
53
|
dispose(): void;
|
|
76
54
|
}
|
|
77
55
|
/**
|
|
@@ -80,24 +58,21 @@ export interface RenderReadLease {
|
|
|
80
58
|
* transform/instance columns; the World internals remain owned by ECS.
|
|
81
59
|
*/
|
|
82
60
|
export declare function readRenderArrayView(world: World, entity: EntityHandle, component: Component, fieldName: string): ArrayLike<number> | undefined;
|
|
61
|
+
export interface RenderReadVersion {
|
|
62
|
+
readonly mutationEpoch: number;
|
|
63
|
+
readonly structureEpoch: number;
|
|
64
|
+
readonly sharedRefEpoch: number;
|
|
65
|
+
}
|
|
83
66
|
/** Create the render-owned lease from the ECS projection boundary. */
|
|
84
67
|
export declare function createRenderReadLease(world: World, token?: object): RenderReadLease;
|
|
85
68
|
/**
|
|
86
|
-
* Publish one owner-derived component value
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* storage, while the journal records a `derived-component-changed` fact for
|
|
90
|
-
* incremental projections.
|
|
69
|
+
* Publish one owner-derived component value through the component's ordinary
|
|
70
|
+
* version. Numeric consumers observe the same row epoch regardless of which
|
|
71
|
+
* owner computed the value; there is no parallel derived-change vocabulary.
|
|
91
72
|
*/
|
|
92
73
|
export declare function setDerivedComponent(world: World, entity: EntityHandle, component: Component, value: Record<string, unknown>): Result<void, EcsError>;
|
|
93
74
|
/** Route an owner-domain error through the World without exposing raw internals. */
|
|
94
75
|
export declare function routeWorldError(world: World, error: unknown, context?: {
|
|
95
76
|
readonly systemName: string;
|
|
96
77
|
}): void;
|
|
97
|
-
/**
|
|
98
|
-
* Create the narrow incremental evidence surface for an owner projection.
|
|
99
|
-
* Rebuilds intentionally return a reason; complete data always comes from
|
|
100
|
-
* the owner's regular Query/QuerySpan path.
|
|
101
|
-
*/
|
|
102
|
-
export declare function createWorldProjection(world: World, options?: WorldProjectionOptions): WorldProjection;
|
|
103
78
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/projection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/projection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBA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ACjC;AAoCD,sEAAsE;AACtE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAE,MAAW,GAAG,eAAe,CAqEvF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAKxB;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxC,IAAI,CAEN"}
|
|
@@ -122,6 +122,30 @@ var SpriteInstancesMutuallyExclusiveWithInstancesError = class extends Error {
|
|
|
122
122
|
|
|
123
123
|
// src/errors/validation-errors.ts
|
|
124
124
|
var SPAWN_LIGHT_INVALID_BOUNDS_POLICY = {
|
|
125
|
+
intensity: {
|
|
126
|
+
expected: "intensity is finite and >= 0",
|
|
127
|
+
hint: (componentName, got) => `${componentName}.intensity must be a finite non-negative number (got ${got})`
|
|
128
|
+
},
|
|
129
|
+
color: {
|
|
130
|
+
expected: "color is a finite non-negative [r, g, b] vector",
|
|
131
|
+
hint: (componentName, got) => `${componentName}.color must contain three finite non-negative channels (got ${JSON.stringify(got)})`
|
|
132
|
+
},
|
|
133
|
+
width: {
|
|
134
|
+
expected: "width is finite and > 0",
|
|
135
|
+
hint: (componentName, got) => `${componentName}.width must be a finite positive meter value (got ${got})`
|
|
136
|
+
},
|
|
137
|
+
height: {
|
|
138
|
+
expected: "height is finite and > 0",
|
|
139
|
+
hint: (componentName, got) => `${componentName}.height must be a finite positive meter value (got ${got})`
|
|
140
|
+
},
|
|
141
|
+
irradiance: {
|
|
142
|
+
expected: "irradiance is a finite 27-value SH vector",
|
|
143
|
+
hint: (componentName, got) => `${componentName}.irradiance must contain 27 finite SH values (got ${JSON.stringify(got)})`
|
|
144
|
+
},
|
|
145
|
+
radius: {
|
|
146
|
+
expected: "radius is finite and >= R_MIN",
|
|
147
|
+
hint: (componentName, got) => `${componentName}.radius must be a finite value >= R_MIN (got ${got})`
|
|
148
|
+
},
|
|
125
149
|
range: {
|
|
126
150
|
expected: "range >= 0 or Number.POSITIVE_INFINITY",
|
|
127
151
|
hint: (componentName, got) => `${componentName}.range = ${got} is invalid; use Number.POSITIVE_INFINITY for unlimited range, or a non-negative meter value`
|
|
@@ -467,6 +491,9 @@ function fillComponentDefaults(token, raw) {
|
|
|
467
491
|
}
|
|
468
492
|
|
|
469
493
|
// src/projection/index.ts
|
|
494
|
+
function readStructuralEvidence(world, cursor) {
|
|
495
|
+
return world[worldInternal].getStructuralEvidence().readAfter(cursor);
|
|
496
|
+
}
|
|
470
497
|
function readRenderArrayView(world, entity, component, fieldName) {
|
|
471
498
|
return world[worldInternal].getArrayView(entity, component, fieldName);
|
|
472
499
|
}
|
|
@@ -501,115 +528,78 @@ function readProjectionSpans(world, generation, request) {
|
|
|
501
528
|
}
|
|
502
529
|
function createRenderReadLease(world, token = {}) {
|
|
503
530
|
const sharedRefs = world[worldInternal].getSharedRefs();
|
|
504
|
-
const generation = Math.max(1, world[worldInternal].getStructureEpoch());
|
|
505
531
|
let disposed = false;
|
|
506
|
-
let nextCursor = 1;
|
|
507
|
-
const cursors = /* @__PURE__ */ new Map([
|
|
508
|
-
[
|
|
509
|
-
0,
|
|
510
|
-
{ world: world[worldInternal].getChangeCursor(), sharedRefs: sharedRefs.getMutationEpoch() }
|
|
511
|
-
]
|
|
512
|
-
]);
|
|
513
532
|
const assertLive = () => {
|
|
514
533
|
if (disposed) throw new Error("RenderReadLease is disposed.");
|
|
515
534
|
};
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
if (cursors.size > 8) {
|
|
523
|
-
const oldest = cursors.keys().next().value;
|
|
524
|
-
if (typeof oldest === "number" && oldest !== cursor) cursors.delete(oldest);
|
|
525
|
-
}
|
|
526
|
-
return cursor;
|
|
535
|
+
const captureVersion = () => {
|
|
536
|
+
return {
|
|
537
|
+
mutationEpoch: world[worldInternal].getMutationEpoch(),
|
|
538
|
+
structureEpoch: world[worldInternal].getStructureEpoch(),
|
|
539
|
+
sharedRefEpoch: sharedRefs.getMutationEpoch()
|
|
540
|
+
};
|
|
527
541
|
};
|
|
528
542
|
return {
|
|
529
543
|
worldIdentity: world.identity,
|
|
530
|
-
generation
|
|
531
|
-
|
|
544
|
+
get generation() {
|
|
545
|
+
return Math.max(1, world[worldInternal].getStructureEpoch());
|
|
546
|
+
},
|
|
547
|
+
captureVersion() {
|
|
532
548
|
assertLive();
|
|
533
|
-
return
|
|
549
|
+
return captureVersion();
|
|
534
550
|
},
|
|
535
|
-
readChanges(
|
|
551
|
+
readChanges(start) {
|
|
536
552
|
assertLive();
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
553
|
+
const toEpoch = world[worldInternal].getMutationEpoch();
|
|
554
|
+
const componentEpochs = world[worldInternal].getComponentMutationEpochs();
|
|
555
|
+
const changedComponentIds = [];
|
|
556
|
+
for (let componentId2 = 0; componentId2 < componentEpochs.length; componentId2 += 1) {
|
|
557
|
+
const epoch = componentEpochs[componentId2] ?? 0;
|
|
558
|
+
if (epoch > start.mutationEpoch && epoch <= toEpoch) changedComponentIds.push(componentId2);
|
|
559
|
+
}
|
|
560
|
+
const worldRead = {
|
|
561
|
+
fromEpoch: start.mutationEpoch,
|
|
562
|
+
toEpoch,
|
|
563
|
+
changedComponentIds
|
|
564
|
+
};
|
|
565
|
+
const sharedRead = sharedRefs.readChangesSince(start.sharedRefEpoch);
|
|
566
|
+
const version = captureVersion();
|
|
567
|
+
const structureChanged = start.structureEpoch !== world[worldInternal].getStructureEpoch();
|
|
568
|
+
if (structureChanged) {
|
|
547
569
|
return {
|
|
548
|
-
status: "
|
|
549
|
-
|
|
570
|
+
status: "rebuild",
|
|
571
|
+
version,
|
|
550
572
|
resync: true,
|
|
551
|
-
|
|
573
|
+
reason: "structure-changed",
|
|
552
574
|
world: worldRead,
|
|
553
575
|
sharedRefs: sharedRead
|
|
554
576
|
};
|
|
555
577
|
}
|
|
556
|
-
return { status: "ok",
|
|
578
|
+
return { status: "ok", version, world: worldRead, sharedRefs: sharedRead };
|
|
557
579
|
},
|
|
558
580
|
querySpans(request) {
|
|
559
581
|
assertLive();
|
|
560
|
-
return readProjectionSpans(
|
|
582
|
+
return readProjectionSpans(
|
|
583
|
+
world,
|
|
584
|
+
Math.max(1, world[worldInternal].getStructureEpoch()),
|
|
585
|
+
request
|
|
586
|
+
);
|
|
561
587
|
},
|
|
562
588
|
dispose() {
|
|
563
589
|
disposed = true;
|
|
564
|
-
cursors.clear();
|
|
565
590
|
}
|
|
566
591
|
};
|
|
567
592
|
}
|
|
568
593
|
function setDerivedComponent(world, entity, component, value) {
|
|
569
594
|
const result = world[worldInternal].setQueryRow(entity, component, value);
|
|
570
595
|
if (!result.ok) return result;
|
|
571
|
-
world[worldInternal].
|
|
596
|
+
world[worldInternal].markComponentChanged(entity, componentId(component));
|
|
572
597
|
return result;
|
|
573
598
|
}
|
|
574
599
|
function routeWorldError(world, error, context) {
|
|
575
600
|
world[worldInternal].routeError(error, context);
|
|
576
601
|
}
|
|
577
|
-
function createWorldProjection(world, options = {}) {
|
|
578
|
-
const componentById = options.components === void 0 ? void 0 : new Map(options.components.map((component) => [componentId(component), component]));
|
|
579
|
-
const componentIds = componentById === void 0 ? void 0 : new Set(componentById.keys());
|
|
580
|
-
let cursor = world[worldInternal].getChangeCursor();
|
|
581
|
-
const pollSince = (requestedCursor) => {
|
|
582
|
-
const result = world[worldInternal].readChangesSince(requestedCursor);
|
|
583
|
-
if (result.status === "overflow") {
|
|
584
|
-
cursor = result.cursor;
|
|
585
|
-
return { status: "rebuild", cursor, reason: "journal-overflow" };
|
|
586
|
-
}
|
|
587
|
-
cursor = result.cursor;
|
|
588
|
-
const changes = [];
|
|
589
|
-
for (const record of result.records) {
|
|
590
|
-
if (componentIds !== void 0 && record.kind !== "entity-removed" && (record.componentId === void 0 || !componentIds.has(record.componentId))) {
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
const component = record.componentId === void 0 ? void 0 : componentById?.get(record.componentId);
|
|
594
|
-
changes.push({
|
|
595
|
-
entity: record.entity,
|
|
596
|
-
kind: record.kind,
|
|
597
|
-
...component === void 0 ? {} : { component },
|
|
598
|
-
...record.componentId === void 0 ? {} : { componentId: record.componentId }
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
return { status: "delta", cursor, changes };
|
|
602
|
-
};
|
|
603
|
-
return {
|
|
604
|
-
get cursor() {
|
|
605
|
-
return cursor;
|
|
606
|
-
},
|
|
607
|
-
poll() {
|
|
608
|
-
return pollSince(cursor);
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
602
|
|
|
613
|
-
export { ComponentNotDefinedError, InstanceTransformsStrideMismatchError, ManagedBufferOutOfBoundsError, ResourceInvalidValueError, SpawnLightInvalidBoundsError, SpriteAnimationInvalidError, SpriteInstancesCountMismatchError, SpriteInstancesMutuallyExclusiveWithInstancesError, SpriteInstancesRequiresSpriteShaderError, StaleEntityError, createRenderReadLease,
|
|
603
|
+
export { ComponentNotDefinedError, InstanceTransformsStrideMismatchError, ManagedBufferOutOfBoundsError, ResourceInvalidValueError, SpawnLightInvalidBoundsError, SpriteAnimationInvalidError, SpriteInstancesCountMismatchError, SpriteInstancesMutuallyExclusiveWithInstancesError, SpriteInstancesRequiresSpriteShaderError, StaleEntityError, createRenderReadLease, fillComponentDefaults, readRenderArrayView, readStructuralEvidence, routeWorldError, setDerivedComponent };
|
|
614
604
|
//# sourceMappingURL=index.mjs.map
|
|
615
605
|
//# sourceMappingURL=index.mjs.map
|