@vgai/engine 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +35 -0
- package/package.json +55 -0
- package/src/adapter/authoring.ts +402 -0
- package/src/adapter/colyseus-networking-adapter.ts +72 -0
- package/src/adapter/first-party-systems.ts +103 -0
- package/src/adapter/game-adapter.ts +151 -0
- package/src/adapter/host-context.ts +77 -0
- package/src/adapter/index.ts +85 -0
- package/src/adapter/ingest/game-contract.ts +59 -0
- package/src/adapter/ingest/overlay-applier.ts +207 -0
- package/src/adapter/ingest/overlay-apply.ts +124 -0
- package/src/adapter/ingest/overlay-file.ts +126 -0
- package/src/adapter/ingest/overlay-report.ts +176 -0
- package/src/adapter/ingest/scene-capture.ts +307 -0
- package/src/adapter/ingest/upstream-pin.ts +52 -0
- package/src/adapter/loop-gate-report.ts +54 -0
- package/src/adapter/rapier-physics-adapter.ts +56 -0
- package/src/adapter/system-adapter.ts +154 -0
- package/src/adapter/transform.ts +18 -0
- package/src/adapter/vgai-scene-game-adapter.ts +886 -0
- package/src/adapter/world-kind.ts +34 -0
- package/src/ai/navigation.ts +164 -0
- package/src/animation/anim-graph-types.ts +56 -0
- package/src/animation/anim-graph.ts +406 -0
- package/src/animation/anim-system.ts +28 -0
- package/src/animation/blend-node.ts +119 -0
- package/src/animation/property-track.ts +178 -0
- package/src/animation/schema.ts +204 -0
- package/src/assets.ts +80 -0
- package/src/audio/ambient.ts +300 -0
- package/src/audio/impacts.ts +212 -0
- package/src/audio/index.ts +7 -0
- package/src/audio/movement.ts +140 -0
- package/src/audio/musical.ts +200 -0
- package/src/audio/ui-sounds.ts +171 -0
- package/src/audio/vehicle.ts +235 -0
- package/src/audio/weapons.ts +152 -0
- package/src/core/game-loop.ts +127 -0
- package/src/core/system-runner.ts +298 -0
- package/src/core/types.ts +58 -0
- package/src/dev/console-bridge.ts +83 -0
- package/src/dev/debug-draw.ts +80 -0
- package/src/dev/logger.ts +119 -0
- package/src/ecs/component-manager.ts +748 -0
- package/src/ecs/game-component.ts +147 -0
- package/src/ecs/hmr-swap-report.ts +65 -0
- package/src/input/input-manager.ts +439 -0
- package/src/input/input-types.ts +19 -0
- package/src/input/schema.ts +129 -0
- package/src/loader.ts +70 -0
- package/src/manifest/index.ts +24 -0
- package/src/manifest/load-file.ts +16 -0
- package/src/manifest/load.ts +378 -0
- package/src/manifest/schema.ts +375 -0
- package/src/physics/collision-system.ts +76 -0
- package/src/physics/physics-registry.ts +83 -0
- package/src/physics/transform-writer.ts +41 -0
- package/src/physics/trigger-dispatch.ts +97 -0
- package/src/react/game-state.tsx +172 -0
- package/src/render/auto-batcher.ts +169 -0
- package/src/render/render-batch-system.ts +268 -0
- package/src/render/render-features.ts +146 -0
- package/src/render/render-settings.ts +72 -0
- package/src/runtime/create-runtime.ts +1152 -0
- package/src/runtime/frame-selector-cache.ts +81 -0
- package/src/runtime/game.ts +1003 -0
- package/src/runtime/input-router.ts +213 -0
- package/src/runtime/mount-game.ts +269 -0
- package/src/runtime/mount-manifest.ts +361 -0
- package/src/runtime/scene-ui-bridge.ts +86 -0
- package/src/runtime/scene-ui-data.ts +119 -0
- package/src/runtime/state-bridge.ts +79 -0
- package/src/runtime/types.ts +196 -0
- package/src/scene/asset-loaders.ts +195 -0
- package/src/scene/asset-paths.ts +123 -0
- package/src/scene/asset-registry.ts +67 -0
- package/src/scene/collider-dimensions.ts +125 -0
- package/src/scene/component-registry.ts +40 -0
- package/src/scene/defaults.ts +164 -0
- package/src/scene/geometries/index.ts +7 -0
- package/src/scene/geometries/terrain.ts +42 -0
- package/src/scene/geometry-registry.ts +42 -0
- package/src/scene/instance-registry.ts +84 -0
- package/src/scene/instancers/grid.ts +38 -0
- package/src/scene/instancers/index.ts +7 -0
- package/src/scene/light-camera-factory.ts +97 -0
- package/src/scene/material-factory.ts +211 -0
- package/src/scene/material-registry.ts +73 -0
- package/src/scene/materials/index.ts +7 -0
- package/src/scene/materials/water.ts +56 -0
- package/src/scene/parse.ts +71 -0
- package/src/scene/particles-factory.ts +383 -0
- package/src/scene/scene-apply.ts +356 -0
- package/src/scene/scene-diff-schema.ts +115 -0
- package/src/scene/scene-diff-types.ts +29 -0
- package/src/scene/scene-loader.ts +1533 -0
- package/src/scene/scene-query.ts +63 -0
- package/src/scene/scene-types.ts +34 -0
- package/src/scene/scene-version.ts +40 -0
- package/src/scene/schema/animation.ts +95 -0
- package/src/scene/schema/audio.ts +25 -0
- package/src/scene/schema/camera.ts +21 -0
- package/src/scene/schema/collider.ts +69 -0
- package/src/scene/schema/entity-ref.ts +78 -0
- package/src/scene/schema/entity.ts +169 -0
- package/src/scene/schema/environment.ts +384 -0
- package/src/scene/schema/index.ts +95 -0
- package/src/scene/schema/instances.ts +35 -0
- package/src/scene/schema/joint.ts +26 -0
- package/src/scene/schema/light.ts +38 -0
- package/src/scene/schema/material.ts +113 -0
- package/src/scene/schema/mesh.ts +108 -0
- package/src/scene/schema/particles.ts +398 -0
- package/src/scene/schema/physics.ts +49 -0
- package/src/scene/schema/scene-file.ts +299 -0
- package/src/scene/schema/shadow.ts +24 -0
- package/src/scene/schema/spline.ts +21 -0
- package/src/scene/schema/tuples.ts +21 -0
- package/src/scene/schema/ui.ts +602 -0
- package/src/scene/user-data.ts +203 -0
- package/src/setup/setup-audio.ts +60 -0
- package/src/setup/setup-particles.ts +23 -0
- package/src/setup/setup-physics.ts +67 -0
- package/src/setup/setup-renderer.ts +529 -0
- package/src/types-n8ao.d.ts +37 -0
- package/src/types-realism-effects.d.ts +61 -0
- package/src/world2d/authoring-2d.ts +208 -0
- package/src/world2d/capture-to-scene2d.ts +52 -0
- package/src/world2d/collision-2d.ts +106 -0
- package/src/world2d/components-2d.ts +86 -0
- package/src/world2d/index.ts +66 -0
- package/src/world2d/ingest-iframe-2d.ts +255 -0
- package/src/world2d/ingest2d.ts +131 -0
- package/src/world2d/physics2d-registry.ts +49 -0
- package/src/world2d/pixi-game-adapter.ts +325 -0
- package/src/world2d/pixi-surface.ts +78 -0
- package/src/world2d/scene-capture-2d.ts +117 -0
- package/src/world2d/scene2d-loader.ts +308 -0
- package/src/world2d/schema/entity2d.ts +145 -0
- package/src/world2d/schema/physics2d.ts +53 -0
- package/src/world2d/schema/sprite.ts +71 -0
- package/src/world2d/schema/tilemap.ts +22 -0
- package/src/world2d/schema/tuples2d.ts +25 -0
- package/src/world2d/system-adapters-2d.ts +49 -0
- package/src/world2d/transform-writer-2d.ts +24 -0
- package/src/world2d/types.ts +55 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, react-free frame-version cache (T7.4 slice 1 — `docs/
|
|
3
|
+
* REACT-STATE-BRIDGE.md` §3). `useGameState` (`packages/editor/template/src/
|
|
4
|
+
* ui/game-state.tsx`) is a thin `useSyncExternalStore` wrapper
|
|
5
|
+
* around this: `getSnapshot` re-runs the selector once per `frameVersion`
|
|
6
|
+
* bump (`GameStateBridge`, `runtime/state-bridge.ts`), caches by version,
|
|
7
|
+
* and returns the PREVIOUS reference when `equals` holds against the fresh
|
|
8
|
+
* result — that reference stability is what lets `useSyncExternalStore`
|
|
9
|
+
* (and thus React) bail out of a re-render.
|
|
10
|
+
*
|
|
11
|
+
* Extracted to its own react-free module (no react import here, or anywhere
|
|
12
|
+
* under `runtime/`) so this cache/equality logic — the part of the hook
|
|
13
|
+
* that has real branching to get wrong — is unit-testable headlessly under
|
|
14
|
+
* `packages/engine/test/`, without needing a react test harness (none
|
|
15
|
+
* exists in this repo today; see `test/frame-selector-cache.test.ts`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Equality comparator for `FrameSelectorCache`/`useGameState`. Defaults to
|
|
19
|
+
* `Object.is` (T7.4 §3); pass {@link shallow} for tuples/plain objects. */
|
|
20
|
+
export type Equals<T> = (a: T, b: T) => boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One-level shallow-equality helper (own enumerable keys, `Object.is` per
|
|
24
|
+
* value) — the opt-in equality for selectors that return a fresh
|
|
25
|
+
* object/array/tuple every call. Two non-object values fall back to
|
|
26
|
+
* `Object.is`; a non-object compared against an object is never equal.
|
|
27
|
+
*/
|
|
28
|
+
export function shallow<T>(a: T, b: T): boolean {
|
|
29
|
+
if (Object.is(a, b)) return true;
|
|
30
|
+
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const aKeys = Object.keys(a as object);
|
|
34
|
+
const bKeys = Object.keys(b as object);
|
|
35
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
36
|
+
const bRecord = b as Record<string, unknown>;
|
|
37
|
+
for (const key of aKeys) {
|
|
38
|
+
if (!Object.is((a as Record<string, unknown>)[key], bRecord[key])) return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FrameSelectorCache<T> {
|
|
44
|
+
/**
|
|
45
|
+
* Return the cached value for `frameVersion` if it's the SAME version as
|
|
46
|
+
* the last call (selector not re-run at all). Otherwise call `compute()`
|
|
47
|
+
* once: if the fresh result is `equals` to the previously cached value,
|
|
48
|
+
* the PREVIOUS reference is returned (and re-tagged with this
|
|
49
|
+
* `frameVersion`, so the next same-version call also short-circuits);
|
|
50
|
+
* otherwise the fresh value is cached and returned.
|
|
51
|
+
*/
|
|
52
|
+
get(frameVersion: number, compute: () => T): T;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Construct a fresh per-subscriber cache. One per `useGameState` call site
|
|
56
|
+
* (a fresh cache each mount — see the hook). */
|
|
57
|
+
export function createFrameSelectorCache<T>(equals: Equals<T> = Object.is): FrameSelectorCache<T> {
|
|
58
|
+
let hasValue = false;
|
|
59
|
+
let cachedVersion = -1;
|
|
60
|
+
let cachedValue: T;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
get(frameVersion: number, compute: () => T): T {
|
|
64
|
+
if (hasValue && frameVersion === cachedVersion) {
|
|
65
|
+
return cachedValue;
|
|
66
|
+
}
|
|
67
|
+
const next = compute();
|
|
68
|
+
if (hasValue && equals(cachedValue, next)) {
|
|
69
|
+
// Bail-out: keep the PREVIOUS reference, but remember we're current
|
|
70
|
+
// as of this frameVersion so a repeat call at the same version
|
|
71
|
+
// doesn't even re-run `compute`.
|
|
72
|
+
cachedVersion = frameVersion;
|
|
73
|
+
return cachedValue;
|
|
74
|
+
}
|
|
75
|
+
cachedValue = next;
|
|
76
|
+
cachedVersion = frameVersion;
|
|
77
|
+
hasValue = true;
|
|
78
|
+
return cachedValue;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|