@vgai/engine 0.5.22 → 0.5.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 +6 -3
- package/dist/adapter/adapter-module.d.ts.map +1 -1
- package/dist/adapter/adapter-module.js +2 -4
- package/dist/adapter/adapter-surface.d.ts +1 -1
- package/dist/adapter/adapter-surface.js +1 -1
- package/dist/adapter/authoring.d.ts +19 -21
- package/dist/adapter/authoring.d.ts.map +1 -1
- package/dist/adapter/authoring.js +2 -2
- package/dist/adapter/binding.d.ts +341 -0
- package/dist/adapter/binding.d.ts.map +1 -0
- package/dist/adapter/binding.js +148 -0
- package/dist/adapter/colyseus-networking-adapter.d.ts.map +1 -1
- package/dist/adapter/colyseus-networking-adapter.js +23 -4
- package/dist/adapter/entrypoint-selection-readers.d.ts +24 -0
- package/dist/adapter/entrypoint-selection-readers.d.ts.map +1 -0
- package/dist/adapter/entrypoint-selection-readers.js +63 -0
- package/dist/adapter/entrypoint-selection-source.d.ts.map +1 -1
- package/dist/adapter/entrypoint-selection-source.js +1 -44
- package/dist/adapter/finders/scenes-from-entrypoint-selection.d.ts.map +1 -1
- package/dist/adapter/finders/scenes-from-entrypoint-selection.js +1 -52
- package/dist/adapter/host-context.d.ts +46 -15
- package/dist/adapter/host-context.d.ts.map +1 -1
- package/dist/adapter/host-context.js +2 -9
- package/dist/adapter/index.d.ts +11 -12
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/adapter/index.js +9 -10
- package/dist/adapter/ingest/game-contract.d.ts +0 -3
- package/dist/adapter/ingest/game-contract.d.ts.map +1 -1
- package/dist/adapter/ingest/game-contract.js +0 -3
- package/dist/adapter/ingest/scene-capture.d.ts +19 -23
- package/dist/adapter/ingest/scene-capture.d.ts.map +1 -1
- package/dist/adapter/ingest/scene-capture.js +143 -17
- package/dist/adapter/ingest/visible-capture-window.d.ts +34 -0
- package/dist/adapter/ingest/visible-capture-window.d.ts.map +1 -1
- package/dist/adapter/native-debug-module.d.ts +31 -5
- package/dist/adapter/native-debug-module.d.ts.map +1 -1
- package/dist/adapter/native-debug-module.js +25 -7
- package/dist/adapter/rapier-physics-adapter.d.ts +31 -1
- package/dist/adapter/rapier-physics-adapter.d.ts.map +1 -1
- package/dist/adapter/rapier-physics-adapter.js +50 -36
- package/dist/adapter/renderer-config.d.ts +2 -2
- package/dist/adapter/renderer-config.js +2 -2
- package/dist/adapter/root-adapter.d.ts +7 -7
- package/dist/adapter/root-adapter.js +4 -4
- package/dist/adapter/system-adapter.d.ts +45 -7
- package/dist/adapter/system-adapter.d.ts.map +1 -1
- package/dist/adapter/system-seam-contract.d.ts +3 -3
- package/dist/adapter/system-seam-contract.js +3 -3
- package/dist/adapter/system-slot.d.ts +168 -0
- package/dist/adapter/system-slot.d.ts.map +1 -0
- package/dist/adapter/system-slot.js +229 -0
- package/dist/adapter/transform.d.ts +11 -1
- package/dist/adapter/transform.d.ts.map +1 -1
- package/dist/ai/navigation.d.ts +17 -1
- package/dist/ai/navigation.d.ts.map +1 -1
- package/dist/ai/navigation.js +26 -5
- package/dist/animation/anim-graph-types.d.ts +11 -3
- package/dist/animation/anim-graph-types.d.ts.map +1 -1
- package/dist/animation/theatre-clock-binding.d.ts +4 -4
- package/dist/animation/theatre-clock-binding.js +4 -4
- package/dist/animation/xstate-animation-binding.d.ts.map +1 -1
- package/dist/animation/xstate-animation-binding.js +2 -2
- package/dist/animation/xstate-animation-meta.d.ts +13 -0
- package/dist/animation/xstate-animation-meta.d.ts.map +1 -1
- package/dist/animation/xstate-animation-meta.js +14 -0
- package/dist/asset-formats/index.d.ts +4 -7
- package/dist/asset-formats/index.d.ts.map +1 -1
- package/dist/asset-formats/index.js +4 -7
- package/dist/asset-formats/render-env.d.ts +5 -8
- package/dist/asset-formats/render-env.d.ts.map +1 -1
- package/dist/asset-formats/render-env.js +3 -6
- package/dist/asset-parse-error.d.ts +2 -5
- package/dist/asset-parse-error.d.ts.map +1 -1
- package/dist/asset-parse-error.js +2 -5
- package/dist/audio/bus-mixer.d.ts +101 -0
- package/dist/audio/bus-mixer.d.ts.map +1 -0
- package/dist/audio/bus-mixer.js +115 -0
- package/dist/core/frame-pacing.d.ts +1 -1
- package/dist/core/frame-pacing.js +2 -2
- package/dist/core/game-loop.d.ts +1 -3
- package/dist/core/game-loop.d.ts.map +1 -1
- package/dist/core/game-loop.js +1 -3
- package/dist/core/seeded-random.d.ts +1 -1
- package/dist/core/sim-clock.d.ts +5 -6
- package/dist/core/sim-clock.d.ts.map +1 -1
- package/dist/core/sim-clock.js +4 -5
- package/dist/core/types.d.ts +1 -3
- package/dist/core/types.d.ts.map +1 -1
- package/dist/defaults.d.ts +6 -14
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +6 -14
- package/dist/dev/register-render-vitals.d.ts +1 -4
- package/dist/dev/register-render-vitals.d.ts.map +1 -1
- package/dist/dev/register-render-vitals.js +1 -4
- package/dist/dev/render-debug-adapter.d.ts +2 -3
- package/dist/dev/render-debug-adapter.d.ts.map +1 -1
- package/dist/dev/render-debug-adapter.js +2 -3
- package/dist/dev/render-vitals.d.ts +3 -3
- package/dist/dev/render-vitals.js +3 -3
- package/dist/dev/webgl-frame-capture.d.ts +1 -1
- package/dist/dev/webgl-frame-capture.js +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/input/host-pointer.d.ts +122 -0
- package/dist/input/host-pointer.d.ts.map +1 -0
- package/dist/input/host-pointer.js +160 -0
- package/dist/input/input-manager.d.ts +18 -5
- package/dist/input/input-manager.d.ts.map +1 -1
- package/dist/input/input-manager.js +33 -13
- package/dist/input/rebind-controller.d.ts.map +1 -1
- package/dist/input/rebind-controller.js +6 -8
- package/dist/input/schema.d.ts.map +1 -1
- package/dist/input/schema.js +56 -28
- package/dist/manifest/filename.d.ts.map +1 -1
- package/dist/manifest/filename.js +8 -12
- package/dist/manifest/load.d.ts +10 -10
- package/dist/manifest/load.d.ts.map +1 -1
- package/dist/manifest/load.js +9 -6
- package/dist/manifest/schema.d.ts +17 -21
- package/dist/manifest/schema.d.ts.map +1 -1
- package/dist/manifest/schema.js +45 -35
- package/dist/physics/collider-dimensions.d.ts +8 -12
- package/dist/physics/collider-dimensions.d.ts.map +1 -1
- package/dist/physics/collider-dimensions.js +8 -12
- package/dist/pixi/scene-capture.d.ts +11 -13
- package/dist/pixi/scene-capture.d.ts.map +1 -1
- package/dist/react/world-state.d.ts +1 -1
- package/dist/react/world-state.d.ts.map +1 -1
- package/dist/render/light-camera-factory.d.ts +5 -7
- package/dist/render/light-camera-factory.d.ts.map +1 -1
- package/dist/render/light-camera-factory.js +8 -11
- package/dist/render/material-factory.js +1 -1
- package/dist/render/render-batch-system.d.ts.map +1 -1
- package/dist/render/render-features.d.ts +17 -6
- package/dist/render/render-features.d.ts.map +1 -1
- package/dist/render/render-features.js +0 -28
- package/dist/runtime/create-runtime.d.ts +34 -25
- package/dist/runtime/create-runtime.d.ts.map +1 -1
- package/dist/runtime/create-runtime.js +218 -93
- package/dist/runtime/debug-registry.d.ts +77 -8
- package/dist/runtime/debug-registry.d.ts.map +1 -1
- package/dist/runtime/debug-registry.js +3 -3
- package/dist/runtime/dev-build.d.ts +2 -2
- package/dist/runtime/dev-build.js +2 -2
- package/dist/runtime/game-input-seams.d.ts +2 -2
- package/dist/runtime/game-input-seams.d.ts.map +1 -1
- package/dist/runtime/game.d.ts +90 -41
- package/dist/runtime/game.d.ts.map +1 -1
- package/dist/runtime/game.js +80 -54
- package/dist/runtime/mount-game.d.ts +0 -16
- package/dist/runtime/mount-game.d.ts.map +1 -1
- package/dist/runtime/mount-game.js +8 -39
- package/dist/runtime/mount-manifest.d.ts +22 -14
- package/dist/runtime/mount-manifest.d.ts.map +1 -1
- package/dist/runtime/mount-manifest.js +18 -18
- package/dist/runtime/playtest.d.ts +22 -0
- package/dist/runtime/playtest.d.ts.map +1 -0
- package/dist/runtime/playtest.js +12 -0
- package/dist/runtime/state-bridge.d.ts +2 -3
- package/dist/runtime/state-bridge.d.ts.map +1 -1
- package/dist/runtime/state-bridge.js +1 -0
- package/dist/setup/setup-audio.d.ts +12 -0
- package/dist/setup/setup-audio.d.ts.map +1 -1
- package/dist/setup/setup-audio.js +9 -10
- package/dist/setup/setup-renderer.d.ts +2 -25
- package/dist/setup/setup-renderer.d.ts.map +1 -1
- package/dist/setup/setup-renderer.js +2 -31
- package/dist/world3d-react/r3f-root-factory.d.ts +7 -7
- package/dist/world3d-react/r3f-root-factory.js +7 -7
- package/dist/world3d-react/rapier-physics-bridge.d.ts +9 -8
- package/dist/world3d-react/rapier-physics-bridge.d.ts.map +1 -1
- package/dist/world3d-react/rapier-physics-bridge.js +100 -48
- package/package.json +1 -1
- package/schemas/engine-capabilities.json +16 -14
- package/schemas/vgai-project.schema.json +35 -26
- package/src/adapter/adapter-module.ts +2 -4
- package/src/adapter/adapter-surface.ts +1 -1
- package/src/adapter/authoring.ts +19 -21
- package/src/adapter/binding.ts +468 -0
- package/src/adapter/colyseus-networking-adapter.ts +20 -5
- package/src/adapter/entrypoint-selection-readers.ts +66 -0
- package/src/adapter/entrypoint-selection-source.ts +1 -40
- package/src/adapter/finders/scenes-from-entrypoint-selection.ts +1 -48
- package/src/adapter/host-context.ts +45 -15
- package/src/adapter/index.ts +23 -11
- package/src/adapter/ingest/game-contract.ts +0 -3
- package/src/adapter/ingest/scene-capture.ts +190 -39
- package/src/adapter/ingest/visible-capture-window.ts +35 -0
- package/src/adapter/native-debug-module.ts +43 -7
- package/src/adapter/rapier-physics-adapter.ts +76 -20
- package/src/adapter/renderer-config.ts +2 -2
- package/src/adapter/root-adapter.ts +7 -7
- package/src/adapter/system-adapter.ts +43 -8
- package/src/adapter/system-seam-contract.ts +3 -3
- package/src/adapter/system-slot.ts +291 -0
- package/src/adapter/transform.ts +18 -1
- package/src/ai/navigation.ts +30 -3
- package/src/animation/anim-graph-types.ts +11 -3
- package/src/animation/theatre-clock-binding.ts +4 -4
- package/src/animation/xstate-animation-binding.ts +2 -2
- package/src/animation/xstate-animation-meta.ts +16 -0
- package/src/asset-formats/index.ts +4 -7
- package/src/asset-formats/render-env.ts +3 -6
- package/src/asset-parse-error.ts +2 -5
- package/src/audio/bus-mixer.ts +161 -0
- package/src/core/frame-pacing.ts +2 -2
- package/src/core/game-loop.ts +1 -3
- package/src/core/seeded-random.ts +1 -1
- package/src/core/sim-clock.ts +5 -6
- package/src/core/types.ts +1 -3
- package/src/defaults.ts +6 -14
- package/src/dev/register-render-vitals.ts +1 -4
- package/src/dev/render-debug-adapter.ts +2 -3
- package/src/dev/render-vitals.ts +3 -3
- package/src/dev/webgl-frame-capture.ts +1 -1
- package/src/index.ts +2 -5
- package/src/input/host-pointer.ts +230 -0
- package/src/input/input-manager.ts +34 -13
- package/src/input/input-types.ts +1 -1
- package/src/input/rebind-controller.ts +6 -8
- package/src/input/schema.ts +216 -188
- package/src/manifest/filename.ts +8 -12
- package/src/manifest/load.ts +17 -13
- package/src/manifest/schema.ts +55 -47
- package/src/physics/collider-dimensions.ts +8 -12
- package/src/pixi/scene-capture.ts +12 -15
- package/src/react/world-state.tsx +1 -1
- package/src/render/light-camera-factory.ts +8 -11
- package/src/render/material-factory.ts +1 -1
- package/src/render/render-batch-system.ts +14 -6
- package/src/render/render-features.ts +17 -35
- package/src/runtime/create-runtime.ts +270 -108
- package/src/runtime/debug-registry.ts +84 -8
- package/src/runtime/dev-build.ts +2 -2
- package/src/runtime/game-input-seams.ts +2 -2
- package/src/runtime/game.ts +168 -80
- package/src/runtime/mount-game.ts +8 -56
- package/src/runtime/mount-manifest.ts +43 -34
- package/src/runtime/playtest.ts +22 -0
- package/src/runtime/state-bridge.ts +3 -3
- package/src/setup/setup-audio.ts +21 -11
- package/src/setup/setup-renderer.ts +2 -61
- package/src/world3d-react/r3f-root-factory.tsx +7 -7
- package/src/world3d-react/rapier-physics-bridge.tsx +107 -50
- package/dist/adapter/setup-three-root-adapter.d.ts +0 -86
- package/dist/adapter/setup-three-root-adapter.d.ts.map +0 -1
- package/dist/adapter/setup-three-root-adapter.js +0 -908
- package/dist/animation/clip-map.d.ts +0 -12
- package/dist/animation/clip-map.d.ts.map +0 -1
- package/dist/animation/clip-map.js +0 -31
- package/dist/asset-registry.d.ts +0 -38
- package/dist/asset-registry.d.ts.map +0 -1
- package/dist/asset-registry.js +0 -66
- package/dist/canvas-react/engine-bridge.d.ts +0 -45
- package/dist/canvas-react/engine-bridge.d.ts.map +0 -1
- package/dist/canvas-react/engine-bridge.js +0 -45
- package/dist/canvas-react/pixi-react-adapter.d.ts +0 -77
- package/dist/canvas-react/pixi-react-adapter.d.ts.map +0 -1
- package/dist/canvas-react/pixi-react-adapter.js +0 -294
- package/dist/canvas-react/world-context.d.ts +0 -98
- package/dist/canvas-react/world-context.d.ts.map +0 -1
- package/dist/canvas-react/world-context.js +0 -173
- package/dist/dev/debug-draw.d.ts +0 -24
- package/dist/dev/debug-draw.d.ts.map +0 -1
- package/dist/dev/debug-draw.js +0 -73
- package/dist/render/auto-batcher.d.ts +0 -34
- package/dist/render/auto-batcher.d.ts.map +0 -1
- package/dist/render/auto-batcher.js +0 -140
- package/dist/render/lod.d.ts +0 -13
- package/dist/render/lod.d.ts.map +0 -1
- package/dist/render/lod.js +0 -16
- package/dist/runtime/types.d.ts +0 -303
- package/dist/runtime/types.d.ts.map +0 -1
- package/dist/runtime/types.js +0 -1
- package/dist/world3d-react/engine-bridge.d.ts +0 -47
- package/dist/world3d-react/engine-bridge.d.ts.map +0 -1
- package/dist/world3d-react/engine-bridge.js +0 -73
- package/dist/world3d-react/r3f-adapter.d.ts +0 -58
- package/dist/world3d-react/r3f-adapter.d.ts.map +0 -1
- package/dist/world3d-react/r3f-adapter.js +0 -634
- package/dist/world3d-react/world-context.d.ts +0 -182
- package/dist/world3d-react/world-context.d.ts.map +0 -1
- package/dist/world3d-react/world-context.js +0 -235
- package/src/adapter/setup-three-root-adapter.ts +0 -1032
- package/src/animation/clip-map.ts +0 -34
- package/src/asset-registry.ts +0 -89
- package/src/dev/debug-draw.ts +0 -80
- package/src/render/auto-batcher.ts +0 -168
- package/src/render/lod.ts +0 -17
- package/src/runtime/types.ts +0 -328
|
@@ -23,6 +23,7 @@ import type { Game } from '../runtime/game';
|
|
|
23
23
|
import {
|
|
24
24
|
CONTRACT_SYSTEM_SLOTS,
|
|
25
25
|
type ContractSurface,
|
|
26
|
+
type ContractSystemEmptySlot,
|
|
26
27
|
projectContractSystemAdapters,
|
|
27
28
|
} from './ingest/contract-system-adapters';
|
|
28
29
|
import type { VgaiGameSystemAdapters } from './ingest/game-contract';
|
|
@@ -447,6 +448,18 @@ export function installNativeDebugBindings(
|
|
|
447
448
|
export interface NativeSystemsBinding {
|
|
448
449
|
readonly rootId: string;
|
|
449
450
|
readonly slots: Readonly<Partial<SystemAdapters>>;
|
|
451
|
+
/**
|
|
452
|
+
* The slots this root's `systems` table answered with `absent(reason)` — the
|
|
453
|
+
* positive absences, in the game's own words.
|
|
454
|
+
*
|
|
455
|
+
* They are carried rather than dropped because they are the ONLY thing that
|
|
456
|
+
* can tell a coverage reader "this game has no networking" apart from "nobody
|
|
457
|
+
* ever looked". Nothing is installed for them (that would be the stub adapter
|
|
458
|
+
* `absent()`'s own comment forbids); they exist to be READ — through
|
|
459
|
+
* `binding.observation.entrySystems`, which is the product door the coverage
|
|
460
|
+
* table renders from.
|
|
461
|
+
*/
|
|
462
|
+
readonly absent: readonly ContractSystemEmptySlot[];
|
|
450
463
|
}
|
|
451
464
|
|
|
452
465
|
/**
|
|
@@ -478,13 +491,27 @@ export function nativeSystemsBindingFromEntryModule(
|
|
|
478
491
|
if (Object.keys(projection.bound).length === 0 && projection.empty.length === 0) {
|
|
479
492
|
throw new Error(`Root "${rootId}" exports an empty \`systems\` object.`);
|
|
480
493
|
}
|
|
481
|
-
return { rootId, slots: projection.bound };
|
|
494
|
+
return { rootId, slots: projection.bound, absent: projection.empty };
|
|
482
495
|
}
|
|
483
496
|
|
|
484
|
-
/**
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
497
|
+
/**
|
|
498
|
+
* Install every declared binding onto the mounted Game's game-scoped slot
|
|
499
|
+
* table (`Game.installDeclaredSystemAdapters`), where the ordinary
|
|
500
|
+
* `game.systemAdapters` merge picks them up ahead of any lingering component
|
|
501
|
+
* registration for the same root.
|
|
502
|
+
*
|
|
503
|
+
* A root's ABSENCES travel the same call and install NOTHING — they are
|
|
504
|
+
* recorded, never bound, because the whole point of `absent()` is that no
|
|
505
|
+
* adapter exists to bind (see its comment: a marker, never a stub). They are
|
|
506
|
+
* recorded HERE rather than left on the binding alone so the answer is
|
|
507
|
+
* game-scoped, matching the registry every editor panel already reads: a
|
|
508
|
+
* `SystemAdapters` slot is filled by whichever root builds it, so "does this
|
|
509
|
+
* GAME have physics" cannot be answered one root at a time.
|
|
510
|
+
*
|
|
511
|
+
* A root that declares only absences therefore still calls through — skipping
|
|
512
|
+
* it on an empty `slots` map is what would drop exactly the games whose whole
|
|
513
|
+
* declaration is "I have none of these".
|
|
514
|
+
*/
|
|
488
515
|
export function installNativeSystemsBindings(
|
|
489
516
|
game: Game,
|
|
490
517
|
bindings: readonly NativeSystemsBinding[],
|
|
@@ -498,7 +525,16 @@ export function installNativeSystemsBindings(
|
|
|
498
525
|
);
|
|
499
526
|
}
|
|
500
527
|
for (const binding of bindings) {
|
|
501
|
-
if (Object.keys(binding.slots).length === 0) continue;
|
|
502
|
-
install.call(
|
|
528
|
+
if (Object.keys(binding.slots).length === 0 && binding.absent.length === 0) continue;
|
|
529
|
+
install.call(
|
|
530
|
+
game,
|
|
531
|
+
binding.rootId,
|
|
532
|
+
binding.slots,
|
|
533
|
+
binding.absent.map((slot) => ({
|
|
534
|
+
rootId: binding.rootId,
|
|
535
|
+
slot: slot.slot,
|
|
536
|
+
reason: slot.evidence,
|
|
537
|
+
})),
|
|
538
|
+
);
|
|
503
539
|
}
|
|
504
540
|
}
|
|
@@ -29,6 +29,15 @@ import type { Transform, TransformOwner } from './transform';
|
|
|
29
29
|
* `@react-three/rapier` pins for R3F worlds (0.19). Their `RigidBody` classes
|
|
30
30
|
* are unrelated NOMINAL types, so a shared helper that named either one could
|
|
31
31
|
* not serve both callers.
|
|
32
|
+
*
|
|
33
|
+
* FLIP CONDITION: `@react-three/rapier` pins its rapier EXACTLY (`0.19.2` as
|
|
34
|
+
* of its 2.2.0 — check `npm view @react-three/rapier dependencies`), so an
|
|
35
|
+
* override or engine bump to any OTHER rapier version forks the wasm instance
|
|
36
|
+
* that library initializes against and is refused. This structural split
|
|
37
|
+
* collapses only when the engine's own `@dimforge/rapier3d-compat` and
|
|
38
|
+
* `@react-three/rapier`'s exact pin agree on one version — at that point the
|
|
39
|
+
* two `RigidBody` types are one nominal type again and this interface can
|
|
40
|
+
* name it directly.
|
|
32
41
|
*/
|
|
33
42
|
export interface RapierEditableBody {
|
|
34
43
|
isFixed(): boolean;
|
|
@@ -53,28 +62,66 @@ export interface RapierEditableBody {
|
|
|
53
62
|
* answered differently by each Rapier owner, and a caller that cannot answer
|
|
54
63
|
* one honestly omits it.
|
|
55
64
|
*/
|
|
65
|
+
/**
|
|
66
|
+
* What asking this Rapier owner about a node id actually yields.
|
|
67
|
+
*
|
|
68
|
+
* THE TWO NEGATIVE ANSWERS ARE DIFFERENT FACTS, and collapsing them into one
|
|
69
|
+
* `undefined` is what let `ownerOf` answer `'editor'` — "the editor drives this
|
|
70
|
+
* node's transform" — for an id this world has never heard of. `'no-body'` is a
|
|
71
|
+
* real measurement about a real node; `'unresolved'` is this implementer saying
|
|
72
|
+
* it cannot answer at all.
|
|
73
|
+
*/
|
|
74
|
+
export type RapierBodyLookup =
|
|
75
|
+
| { readonly kind: 'body'; readonly body: RapierEditableBody }
|
|
76
|
+
/** The node exists here and simply has no physics body. */
|
|
77
|
+
| { readonly kind: 'no-body' }
|
|
78
|
+
/** This world does not know this node id. */
|
|
79
|
+
| { readonly kind: 'unresolved' };
|
|
80
|
+
|
|
81
|
+
/** The refusal sentence for a protocol verb aimed at a node this world has
|
|
82
|
+
* never heard of — named once so every verb says the same thing. */
|
|
83
|
+
function unresolvedNodeRefusal(operation: string, nodeId: string): string {
|
|
84
|
+
return (
|
|
85
|
+
`[RapierPhysicsAdapter] ${operation}: this world does not know node id "${nodeId}", so ` +
|
|
86
|
+
'there is no body to drive. Refusing rather than reporting a completed write — gate on ' +
|
|
87
|
+
"ownerOf(id) !== 'unresolved' before driving physics from a game-scoped adapter."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
56
91
|
export function createRapierBodyEditing(
|
|
57
|
-
|
|
92
|
+
lookup: (nodeId: string) => RapierBodyLookup,
|
|
58
93
|
): Pick<PhysicsAdapter, 'ownerOf' | 'freeze' | 'commit' | 'unfreeze'> {
|
|
59
94
|
/** Saved body types while frozen, so unfreeze can restore them. */
|
|
60
95
|
const frozen = new Map<RapierEditableBody, number>();
|
|
61
96
|
|
|
97
|
+
/** The body for a verb that must actually reach one, or `null` when this node
|
|
98
|
+
* genuinely has no physics. THROWS for an unknown id: the three verbs below
|
|
99
|
+
* return `void`, so a silent return is indistinguishable from a completed
|
|
100
|
+
* write, and `commit` in particular is a WRITE the caller believes landed. */
|
|
101
|
+
const bodyForWrite = (operation: string, nodeId: string): RapierEditableBody | null => {
|
|
102
|
+
const answer = lookup(nodeId);
|
|
103
|
+
if (answer.kind === 'unresolved') throw new Error(unresolvedNodeRefusal(operation, nodeId));
|
|
104
|
+
return answer.kind === 'body' ? answer.body : null;
|
|
105
|
+
};
|
|
106
|
+
|
|
62
107
|
return {
|
|
63
108
|
ownerOf(nodeId: string): TransformOwner {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
// A
|
|
67
|
-
|
|
109
|
+
const answer = lookup(nodeId);
|
|
110
|
+
if (answer.kind === 'unresolved') return 'unresolved';
|
|
111
|
+
// A node with no body, and a FIXED body (which never moves on its own),
|
|
112
|
+
// are both transforms the editor drives.
|
|
113
|
+
if (answer.kind === 'no-body') return 'editor';
|
|
114
|
+
return answer.body.isFixed() ? 'editor' : 'physics';
|
|
68
115
|
},
|
|
69
116
|
freeze(nodeId: string): void {
|
|
70
|
-
const body =
|
|
117
|
+
const body = bodyForWrite('freeze', nodeId);
|
|
71
118
|
if (!body || frozen.has(body)) return;
|
|
72
119
|
frozen.set(body, body.bodyType());
|
|
73
120
|
// Kinematic-position: the body stops simulating but tracks the pose we set.
|
|
74
121
|
body.setBodyType(2 /* KinematicPositionBased */, true);
|
|
75
122
|
},
|
|
76
123
|
commit(nodeId: string, t: Transform): void {
|
|
77
|
-
const body =
|
|
124
|
+
const body = bodyForWrite('commit', nodeId);
|
|
78
125
|
if (!body) return;
|
|
79
126
|
body.setTranslation({ x: t.position[0], y: t.position[1], z: t.position[2] }, true);
|
|
80
127
|
body.setRotation(
|
|
@@ -83,7 +130,7 @@ export function createRapierBodyEditing(
|
|
|
83
130
|
);
|
|
84
131
|
},
|
|
85
132
|
unfreeze(nodeId: string): void {
|
|
86
|
-
const body =
|
|
133
|
+
const body = bodyForWrite('unfreeze', nodeId);
|
|
87
134
|
if (!body) return;
|
|
88
135
|
const prev = frozen.get(body);
|
|
89
136
|
if (prev !== undefined) {
|
|
@@ -149,22 +196,31 @@ export function createRapierPhysicsAdapter(
|
|
|
149
196
|
return contactBuf.subarray(0, contactCount * 3);
|
|
150
197
|
};
|
|
151
198
|
|
|
152
|
-
/** The one place this adapter crosses from node id into Three's vocabulary
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
199
|
+
/** The one place this adapter crosses from node id into Three's vocabulary —
|
|
200
|
+
* and the one place that can tell an UNKNOWN node from one with no body. */
|
|
201
|
+
const lookup = (nodeId: string): RapierBodyLookup => {
|
|
202
|
+
const object = resolve(nodeId);
|
|
203
|
+
if (!object) return { kind: 'unresolved' };
|
|
204
|
+
const body = registry.get(object)?.body;
|
|
205
|
+
return body ? { kind: 'body', body } : { kind: 'no-body' };
|
|
156
206
|
};
|
|
157
207
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
208
|
+
const adapter: PhysicsAdapter = { ...createRapierBodyEditing(lookup) };
|
|
209
|
+
// The debug-draw and contact capabilities exist only where a physics CONTEXT
|
|
210
|
+
// does. They used to be attached unconditionally and then no-op internally:
|
|
211
|
+
// `setDebugDrawEnabled(true)` returned as if it had enabled something, and
|
|
212
|
+
// `contactPoints()` returned an empty view — "we looked and there are no
|
|
213
|
+
// contacts" — for a world with no simulation at all. Presence mirrors the
|
|
214
|
+
// capability, so `physics-debug.ts`'s existing `?.()` calls now see absence.
|
|
215
|
+
if (physics) {
|
|
216
|
+
adapter.debugDraw = () => physics.debugMesh;
|
|
217
|
+
adapter.setDebugDrawEnabled = (enabled: boolean): void => {
|
|
163
218
|
// Same two fields the in-game KeyP toggle flips — the adapter's render
|
|
164
219
|
// system reads `debugEnabled` and feeds `debugRender()` into the mesh.
|
|
165
220
|
physics.debugEnabled = enabled;
|
|
166
221
|
physics.debugMesh.visible = enabled;
|
|
167
|
-
}
|
|
168
|
-
contactPoints
|
|
169
|
-
}
|
|
222
|
+
};
|
|
223
|
+
adapter.contactPoints = collectContactPoints;
|
|
224
|
+
}
|
|
225
|
+
return adapter;
|
|
170
226
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* It lives in the ADAPTER SEAM, not in a surface entry, because `WorldRendererConfig` IS part of
|
|
5
5
|
* the root contract: `MountedThreeRoot.rendererConfig` reports it (`./root-adapter.ts`) and
|
|
6
6
|
* `./root-seam-contract.ts` already lists it as a contract field. The seam defines the shape; the
|
|
7
|
-
* surface entries and the editor CONFORM to it — `world3d-react/r3f-
|
|
7
|
+
* surface entries and the editor CONFORM to it — `world3d-react/r3f-root-factory.tsx` is the declarer,
|
|
8
8
|
* `runtime/create-runtime.ts` the host, `editor/src/components/ViewportPanel.tsx` the editor's
|
|
9
9
|
* applier. Do NOT move it back under `world3d-react/`: nothing here touches react, and a core
|
|
10
10
|
* adapter file reaching into a react entry is exactly what `react-core-import-ban.test.ts` forbids
|
|
@@ -90,7 +90,7 @@ export interface WorldRendererConfig {
|
|
|
90
90
|
* Apply `config` to `renderer`, returning the restore function that puts back what was there.
|
|
91
91
|
*
|
|
92
92
|
* `three` is passed in rather than imported for values so the enum constants come from the HOST's
|
|
93
|
-
* three instance — the same identity rule `r3f-
|
|
93
|
+
* three instance — the same identity rule `r3f-root-factory.tsx` follows for the scene and camera.
|
|
94
94
|
*/
|
|
95
95
|
export function applyWorldRendererConfig(
|
|
96
96
|
three: typeof THREE,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RootAdapter — the host ⇄ runtime contract. A ROOT is *anything that mounts*.
|
|
3
3
|
*
|
|
4
|
-
* This is the interface the host depends on.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* This is the interface the host depends on. First-party content and
|
|
5
|
+
* unmodified external games are peer root adapters. A game is the
|
|
6
|
+
* manifest's complete roots array, while each adapter owns exactly one
|
|
7
|
+
* root.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Container } from 'pixi.js';
|
|
@@ -136,8 +136,8 @@ export interface MountedReactRoot extends MountedRootBase {
|
|
|
136
136
|
/** Every kind of live, mounted world. */
|
|
137
137
|
export type MountedRoot = MountedThreeRoot | MountedPixiRoot | MountedReactRoot;
|
|
138
138
|
|
|
139
|
-
/** Map a {@link AdapterSurface} to its mounted-world shape
|
|
140
|
-
*
|
|
139
|
+
/** Map a {@link AdapterSurface} to its mounted-world shape — lets generic
|
|
140
|
+
* code over
|
|
141
141
|
* `K extends AdapterSurface` name the right surface without a manual union. */
|
|
142
142
|
export type MountedRootFor<K extends AdapterSurface> = K extends 'three'
|
|
143
143
|
? MountedThreeRoot
|
|
@@ -174,7 +174,7 @@ export interface RootAdapter<K extends AdapterSurface = 'three'> {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
* One surface tag paired with an adapter typed FOR that surface
|
|
177
|
+
* One surface tag paired with an adapter typed FOR that surface.
|
|
178
178
|
*
|
|
179
179
|
* A resolver that turns a manifest root into a mountable
|
|
180
180
|
* adapter handles every surface in one function, so its return type has to
|
|
@@ -20,7 +20,19 @@ import type { Transform, TransformOwner } from './transform';
|
|
|
20
20
|
export type PhysicsColliderShape =
|
|
21
21
|
| { readonly type: 'cuboid'; readonly halfExtents: readonly [number, number, number] }
|
|
22
22
|
| { readonly type: 'ball'; readonly radius: number }
|
|
23
|
-
| { readonly type: 'capsule'; readonly halfHeight: number; readonly radius: number }
|
|
23
|
+
| { readonly type: 'capsule'; readonly halfHeight: number; readonly radius: number }
|
|
24
|
+
/**
|
|
25
|
+
* A collider this seam has no plain-data projection for — a trimesh,
|
|
26
|
+
* heightfield, convex hull, cylinder, cone, …
|
|
27
|
+
*
|
|
28
|
+
* IT IS STILL A COLLIDER, and the body still has it. Implementations used to
|
|
29
|
+
* drop these from `colliders()` entirely, so a body whose only collider was a
|
|
30
|
+
* trimesh inspected as a body with NO physics at all. `kind` is the native
|
|
31
|
+
* shape's own name, so the inspector can say WHICH shape it cannot draw
|
|
32
|
+
* rather than implying nothing is there. Nothing may synthesize dimensions
|
|
33
|
+
* for one, and `previewCollider` refuses it.
|
|
34
|
+
*/
|
|
35
|
+
| { readonly type: 'unsupported'; readonly kind: string };
|
|
24
36
|
|
|
25
37
|
/** Plain-data projection of one native 3D physics collider. The owning
|
|
26
38
|
* physics implementation keeps the actual collider; editor authoring only
|
|
@@ -249,12 +261,28 @@ export interface NetworkingAdapter {
|
|
|
249
261
|
authority(nodeId: string): 'local' | 'remote' | 'server';
|
|
250
262
|
/** Remote/server-authoritative nodes → inspect-only in the editor. */
|
|
251
263
|
editable(nodeId: string): boolean;
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Optional capability: current connection lifecycle state.
|
|
266
|
+
*
|
|
267
|
+
* OPTIONAL for the same reason every other member here is — `'disconnected'`
|
|
268
|
+
* is a POSITIVE CLAIM about the link, and an implementer that never taught
|
|
269
|
+
* this adapter to read connection state has not made it. Absent ⇒ the
|
|
270
|
+
* inspector marks the section unsupported; it does not report a game as
|
|
271
|
+
* disconnected on the strength of nobody having looked.
|
|
272
|
+
*/
|
|
273
|
+
getConnectionState?(): ConnectionState;
|
|
274
|
+
/**
|
|
275
|
+
* Optional capability: the active room's identity, or `null` when connected
|
|
276
|
+
* to no room. `null` is the ANSWER "there is no room", so absence of the
|
|
277
|
+
* accessor — "nothing here can tell you" — has to be a different thing.
|
|
278
|
+
*/
|
|
279
|
+
getRoomInfo?(): RoomInfo | null;
|
|
280
|
+
/**
|
|
281
|
+
* Optional capability: replication activity snapshot, for a live network
|
|
282
|
+
* inspector panel. Zeroes are a measurement, not a default; an adapter with
|
|
283
|
+
* no counters omits this rather than reporting a quiet link.
|
|
284
|
+
*/
|
|
285
|
+
getReplicationStats?(): ReplicationStats;
|
|
258
286
|
/** Subscribe to changes in connection state / room / replication stats. */
|
|
259
287
|
subscribe(cb: () => void): Unsubscribe;
|
|
260
288
|
/** Optional capability: one plain-data (JSON-safe) snapshot of the
|
|
@@ -281,7 +309,7 @@ export interface NetworkingAdapter {
|
|
|
281
309
|
* (e.g. read off its own room state). The editor consumes this for display —
|
|
282
310
|
* a seat label — ONLY when a real implementer provides it, falling back to a
|
|
283
311
|
* generic label otherwise. */
|
|
284
|
-
getPlayerIdentity?(): NetPlayerIdentity;
|
|
312
|
+
getPlayerIdentity?(): NetPlayerIdentity | undefined;
|
|
285
313
|
/** Optional capability, PAIRED with {@link getPlayerIdentity}: set the local
|
|
286
314
|
* player's identity through the game's OWN multiplayer mechanism. The editor
|
|
287
315
|
* renders an editable name field ONLY when a real implementer provides this
|
|
@@ -346,6 +374,13 @@ export interface NavCrowdAgentState {
|
|
|
346
374
|
*/
|
|
347
375
|
export interface NavigationAdapter {
|
|
348
376
|
hasNavMesh(): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* `[]` means SEARCHED AND FOUND NO ROUTE — a fact about the level. An
|
|
379
|
+
* implementer with no navmesh to search, or whose query FAILED, THROWS
|
|
380
|
+
* instead; those are facts about the implementer, and collapsing all three
|
|
381
|
+
* into `[]` tells a caller the level is impassable when nobody looked.
|
|
382
|
+
* Gate on {@link hasNavMesh} where the first case is reachable.
|
|
383
|
+
*/
|
|
349
384
|
findPath(start: NavPoint, end: NavPoint): NavPoint[];
|
|
350
385
|
debugMesh(scene: THREE.Scene): THREE.Object3D | null;
|
|
351
386
|
/** (Re)build the navmesh from source meshes. Synchronous in the blessed
|
|
@@ -53,9 +53,9 @@ export const NETWORKING_ADAPTER_SHAPE = defineSeamShape<NetworkingAdapter>()({
|
|
|
53
53
|
networkId: { optional: false, kind: 'function', required: 'operation' },
|
|
54
54
|
authority: { optional: false, kind: 'function', required: 'operation' },
|
|
55
55
|
editable: { optional: false, kind: 'function', required: 'operation' },
|
|
56
|
-
getConnectionState: { optional:
|
|
57
|
-
getRoomInfo: { optional:
|
|
58
|
-
getReplicationStats: { optional:
|
|
56
|
+
getConnectionState: { optional: true, kind: 'function', required: 'operation' },
|
|
57
|
+
getRoomInfo: { optional: true, kind: 'function', required: 'operation' },
|
|
58
|
+
getReplicationStats: { optional: true, kind: 'function', required: 'operation' },
|
|
59
59
|
subscribe: { optional: false, kind: 'function', required: 'effect' },
|
|
60
60
|
getStateSnapshot: { optional: true, kind: 'function', required: 'operation' },
|
|
61
61
|
messageEvents: { optional: true, kind: 'function', required: 'operation' },
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createSystemSlot` — THE implementation of the declared-slot façade, the
|
|
3
|
+
* seam between a STATIC `systems` declaration and a LIVE adapter that only
|
|
4
|
+
* exists once the world tree is mounted.
|
|
5
|
+
*
|
|
6
|
+
* WHY IT EXISTS. An entry declares its systems statically
|
|
7
|
+
* (`export const systems = { networking: networkingSystem() }`), while the
|
|
8
|
+
* thing being declared — a joined Colyseus room, a baked navmesh, a mounted
|
|
9
|
+
* `<Physics>`, a cutscene's camera ownership — is built inside the world tree,
|
|
10
|
+
* later, and may be replaced (reconnect, remount, hot restart) or go away
|
|
11
|
+
* (stop). The slot is a stable object the host installs at mount and holds
|
|
12
|
+
* forever; every call forwards to whatever is attached right now.
|
|
13
|
+
*
|
|
14
|
+
* ── THE HONESTY RULE, STATED IN ONE PLACE ───────────────────────────────────
|
|
15
|
+
* This is why the pattern is centralized: five hand-rolled copies disagreed
|
|
16
|
+
* about it, and each disagreement was found by a separate review.
|
|
17
|
+
*
|
|
18
|
+
* - An **action** with no live target REFUSES BY NAME
|
|
19
|
+
* (`<name>: <unattachedMessage>`). Never a silent no-op — a caller that
|
|
20
|
+
* told the game to DO something must learn that it did not happen. An
|
|
21
|
+
* action against a live adapter that lacks the member refuses the same
|
|
22
|
+
* way, naming the member.
|
|
23
|
+
* - A **read** answers its declared HONEST EMPTY — `'disconnected'`, `[]`,
|
|
24
|
+
* `null`, `false`. That is not a fabrication: it is the truth of the
|
|
25
|
+
* not-attached state, in the same vocabulary the editor's own edit-mode
|
|
26
|
+
* adapters use. Reads are also the only kind safe to call from a per-frame
|
|
27
|
+
* debug draw, which is why a throw into a rAF loop is never the answer.
|
|
28
|
+
* - An **optional** member MIRRORS THE LIVE ADAPTER'S PRESENCE: absent while
|
|
29
|
+
* unattached, and absent afterwards when the live adapter itself does not
|
|
30
|
+
* provide it. Presence IS the consume-by-presence protocol's signal, so
|
|
31
|
+
* the slot may never invent it. Each presence read CAPTURES the adapter it
|
|
32
|
+
* saw and forwards to that same instance, so a detach between the read and
|
|
33
|
+
* the call answers as the adapter the caller was handed rather than a
|
|
34
|
+
* mid-flight swap.
|
|
35
|
+
* - A **subscribe** member SURVIVES REATTACHMENT: listeners live on the
|
|
36
|
+
* slot, never on the instance, and the slot re-binds its own single
|
|
37
|
+
* subscription on every attach/detach. A panel that subscribed once to the
|
|
38
|
+
* stable slot object is therefore never left holding a disposed system, and
|
|
39
|
+
* it is notified when the live half appears or disappears.
|
|
40
|
+
* - A member the config DOES NOT LIST does not exist on the slot at all.
|
|
41
|
+
* That is how the anti-shim rule spells omission — e.g. `PhysicsAdapter`'s
|
|
42
|
+
* `debugDraw`/`contactPoints` over `@react-three/rapier`, whose debug line
|
|
43
|
+
* segments live inside the fiber tree and expose no handle. Absence is a
|
|
44
|
+
* capability answer; a stub is a lie.
|
|
45
|
+
*
|
|
46
|
+
* ── RESOURCE OWNERSHIP ──────────────────────────────────────────────────────
|
|
47
|
+
* OWNER: whoever built the live adapter (the hook, the bridge component). The
|
|
48
|
+
* slot owns only the POINTER to it plus its own listener set and its own
|
|
49
|
+
* subscription to the live half. SHARERS: every reader of the declared
|
|
50
|
+
* system — editor inspectors, instruments. TEARDOWN: the function `attach`
|
|
51
|
+
* returns, and nothing else. It is IDENTITY-GUARDED — it clears only while
|
|
52
|
+
* the same instance is still attached, so a replace-then-teardown-the-old
|
|
53
|
+
* ordering cannot detach the new one — and detaching never disposes the
|
|
54
|
+
* adapter, because the slot did not create it.
|
|
55
|
+
*
|
|
56
|
+
* WHERE the slot module lives decides how many games share it. A slot in
|
|
57
|
+
* PROJECT-owned source (the four capability/example façades) is per Play
|
|
58
|
+
* instance, because the editor stamps mount ids onto project-owned import
|
|
59
|
+
* specifiers (`server/project-module-instance.ts`) — N instances get N module
|
|
60
|
+
* graphs and N slots. A slot in an ENGINE module is reached by bare
|
|
61
|
+
* specifier, which that stamping deliberately never touches, so it is ONE per
|
|
62
|
+
* page: every Play instance shares it, and concurrent instances' attaches
|
|
63
|
+
* contend (last attach wins; the loser's detach is dropped by the identity
|
|
64
|
+
* guard). `rapier-physics-bridge.tsx` is the one such slot today and warns
|
|
65
|
+
* loudly when contended — prefer project-owned slot modules for anything new.
|
|
66
|
+
*
|
|
67
|
+
* NOT A WRAPPER. The slot's members have the adapter interface's own exact
|
|
68
|
+
* signatures and hand back the implementation's own values; nothing stands
|
|
69
|
+
* between a caller and the live library object.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
import type { VgaiGameSystemEmpty } from './ingest/game-contract';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `absent(reason)` — THE WHOLE-SLOT counterpart of the four per-member policies
|
|
76
|
+
* above, and the fifth line of the same honesty rule.
|
|
77
|
+
*
|
|
78
|
+
* The four policies answer "this slot exists but nothing is attached yet". This
|
|
79
|
+
* one answers a different question entirely: **this game will never have that
|
|
80
|
+
* subsystem, and here is what was searched.** A slot simply left out of the
|
|
81
|
+
* `systems` table cannot say that — an omitted key means "unsupported", which is
|
|
82
|
+
* the same shape as "nobody looked", and the coverage report has to file it as a
|
|
83
|
+
* work order forever. Declaring the absence turns an UNANSWERED row into a
|
|
84
|
+
* terminal one.
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* export const systems = {
|
|
88
|
+
* audio: sfxAudioSystem(),
|
|
89
|
+
* physics: rapierPhysicsSystem(),
|
|
90
|
+
* networking: absent('single-player: no Colyseus client anywhere in `src/`'),
|
|
91
|
+
* };
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* ## It is a CONSTRUCTOR for the shape that already exists, not a second one
|
|
95
|
+
*
|
|
96
|
+
* The returned value IS `VgaiGameSystemEmpty` — the plain
|
|
97
|
+
* `{ present: false, evidence }` record an INGESTED game declares on
|
|
98
|
+
* `window.vgaiGame.systems.systemAdapters`, validated by the same single
|
|
99
|
+
* projection (`ingest/contract-system-adapters.ts`). There is one shape law, not
|
|
100
|
+
* two: a foreign game cannot import this helper and must stay able to write the
|
|
101
|
+
* record by hand, so nothing here may brand the runtime value. What the helper
|
|
102
|
+
* buys a FIRST-PARTY author is the reason-quality check moved to the call site —
|
|
103
|
+
* our own code failing its own contract fails fast, where an ingested game's
|
|
104
|
+
* same mistake is filed as a `malformed` verdict for its coverage report.
|
|
105
|
+
*
|
|
106
|
+
* ## It is a MARKER, never a stub adapter
|
|
107
|
+
*
|
|
108
|
+
* Do not answer an absent slot with an adapter whose methods return zeros. A
|
|
109
|
+
* `getConnectionState()` of `'disconnected'` on a game with no transport implies
|
|
110
|
+
* a connection that could exist; that is the fabrication the anti-shim rule
|
|
111
|
+
* forbids. The absence is STATED, and the host installs nothing for it.
|
|
112
|
+
*
|
|
113
|
+
* @param reason What was searched and what was found, in the game's own source
|
|
114
|
+
* terms. "no netcode anywhere in `src/`" is a finished answer a reviewer can
|
|
115
|
+
* re-run; "not implemented yet" is a plan, and is rejected here.
|
|
116
|
+
*/
|
|
117
|
+
export function absent(reason: string): VgaiGameSystemEmpty {
|
|
118
|
+
if (typeof reason !== 'string' || reason.trim() === '') {
|
|
119
|
+
throw new Error(
|
|
120
|
+
'absent(): an absence needs evidence — say what was searched and what was found ' +
|
|
121
|
+
'(e.g. "no Colyseus client anywhere in `src/`"), so a reviewer can re-run it. ' +
|
|
122
|
+
'An unevidenced absence asserts something nobody can re-check.',
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return { present: false, evidence: reason };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Any adapter member. `never[]` args make the conditional match contravariantly. */
|
|
129
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
130
|
+
|
|
131
|
+
/** The declared member's return type, used to type a `read`'s honest empty. */
|
|
132
|
+
type MemberReturn<F> = NonNullable<F> extends (...args: never[]) => infer R ? R : never;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The per-member policy. There are exactly four, and every member of every
|
|
136
|
+
* declared slot in the repo is one of them — see the honesty rule above.
|
|
137
|
+
*/
|
|
138
|
+
export type SystemSlotMemberSpec<F> =
|
|
139
|
+
| { readonly kind: 'action' }
|
|
140
|
+
| { readonly kind: 'read'; readonly empty: MemberReturn<F> }
|
|
141
|
+
| { readonly kind: 'subscribe' }
|
|
142
|
+
| { readonly kind: 'optional' };
|
|
143
|
+
|
|
144
|
+
/** The keys of `T` whose values are callable (data properties are not slottable). */
|
|
145
|
+
type FunctionMemberKeys<T> = {
|
|
146
|
+
[K in keyof T]-?: NonNullable<T[K]> extends AnyFn ? K : never;
|
|
147
|
+
}[keyof T];
|
|
148
|
+
|
|
149
|
+
/** Per-member policies. A member left out is left OFF the slot entirely. */
|
|
150
|
+
export type SystemSlotMembers<T> = {
|
|
151
|
+
readonly [K in FunctionMemberKeys<T>]?: SystemSlotMemberSpec<T[K]>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export interface SystemSlotConfig<T extends object> {
|
|
155
|
+
/**
|
|
156
|
+
* The slot's own name, used as the prefix of every refusal so a stack-less
|
|
157
|
+
* error still names the seam (`'networkingSystem'`, `'rapierPhysicsSystem'`).
|
|
158
|
+
*/
|
|
159
|
+
readonly name: string;
|
|
160
|
+
/**
|
|
161
|
+
* The rest of an action's refusal while nothing is attached — the DOMAIN
|
|
162
|
+
* half of the message, naming what has not happened yet ("the world is not
|
|
163
|
+
* playing, or the navmesh has not finished building").
|
|
164
|
+
*/
|
|
165
|
+
readonly unattachedMessage: string;
|
|
166
|
+
readonly members: SystemSlotMembers<T>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface SystemSlot<T extends object> {
|
|
170
|
+
/**
|
|
171
|
+
* Publish `live` as the slot's target. Returns the ONE detach path, which
|
|
172
|
+
* is identity-guarded: it clears only while `live` is still the attached
|
|
173
|
+
* instance, and never disposes it.
|
|
174
|
+
*/
|
|
175
|
+
attach(live: T): () => void;
|
|
176
|
+
/** The stable declared object. Hand THIS to the entry's `systems` map. */
|
|
177
|
+
readonly slot: T;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function createSystemSlot<T extends object>(config: SystemSlotConfig<T>): SystemSlot<T> {
|
|
181
|
+
const { name, unattachedMessage, members } = config;
|
|
182
|
+
|
|
183
|
+
let live: T | null = null;
|
|
184
|
+
/** Subscribers to the stable slot object; they outlive any one live instance. */
|
|
185
|
+
const listeners = new Set<() => void>();
|
|
186
|
+
/** The slot's own single subscription to whatever is attached. */
|
|
187
|
+
let liveUnsubscribe: (() => void) | null = null;
|
|
188
|
+
let subscribeMember: string | null = null;
|
|
189
|
+
|
|
190
|
+
const asRecord = (value: object): Record<string, unknown> =>
|
|
191
|
+
value as unknown as Record<string, unknown>;
|
|
192
|
+
|
|
193
|
+
const liveMember = (member: string): AnyFn | undefined => {
|
|
194
|
+
if (!live) return undefined;
|
|
195
|
+
const value = asRecord(live)[member];
|
|
196
|
+
return typeof value === 'function' ? (value as AnyFn) : undefined;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const notify = (): void => {
|
|
200
|
+
for (const listener of [...listeners]) listener();
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const bindLive = (): void => {
|
|
204
|
+
liveUnsubscribe?.();
|
|
205
|
+
liveUnsubscribe = null;
|
|
206
|
+
if (!live || subscribeMember === null || listeners.size === 0) return;
|
|
207
|
+
const subscribe = liveMember(subscribeMember);
|
|
208
|
+
if (!subscribe) return;
|
|
209
|
+
const result = subscribe.call(live, notify as never);
|
|
210
|
+
liveUnsubscribe = typeof result === 'function' ? (result as () => void) : null;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const target: Record<string, unknown> = {};
|
|
214
|
+
|
|
215
|
+
const declared = Object.entries(members) as [string, SystemSlotMemberSpec<unknown>][];
|
|
216
|
+
for (const [member, spec] of declared) {
|
|
217
|
+
switch (spec.kind) {
|
|
218
|
+
case 'action': {
|
|
219
|
+
// Refuse by name, twice over: no live adapter at all, or a live
|
|
220
|
+
// adapter that does not carry this member (only ever a foreign
|
|
221
|
+
// replacement — the blessed implementations carry all of theirs).
|
|
222
|
+
target[member] = (...args: never[]): unknown => {
|
|
223
|
+
if (!live) throw new Error(`${name}: ${unattachedMessage}`);
|
|
224
|
+
const fn = liveMember(member);
|
|
225
|
+
if (!fn) throw new Error(`${name}: the live adapter has no ${member}().`);
|
|
226
|
+
return fn.apply(live, args);
|
|
227
|
+
};
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'read': {
|
|
231
|
+
const { empty } = spec;
|
|
232
|
+
target[member] = (...args: never[]): unknown => {
|
|
233
|
+
const current = live;
|
|
234
|
+
const fn = liveMember(member);
|
|
235
|
+
const value = fn ? fn.apply(current, args) : undefined;
|
|
236
|
+
return value ?? empty;
|
|
237
|
+
};
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case 'subscribe': {
|
|
241
|
+
if (subscribeMember !== null) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`${name}: a slot declares at most one 'subscribe' member (${subscribeMember} and ${member}).`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
subscribeMember = member;
|
|
247
|
+
target[member] = (listener: () => void): (() => void) => {
|
|
248
|
+
listeners.add(listener);
|
|
249
|
+
bindLive();
|
|
250
|
+
return () => {
|
|
251
|
+
listeners.delete(listener);
|
|
252
|
+
bindLive();
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case 'optional': {
|
|
258
|
+
Object.defineProperty(target, member, {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
configurable: true,
|
|
261
|
+
get(): AnyFn | undefined {
|
|
262
|
+
const current = live;
|
|
263
|
+
const fn = liveMember(member);
|
|
264
|
+
if (!fn) return undefined;
|
|
265
|
+
return (...args: never[]): unknown => fn.apply(current, args);
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const attach = (next: T): (() => void) => {
|
|
274
|
+
live = next;
|
|
275
|
+
bindLive();
|
|
276
|
+
notify();
|
|
277
|
+
return () => {
|
|
278
|
+
if (live !== next) return;
|
|
279
|
+
live = null;
|
|
280
|
+
bindLive();
|
|
281
|
+
notify();
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// THE ONE CAST. `exactOptionalPropertyTypes` forbids an optional member
|
|
286
|
+
// whose getter can yield `undefined`, but that is precisely the honest
|
|
287
|
+
// shape here — the getter IS how presence mirrors the live adapter — and a
|
|
288
|
+
// reflectively built object cannot be typed structurally anyway. Callers
|
|
289
|
+
// see exactly the absent/present behavior the adapter interface documents.
|
|
290
|
+
return { attach, slot: target as T };
|
|
291
|
+
}
|