@multitapio/multitap 0.0.1
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/dist/.stamp +0 -0
- package/dist/cache.d.ts +117 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/channel.d.ts +91 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.worker.d.ts +3 -0
- package/dist/channel.worker.d.ts.map +1 -0
- package/dist/codegen/config.d.ts +107 -0
- package/dist/codegen/config.d.ts.map +1 -0
- package/dist/codegen/generator.d.ts +78 -0
- package/dist/codegen/generator.d.ts.map +1 -0
- package/dist/codegen/index.d.ts +13 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/inject.d.ts +51 -0
- package/dist/codegen/inject.d.ts.map +1 -0
- package/dist/codegen/rust.d.ts +22 -0
- package/dist/codegen/rust.d.ts.map +1 -0
- package/dist/codegen/typescript.d.ts +22 -0
- package/dist/codegen/typescript.d.ts.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/crypto.d.ts +141 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/debug.d.ts +39 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/diagnostics/index.d.ts +12 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics.js +5502 -0
- package/dist/e2e/cli.d.ts +2 -0
- package/dist/e2e/cli.d.ts.map +1 -0
- package/dist/executor.d.ts +130 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/globals.d.ts +32 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/input-codec.d.ts +136 -0
- package/dist/input-codec.d.ts.map +1 -0
- package/dist/input-graph.d.ts +106 -0
- package/dist/input-graph.d.ts.map +1 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +9409 -0
- package/dist/messages.d.ts +63 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/peer-mesh.d.ts +77 -0
- package/dist/peer-mesh.d.ts.map +1 -0
- package/dist/react/Crosshair.d.ts +17 -0
- package/dist/react/Crosshair.d.ts.map +1 -0
- package/dist/react/Player.d.ts +10 -0
- package/dist/react/Player.d.ts.map +1 -0
- package/dist/react/PlayerPoseContext.d.ts +31 -0
- package/dist/react/PlayerPoseContext.d.ts.map +1 -0
- package/dist/react/hooks/index.d.ts +7 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/useEvent.d.ts +46 -0
- package/dist/react/hooks/useEvent.d.ts.map +1 -0
- package/dist/react/hooks/useFrame.d.ts +23 -0
- package/dist/react/hooks/useFrame.d.ts.map +1 -0
- package/dist/react/hooks/usePlayers.d.ts +24 -0
- package/dist/react/hooks/usePlayers.d.ts.map +1 -0
- package/dist/react/hooks/useQuery.d.ts +41 -0
- package/dist/react/hooks/useQuery.d.ts.map +1 -0
- package/dist/react/hooks/useSession.d.ts +10 -0
- package/dist/react/hooks/useSession.d.ts.map +1 -0
- package/dist/react/index.d.ts +18 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/input/DesktopInputMapper.d.ts +38 -0
- package/dist/react/input/DesktopInputMapper.d.ts.map +1 -0
- package/dist/react/input/index.d.ts +4 -0
- package/dist/react/input/index.d.ts.map +1 -0
- package/dist/react/input/types.d.ts +46 -0
- package/dist/react/input/types.d.ts.map +1 -0
- package/dist/react/providers/SessionProvider.d.ts +17 -0
- package/dist/react/providers/SessionProvider.d.ts.map +1 -0
- package/dist/react/providers/index.d.ts +2 -0
- package/dist/react/providers/index.d.ts.map +1 -0
- package/dist/react/types/index.d.ts +2 -0
- package/dist/react/types/index.d.ts.map +1 -0
- package/dist/react/types/session.d.ts +88 -0
- package/dist/react/types/session.d.ts.map +1 -0
- package/dist/react/types.d.ts +134 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/utils/math.d.ts +19 -0
- package/dist/react/utils/math.d.ts.map +1 -0
- package/dist/react/views/AsteroidsView.d.ts +24 -0
- package/dist/react/views/AsteroidsView.d.ts.map +1 -0
- package/dist/react/views/FirstPersonView.d.ts +10 -0
- package/dist/react/views/FirstPersonView.d.ts.map +1 -0
- package/dist/react/views/IsometricView.d.ts +21 -0
- package/dist/react/views/IsometricView.d.ts.map +1 -0
- package/dist/react/views/MapView.d.ts +16 -0
- package/dist/react/views/MapView.d.ts.map +1 -0
- package/dist/react/views/MobaView.d.ts +17 -0
- package/dist/react/views/MobaView.d.ts.map +1 -0
- package/dist/react/views/SideOnView.d.ts +23 -0
- package/dist/react/views/SideOnView.d.ts.map +1 -0
- package/dist/react/views/ThirdPersonFixedView.d.ts +21 -0
- package/dist/react/views/ThirdPersonFixedView.d.ts.map +1 -0
- package/dist/react/views/ThirdPersonView.d.ts +12 -0
- package/dist/react/views/ThirdPersonView.d.ts.map +1 -0
- package/dist/react/views/TopDownFixedView.d.ts +20 -0
- package/dist/react/views/TopDownFixedView.d.ts.map +1 -0
- package/dist/react/views/TopDownView.d.ts +12 -0
- package/dist/react/views/TopDownView.d.ts.map +1 -0
- package/dist/react/views/TwinStickView.d.ts +13 -0
- package/dist/react/views/TwinStickView.d.ts.map +1 -0
- package/dist/react/views/VehicleFixedView.d.ts +16 -0
- package/dist/react/views/VehicleFixedView.d.ts.map +1 -0
- package/dist/react/views/VehicleView.d.ts +13 -0
- package/dist/react/views/VehicleView.d.ts.map +1 -0
- package/dist/react/views/index.d.ts +21 -0
- package/dist/react/views/index.d.ts.map +1 -0
- package/dist/react/views/types.d.ts +136 -0
- package/dist/react/views/types.d.ts.map +1 -0
- package/dist/rollback.d.ts +193 -0
- package/dist/rollback.d.ts.map +1 -0
- package/dist/rollback.worker.d.ts +3 -0
- package/dist/rollback.worker.d.ts.map +1 -0
- package/dist/schema.d.ts +309 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/session-config.d.ts +119 -0
- package/dist/session-config.d.ts.map +1 -0
- package/dist/session.d.ts +120 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/state.d.ts +400 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/stats.d.ts +21 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/test-session.d.ts +170 -0
- package/dist/test-session.d.ts.map +1 -0
- package/dist/types/cache.d.ts +117 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/channel.d.ts +91 -0
- package/dist/types/channel.d.ts.map +1 -0
- package/dist/types/channel.worker.d.ts +3 -0
- package/dist/types/channel.worker.d.ts.map +1 -0
- package/dist/types/codegen/config.d.ts +107 -0
- package/dist/types/codegen/config.d.ts.map +1 -0
- package/dist/types/codegen/generator.d.ts +78 -0
- package/dist/types/codegen/generator.d.ts.map +1 -0
- package/dist/types/codegen/index.d.ts +13 -0
- package/dist/types/codegen/index.d.ts.map +1 -0
- package/dist/types/codegen/inject.d.ts +51 -0
- package/dist/types/codegen/inject.d.ts.map +1 -0
- package/dist/types/codegen/rust.d.ts +22 -0
- package/dist/types/codegen/rust.d.ts.map +1 -0
- package/dist/types/codegen/typescript.d.ts +22 -0
- package/dist/types/codegen/typescript.d.ts.map +1 -0
- package/dist/types/constants.d.ts +5 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/crypto.d.ts +141 -0
- package/dist/types/crypto.d.ts.map +1 -0
- package/dist/types/debug.d.ts +39 -0
- package/dist/types/debug.d.ts.map +1 -0
- package/dist/types/diagnostics/index.d.ts +12 -0
- package/dist/types/diagnostics/index.d.ts.map +1 -0
- package/dist/types/e2e/cli.d.ts +2 -0
- package/dist/types/e2e/cli.d.ts.map +1 -0
- package/dist/types/executor.d.ts +130 -0
- package/dist/types/executor.d.ts.map +1 -0
- package/dist/types/helpers.d.ts +3 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/input-codec.d.ts +136 -0
- package/dist/types/input-codec.d.ts.map +1 -0
- package/dist/types/input-graph.d.ts +106 -0
- package/dist/types/input-graph.d.ts.map +1 -0
- package/dist/types/lib.d.ts +10 -0
- package/dist/types/lib.d.ts.map +1 -0
- package/dist/types/messages.d.ts +63 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/peer-mesh.d.ts +77 -0
- package/dist/types/peer-mesh.d.ts.map +1 -0
- package/dist/types/react/Crosshair.d.ts +17 -0
- package/dist/types/react/Crosshair.d.ts.map +1 -0
- package/dist/types/react/Player.d.ts +10 -0
- package/dist/types/react/Player.d.ts.map +1 -0
- package/dist/types/react/PlayerPoseContext.d.ts +31 -0
- package/dist/types/react/PlayerPoseContext.d.ts.map +1 -0
- package/dist/types/react/hooks/index.d.ts +7 -0
- package/dist/types/react/hooks/index.d.ts.map +1 -0
- package/dist/types/react/hooks/useEvent.d.ts +46 -0
- package/dist/types/react/hooks/useEvent.d.ts.map +1 -0
- package/dist/types/react/hooks/useFrame.d.ts +23 -0
- package/dist/types/react/hooks/useFrame.d.ts.map +1 -0
- package/dist/types/react/hooks/usePlayers.d.ts +24 -0
- package/dist/types/react/hooks/usePlayers.d.ts.map +1 -0
- package/dist/types/react/hooks/useQuery.d.ts +41 -0
- package/dist/types/react/hooks/useQuery.d.ts.map +1 -0
- package/dist/types/react/hooks/useSession.d.ts +10 -0
- package/dist/types/react/hooks/useSession.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +18 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/input/DesktopInputMapper.d.ts +38 -0
- package/dist/types/react/input/DesktopInputMapper.d.ts.map +1 -0
- package/dist/types/react/input/index.d.ts +4 -0
- package/dist/types/react/input/index.d.ts.map +1 -0
- package/dist/types/react/input/types.d.ts +46 -0
- package/dist/types/react/input/types.d.ts.map +1 -0
- package/dist/types/react/providers/SessionProvider.d.ts +17 -0
- package/dist/types/react/providers/SessionProvider.d.ts.map +1 -0
- package/dist/types/react/providers/index.d.ts +2 -0
- package/dist/types/react/providers/index.d.ts.map +1 -0
- package/dist/types/react/types/index.d.ts +2 -0
- package/dist/types/react/types/index.d.ts.map +1 -0
- package/dist/types/react/types/session.d.ts +88 -0
- package/dist/types/react/types/session.d.ts.map +1 -0
- package/dist/types/react/types.d.ts +134 -0
- package/dist/types/react/types.d.ts.map +1 -0
- package/dist/types/react/utils/math.d.ts +19 -0
- package/dist/types/react/utils/math.d.ts.map +1 -0
- package/dist/types/react/views/AsteroidsView.d.ts +24 -0
- package/dist/types/react/views/AsteroidsView.d.ts.map +1 -0
- package/dist/types/react/views/FirstPersonView.d.ts +10 -0
- package/dist/types/react/views/FirstPersonView.d.ts.map +1 -0
- package/dist/types/react/views/IsometricView.d.ts +21 -0
- package/dist/types/react/views/IsometricView.d.ts.map +1 -0
- package/dist/types/react/views/MapView.d.ts +16 -0
- package/dist/types/react/views/MapView.d.ts.map +1 -0
- package/dist/types/react/views/MobaView.d.ts +17 -0
- package/dist/types/react/views/MobaView.d.ts.map +1 -0
- package/dist/types/react/views/SideOnView.d.ts +23 -0
- package/dist/types/react/views/SideOnView.d.ts.map +1 -0
- package/dist/types/react/views/ThirdPersonFixedView.d.ts +21 -0
- package/dist/types/react/views/ThirdPersonFixedView.d.ts.map +1 -0
- package/dist/types/react/views/ThirdPersonView.d.ts +12 -0
- package/dist/types/react/views/ThirdPersonView.d.ts.map +1 -0
- package/dist/types/react/views/TopDownFixedView.d.ts +20 -0
- package/dist/types/react/views/TopDownFixedView.d.ts.map +1 -0
- package/dist/types/react/views/TopDownView.d.ts +12 -0
- package/dist/types/react/views/TopDownView.d.ts.map +1 -0
- package/dist/types/react/views/TwinStickView.d.ts +13 -0
- package/dist/types/react/views/TwinStickView.d.ts.map +1 -0
- package/dist/types/react/views/VehicleFixedView.d.ts +16 -0
- package/dist/types/react/views/VehicleFixedView.d.ts.map +1 -0
- package/dist/types/react/views/VehicleView.d.ts +13 -0
- package/dist/types/react/views/VehicleView.d.ts.map +1 -0
- package/dist/types/react/views/index.d.ts +21 -0
- package/dist/types/react/views/index.d.ts.map +1 -0
- package/dist/types/react/views/types.d.ts +136 -0
- package/dist/types/react/views/types.d.ts.map +1 -0
- package/dist/types/rollback.d.ts +193 -0
- package/dist/types/rollback.d.ts.map +1 -0
- package/dist/types/rollback.worker.d.ts +3 -0
- package/dist/types/rollback.worker.d.ts.map +1 -0
- package/dist/types/schema.d.ts +309 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/session-config.d.ts +119 -0
- package/dist/types/session-config.d.ts.map +1 -0
- package/dist/types/session.d.ts +120 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/state.d.ts +400 -0
- package/dist/types/state.d.ts.map +1 -0
- package/dist/types/stats.d.ts +21 -0
- package/dist/types/stats.d.ts.map +1 -0
- package/dist/types/test-session.d.ts +170 -0
- package/dist/types/test-session.d.ts.map +1 -0
- package/dist/types/utils.d.ts +26 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/vite/codegen-runner.d.ts +27 -0
- package/dist/types/vite/codegen-runner.d.ts.map +1 -0
- package/dist/types/vite/index.d.ts +20 -0
- package/dist/types/vite/index.d.ts.map +1 -0
- package/dist/types/vite/module-builder.d.ts +28 -0
- package/dist/types/vite/module-builder.d.ts.map +1 -0
- package/dist/types/vite/plugin.d.ts +27 -0
- package/dist/types/vite/plugin.d.ts.map +1 -0
- package/dist/types/vite/types.d.ts +37 -0
- package/dist/types/vite/types.d.ts.map +1 -0
- package/dist/types/vite/wasm-compiler.d.ts +32 -0
- package/dist/types/vite/wasm-compiler.d.ts.map +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/vite/codegen-runner.d.ts +27 -0
- package/dist/vite/codegen-runner.d.ts.map +1 -0
- package/dist/vite/index.d.ts +20 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +4202 -0
- package/dist/vite/module-builder.d.ts +28 -0
- package/dist/vite/module-builder.d.ts.map +1 -0
- package/dist/vite/plugin.d.ts +27 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/types.d.ts +37 -0
- package/dist/vite/types.d.ts.map +1 -0
- package/dist/vite/wasm-compiler.d.ts +32 -0
- package/dist/vite/wasm-compiler.d.ts.map +1 -0
- package/package.json +92 -0
package/dist/stats.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class RollingCounter {
|
|
2
|
+
private readonly buffer;
|
|
3
|
+
private readonly windowMs;
|
|
4
|
+
private head;
|
|
5
|
+
private tail;
|
|
6
|
+
private size;
|
|
7
|
+
constructor(windowMs?: number, maxEvents?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Record a single event at the given timestamp
|
|
10
|
+
*/
|
|
11
|
+
inc(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Returns number of events within the rolling window
|
|
14
|
+
*/
|
|
15
|
+
count(now?: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the rate of events per second
|
|
18
|
+
*/
|
|
19
|
+
rate(now?: number): number;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/stats.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;gBAEL,QAAQ,GAAE,MAAa,EAAE,SAAS,GAAE,MAAa;IAK7D;;OAEG;IACH,GAAG,IAAI,IAAI;IAcX;;OAEG;IACH,KAAK,CAAC,GAAG,GAAE,MAA0B,GAAG,MAAM;IAc9C;;OAEG;IACH,IAAI,CAAC,GAAG,GAAE,MAA0B,GAAG,MAAM;CAG9C"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TestSession - Headless simulation testing for Multitap games.
|
|
3
|
+
*
|
|
4
|
+
* Enables AI agents and developers to test game logic without network or WebWorkers.
|
|
5
|
+
* Wraps Rollback + InputGraph with a simple API for input simulation and state inspection.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Auto-generated player keys (no crypto knowledge needed)
|
|
9
|
+
* - State history with cursor for rollback testing
|
|
10
|
+
* - Direct state buffer access for use with generated ECS bindings
|
|
11
|
+
*
|
|
12
|
+
* @module test-session
|
|
13
|
+
*/
|
|
14
|
+
import { type TickResult } from './rollback';
|
|
15
|
+
import { type CompiledSchema, type StateSchema, type StateBuffer } from './state';
|
|
16
|
+
import { type InputSchema } from './input-codec';
|
|
17
|
+
import type { Participant, SessionOptions, MultitapPlugin } from './session';
|
|
18
|
+
/**
|
|
19
|
+
* Options for creating a TestSession.
|
|
20
|
+
*/
|
|
21
|
+
export interface TestSessionOptions {
|
|
22
|
+
/** Plugins array (WASM modules in execution order) */
|
|
23
|
+
plugins: MultitapPlugin[];
|
|
24
|
+
/** State and input schemas */
|
|
25
|
+
schema: {
|
|
26
|
+
state: StateSchema | CompiledSchema;
|
|
27
|
+
input: InputSchema;
|
|
28
|
+
};
|
|
29
|
+
/** Tick rate in Hz (default: 20) */
|
|
30
|
+
tickRate?: number;
|
|
31
|
+
/** Maximum ticks for the session (default: 10000) */
|
|
32
|
+
maxTicks?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A test player that can submit inputs.
|
|
36
|
+
*/
|
|
37
|
+
export interface TestPlayer {
|
|
38
|
+
/** The player's slot index (0-15) */
|
|
39
|
+
readonly index: number;
|
|
40
|
+
/**
|
|
41
|
+
* Queue an input for this player.
|
|
42
|
+
* The input will be applied on the next tick() call.
|
|
43
|
+
*
|
|
44
|
+
* @param payload - Raw input bytes (use InputCodec to encode)
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const inputCodec = compileInputCodec(inputSchema);
|
|
49
|
+
* const input = inputCodec.create();
|
|
50
|
+
* input.setFlags('buttons', { up: true, fire: true });
|
|
51
|
+
* player.input(input.encode());
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
input(payload: Uint8Array): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* TestSession provides headless simulation testing for Multitap games.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const session = await TestSession.create({
|
|
62
|
+
* plugins: [{ name: 'game', wasmBytes, reservedBytes: 4194304 }],
|
|
63
|
+
* schema: { state: stateSchema, input: inputSchema },
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* const p1 = session.addPlayer();
|
|
67
|
+
* const p2 = session.addPlayer();
|
|
68
|
+
*
|
|
69
|
+
* p1.input({ buttons: { up: true } });
|
|
70
|
+
* p2.input({ buttons: { fire: true } });
|
|
71
|
+
*
|
|
72
|
+
* await session.tick();
|
|
73
|
+
* console.log('Tick:', session.getTick()); // 1
|
|
74
|
+
*
|
|
75
|
+
* // Test rollback
|
|
76
|
+
* await session.tick(10);
|
|
77
|
+
* session.rollback(5);
|
|
78
|
+
* await session.tick();
|
|
79
|
+
* console.log('Tick:', session.getTick()); // 6
|
|
80
|
+
*
|
|
81
|
+
* // Use state with generated bindings
|
|
82
|
+
* const state = session.getState();
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare class TestSession {
|
|
86
|
+
private inputGraph;
|
|
87
|
+
private asyncInputGraph;
|
|
88
|
+
private rollbackManager;
|
|
89
|
+
private executor;
|
|
90
|
+
private stateSchema;
|
|
91
|
+
private inputCodec;
|
|
92
|
+
private genesisHash;
|
|
93
|
+
private players;
|
|
94
|
+
private joinedPlayers;
|
|
95
|
+
private pendingInputs;
|
|
96
|
+
private states;
|
|
97
|
+
private cursor;
|
|
98
|
+
private constructor();
|
|
99
|
+
/**
|
|
100
|
+
* Create a new TestSession.
|
|
101
|
+
*/
|
|
102
|
+
static create(options: TestSessionOptions): Promise<TestSession>;
|
|
103
|
+
getParticipants(): Participant[];
|
|
104
|
+
/**
|
|
105
|
+
* Create a TestSession from SessionOptions.
|
|
106
|
+
* Ignores network-related properties (playerKey, authority, renderer, etc.)
|
|
107
|
+
*
|
|
108
|
+
* This allows using the same options object for both production Session
|
|
109
|
+
* and headless TestSession.
|
|
110
|
+
*/
|
|
111
|
+
static fromConfig(options: SessionOptions): Promise<TestSession>;
|
|
112
|
+
/**
|
|
113
|
+
* Add a new player to the session.
|
|
114
|
+
* Returns a TestPlayer wrapper for submitting inputs.
|
|
115
|
+
*
|
|
116
|
+
* @param privateKey - Optional private key for deterministic replay testing
|
|
117
|
+
*/
|
|
118
|
+
addPlayer(privateKey?: Uint8Array): TestPlayer;
|
|
119
|
+
/**
|
|
120
|
+
* Queue an input for a player. Called by TestPlayer.input().
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
_queueInput(playerIndex: number, privateKey: Uint8Array, payload: Uint8Array): void;
|
|
124
|
+
/**
|
|
125
|
+
* Advance the simulation by one or more ticks.
|
|
126
|
+
*
|
|
127
|
+
* If cursor is behind the state history, this just moves the cursor forward.
|
|
128
|
+
* Otherwise, it runs the actual simulation to compute new states.
|
|
129
|
+
*/
|
|
130
|
+
tick(count?: number): Promise<TickResult>;
|
|
131
|
+
/**
|
|
132
|
+
* Run multiple ticks with an optional callback before each tick.
|
|
133
|
+
*
|
|
134
|
+
* @param count - Number of ticks to run
|
|
135
|
+
* @param onTick - Optional callback called before each tick with current tick number
|
|
136
|
+
* @returns The result of the last tick
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Run 50 ticks with player input each tick
|
|
141
|
+
* await session.runTicks(50, () => {
|
|
142
|
+
* player.input(fireInput);
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
runTicks(count: number, onTick?: (tick: number) => Promise<void>): Promise<TickResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Rewind the simulation to a previous tick.
|
|
149
|
+
* The next tick() call will produce tick N+1.
|
|
150
|
+
*/
|
|
151
|
+
rollback(toTick: number): void;
|
|
152
|
+
/**
|
|
153
|
+
* Get the current state buffer.
|
|
154
|
+
* Use with generated ECS bindings for state inspection.
|
|
155
|
+
*/
|
|
156
|
+
getState(): StateBuffer;
|
|
157
|
+
/**
|
|
158
|
+
* Get the current tick number.
|
|
159
|
+
*/
|
|
160
|
+
getTick(): number;
|
|
161
|
+
/**
|
|
162
|
+
* Clean up resources.
|
|
163
|
+
*/
|
|
164
|
+
close(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Compute the next tick by processing pending inputs.
|
|
167
|
+
*/
|
|
168
|
+
private computeNextTick;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=test-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-session.d.ts","sourceRoot":"","sources":["../../src/test-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7E,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClG,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAIrF,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM7E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sDAAsD;IACtD,OAAO,EAAE,cAAc,EAAE,CAAC;IAE1B,8BAA8B;IAC9B,MAAM,EAAE;QACN,KAAK,EAAE,WAAW,GAAG,cAAc,CAAC;QACpC,KAAK,EAAE,WAAW,CAAC;KACpB,CAAC;IAEF,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;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AAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAW5F;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAO9B;;;OAGG;IACH,QAAQ,IAAI,WAAW;IAIvB;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;YACW,eAAe;CA+C9B"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Cache for Rollback Networking
|
|
3
|
+
*
|
|
4
|
+
* Provides O(1) lookup of cached states by their stateId.
|
|
5
|
+
* Used during rollback to avoid redundant state transitions when
|
|
6
|
+
* authoritative inputs match predictions.
|
|
7
|
+
*
|
|
8
|
+
* @module state-cache
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Convert a 32-byte stateId to a 64-character hex string for use as Map key.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stateIdToKey(stateId: Uint8Array): string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a 64-character hex string back to a 32-byte stateId.
|
|
16
|
+
*/
|
|
17
|
+
export declare function keyToStateId(key: string): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Options for StateCache configuration.
|
|
20
|
+
*/
|
|
21
|
+
export interface StateCacheOptions {
|
|
22
|
+
/** Maximum number of states to cache. Default: 100. */
|
|
23
|
+
maxSize?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Cache for state snapshots keyed by stateId.
|
|
27
|
+
*
|
|
28
|
+
* Provides O(1) lookup to avoid redundant state transitions during rollback.
|
|
29
|
+
* When authoritative inputs match predictions, we can retrieve the cached
|
|
30
|
+
* state instead of recomputing.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const cache = new StateCache();
|
|
35
|
+
*
|
|
36
|
+
* // After computing a state transition
|
|
37
|
+
* cache.store(state);
|
|
38
|
+
*
|
|
39
|
+
* // Before computing a state transition, check cache
|
|
40
|
+
* const cached = cache.getCached(prevState, tick, orderedPayloadsHash);
|
|
41
|
+
* if (cached) {
|
|
42
|
+
* // Use cached state, skip computation
|
|
43
|
+
* return cached;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class StateCache {
|
|
48
|
+
private cache;
|
|
49
|
+
private maxSize;
|
|
50
|
+
constructor(options?: StateCacheOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Store a state in the cache, keyed by its embedded stateId.
|
|
53
|
+
* Makes a copy of the state buffer to prevent mutation issues.
|
|
54
|
+
*
|
|
55
|
+
* @param state - State buffer to cache
|
|
56
|
+
*/
|
|
57
|
+
store(state: Uint8Array): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get a cached state by its stateId.
|
|
60
|
+
* Returns a copy of the cached state, or undefined if not found.
|
|
61
|
+
*
|
|
62
|
+
* @param stateId - 32-byte stateId to look up
|
|
63
|
+
* @returns Copy of cached state, or undefined
|
|
64
|
+
*/
|
|
65
|
+
getByStateId(stateId: Uint8Array): Uint8Array | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Get the cached state that would result from a state transition.
|
|
68
|
+
*
|
|
69
|
+
* This is the key API for rollback optimization:
|
|
70
|
+
* - Computes what the resulting stateId would be
|
|
71
|
+
* - Looks up that stateId in the cache
|
|
72
|
+
* - If found, returns the cached state (avoiding recomputation)
|
|
73
|
+
*
|
|
74
|
+
* @param prevState - Previous state buffer
|
|
75
|
+
* @param tick - Tick number
|
|
76
|
+
* @param orderedPayloadsHash - 32-byte hash of ordered payloads (one per participant at stable indices)
|
|
77
|
+
* @returns Copy of cached state, or undefined if not found
|
|
78
|
+
*/
|
|
79
|
+
getCached(prevState: Uint8Array, tick: number, orderedPayloadsHash: Uint8Array): Uint8Array | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Check if we have a cached state for a given stateId.
|
|
82
|
+
*
|
|
83
|
+
* @param stateId - 32-byte stateId to check
|
|
84
|
+
* @returns true if cached
|
|
85
|
+
*/
|
|
86
|
+
has(stateId: Uint8Array): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Check if we would have a cached state after a transition.
|
|
89
|
+
*
|
|
90
|
+
* @param prevState - Previous state buffer
|
|
91
|
+
* @param tick - Tick number
|
|
92
|
+
* @param orderedPayloadsHash - 32-byte hash of ordered payloads (one per participant at stable indices)
|
|
93
|
+
* @returns true if we have a cached result for this transition
|
|
94
|
+
*/
|
|
95
|
+
hasCached(prevState: Uint8Array, tick: number, orderedPayloadsHash: Uint8Array): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Remove a cached state by its stateId.
|
|
98
|
+
*
|
|
99
|
+
* @param stateId - 32-byte stateId to remove
|
|
100
|
+
* @returns true if the state was in the cache
|
|
101
|
+
*/
|
|
102
|
+
delete(stateId: Uint8Array): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Clear all cached states.
|
|
105
|
+
*/
|
|
106
|
+
clear(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Get the number of cached states.
|
|
109
|
+
*/
|
|
110
|
+
get size(): number;
|
|
111
|
+
/**
|
|
112
|
+
* Get all cached stateIds (as hex keys).
|
|
113
|
+
* Useful for debugging.
|
|
114
|
+
*/
|
|
115
|
+
keys(): IterableIterator<string>;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAOxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CASpD;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,iBAAsB;IAK3C;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAgB9B;;;;;;OAMG;IACH,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS;IAMzD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS;IAMvG;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO;IAKjC;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,UAAU,GAAG,OAAO;IAMxF;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO;IAKpC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;CAGjC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { InputData, TickMessage } from './messages';
|
|
2
|
+
import { InputGraph, type AsyncTickLog, type GetTicksAfterOptions, type Participant, type PayloadPredictor, type TickNode, type TickPrimitive } from './input-graph';
|
|
3
|
+
export type TickListener = (tick: TickMessage, streamIndex: number) => void;
|
|
4
|
+
export type StateListener = (connected: boolean) => void;
|
|
5
|
+
export type StreamActivityListener = (streamIndex: number) => void;
|
|
6
|
+
export type StreamLifecycleListener = (event: StreamLifecycleEvent) => void;
|
|
7
|
+
export type UnsubscribeFn = () => void;
|
|
8
|
+
export interface StreamLifecycleEvent {
|
|
9
|
+
type: 'added' | 'removed';
|
|
10
|
+
index: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ChannelConfig {
|
|
13
|
+
/** multitap:// connection URL (will be base64-encoded for transport) */
|
|
14
|
+
connectionURL: string;
|
|
15
|
+
serverCertHash: string | null | undefined;
|
|
16
|
+
privateKey?: Uint8Array;
|
|
17
|
+
relayPubKey?: Uint8Array | undefined | null;
|
|
18
|
+
inputPayloadPredictor?: PayloadPredictor | null;
|
|
19
|
+
debug?: boolean | undefined;
|
|
20
|
+
autoConnect?: boolean | undefined;
|
|
21
|
+
connectionTimeoutMs?: number | undefined;
|
|
22
|
+
logSyncTicks?: boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class Channel implements AsyncTickLog {
|
|
25
|
+
readonly connectionURL: string;
|
|
26
|
+
readonly serverCertHash: string | null | undefined;
|
|
27
|
+
readonly connectionTimeoutMs: number;
|
|
28
|
+
private privateKey;
|
|
29
|
+
private publicKey;
|
|
30
|
+
private genesisHash;
|
|
31
|
+
private sessionConfig;
|
|
32
|
+
private transport;
|
|
33
|
+
private streams;
|
|
34
|
+
private replayStreams;
|
|
35
|
+
private roundRobinIndex;
|
|
36
|
+
private connectionGeneration;
|
|
37
|
+
private connected;
|
|
38
|
+
private stopped;
|
|
39
|
+
private debug;
|
|
40
|
+
private logSyncTicks;
|
|
41
|
+
private outbox;
|
|
42
|
+
private stateListeners;
|
|
43
|
+
private flushingOutbox;
|
|
44
|
+
private tickRate;
|
|
45
|
+
inputGraph: InputGraph;
|
|
46
|
+
private tickDeadlineWants;
|
|
47
|
+
private tickDeadlineTimer;
|
|
48
|
+
private tickDeadlineGrace;
|
|
49
|
+
private stats;
|
|
50
|
+
constructor(config: ChannelConfig);
|
|
51
|
+
connect(): Promise<void>;
|
|
52
|
+
getPublicKey(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
53
|
+
getGenesisHash(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
54
|
+
onStateChange(fn: StateListener): UnsubscribeFn;
|
|
55
|
+
getStats(): {
|
|
56
|
+
activeStreams: number;
|
|
57
|
+
totalStreams: number;
|
|
58
|
+
messagesRecv: number;
|
|
59
|
+
messagesSent: number;
|
|
60
|
+
reconnections: number;
|
|
61
|
+
};
|
|
62
|
+
getTickRate(): Promise<number>;
|
|
63
|
+
getParticipantSlots(tick: number): Promise<Participant[]>;
|
|
64
|
+
getSyncHead(): Promise<TickNode>;
|
|
65
|
+
getPredictedHead(): Promise<TickNode>;
|
|
66
|
+
addSyncTick(msg: TickMessage): Promise<void>;
|
|
67
|
+
addOptimisticInput(input: InputData, preVerifiedSigner?: Uint8Array): Promise<void>;
|
|
68
|
+
getPredictionCount(): Promise<number>;
|
|
69
|
+
getTicksAfter(nodeId: string | null, options?: GetTicksAfterOptions): Promise<TickPrimitive[]>;
|
|
70
|
+
setOnParticipantJoined(fn: (participant: Participant) => void): Promise<void>;
|
|
71
|
+
expose(port: MessagePort): Promise<void>;
|
|
72
|
+
close(): Promise<void>;
|
|
73
|
+
private _setConnected;
|
|
74
|
+
private _send;
|
|
75
|
+
private _generateNullInput;
|
|
76
|
+
sendSignedInput(payload: Uint8Array, targetTick?: number): Promise<Uint8Array>;
|
|
77
|
+
private _nextStream;
|
|
78
|
+
private _connectLoop;
|
|
79
|
+
private _acceptStreamsLoop;
|
|
80
|
+
private _addStream;
|
|
81
|
+
private _dropStream;
|
|
82
|
+
private _cleanupHandle;
|
|
83
|
+
private _flushOutbox;
|
|
84
|
+
private _cleanupTransport;
|
|
85
|
+
private _readLoop;
|
|
86
|
+
private _maybeResetDeadline;
|
|
87
|
+
private _resetDeadline;
|
|
88
|
+
private _onTickDeadlineExceeded;
|
|
89
|
+
private _concatBuffers;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/channel.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAe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AAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAInF,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAI9F,sBAAsB,CAAC,EAAE,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7E,MAAM,CAAC,IAAI,EAAE,WAAW;IAKxB,KAAK;IAeX,OAAO,CAAC,aAAa;YAaP,KAAK;IA0BnB,OAAO,CAAC,kBAAkB;IAWpB,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAkCpF,OAAO,CAAC,WAAW;YAQL,YAAY;YA4EZ,kBAAkB;IA6ChC,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,cAAc;YAmBR,YAAY;IA0B1B,OAAO,CAAC,iBAAiB;YAsBX,SAAS;IAwGvB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,uBAAuB;IA8B/B,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.worker.d.ts","sourceRoot":"","sources":["../../src/channel.worker.ts"],"names":[],"mappings":"wBAMkC,UAAU,MAAM;AAAlD,wBAAmD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loading and plugin graph management for codegen.
|
|
3
|
+
*
|
|
4
|
+
* This module provides:
|
|
5
|
+
* - Config type matching mt.config.json structure
|
|
6
|
+
* - Project loading and config file discovery
|
|
7
|
+
* - Plugin dependency graph construction
|
|
8
|
+
* - Schema merging across plugins
|
|
9
|
+
*
|
|
10
|
+
* @module codegen/config
|
|
11
|
+
*/
|
|
12
|
+
import type { StateSchema, InputSchema } from '../schema';
|
|
13
|
+
/**
|
|
14
|
+
* WASM configuration for plugins.
|
|
15
|
+
*/
|
|
16
|
+
export interface WasmConfig {
|
|
17
|
+
/** Number of bytes to reserve in shared WASM memory for this plugin */
|
|
18
|
+
reservedBytes: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Root configuration structure (mt.config.json).
|
|
22
|
+
*/
|
|
23
|
+
export interface Config {
|
|
24
|
+
appID: string;
|
|
25
|
+
entrypoint: string;
|
|
26
|
+
output: string;
|
|
27
|
+
tests?: string[];
|
|
28
|
+
tickRate: number;
|
|
29
|
+
maxTicks: number;
|
|
30
|
+
maxParticipants: number;
|
|
31
|
+
plugins?: string[];
|
|
32
|
+
wasm?: WasmConfig;
|
|
33
|
+
input: InputSchema;
|
|
34
|
+
state: StateSchema;
|
|
35
|
+
fixtures?: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A loaded project with its configuration and paths.
|
|
39
|
+
*/
|
|
40
|
+
export interface Project {
|
|
41
|
+
/** Parsed project configuration */
|
|
42
|
+
config: Config;
|
|
43
|
+
/** Absolute path to the config file */
|
|
44
|
+
configPath: string;
|
|
45
|
+
/** Absolute path to the project directory */
|
|
46
|
+
dir: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A node in the plugin dependency graph.
|
|
50
|
+
*/
|
|
51
|
+
export interface PluginNode {
|
|
52
|
+
/** Absolute path to the plugin directory */
|
|
53
|
+
path: string;
|
|
54
|
+
/** Parsed plugin configuration */
|
|
55
|
+
config: Config;
|
|
56
|
+
/** Absolute paths of plugins this node depends on */
|
|
57
|
+
dependencies: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The complete plugin dependency graph.
|
|
61
|
+
*/
|
|
62
|
+
export interface ConfigGraph {
|
|
63
|
+
/** Root project */
|
|
64
|
+
root: Project;
|
|
65
|
+
/** Plugin nodes mapped by absolute path */
|
|
66
|
+
plugins: Map<string, PluginNode>;
|
|
67
|
+
/** Topologically sorted list of plugin paths (dependencies first) */
|
|
68
|
+
order: string[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of merging all plugin configs.
|
|
72
|
+
*/
|
|
73
|
+
export interface MergedConfig {
|
|
74
|
+
/** Merged configuration with all components */
|
|
75
|
+
config: Config;
|
|
76
|
+
/** Execution order of plugins (dependencies first) */
|
|
77
|
+
pluginOrder: string[];
|
|
78
|
+
/** Maps component names to the plugin path that defined them */
|
|
79
|
+
componentOwners: Map<string, string>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Find a *mt.config.json file in the given path.
|
|
83
|
+
* If path is a file, returns it directly.
|
|
84
|
+
* If path is a directory, searches for files ending in mt.config.json.
|
|
85
|
+
*/
|
|
86
|
+
export declare function findConfig(path: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Load and parse a config file.
|
|
89
|
+
*/
|
|
90
|
+
export declare function loadConfig(path: string): Config;
|
|
91
|
+
/**
|
|
92
|
+
* Load a project from the given path.
|
|
93
|
+
* If path is a file, loads that config directly.
|
|
94
|
+
* If path is a directory, searches for a *mt.config.json file.
|
|
95
|
+
*/
|
|
96
|
+
export declare function loadProject(path: string): Project;
|
|
97
|
+
/**
|
|
98
|
+
* Load the complete plugin dependency graph starting from a root project.
|
|
99
|
+
* Uses BFS to walk the dependency DAG.
|
|
100
|
+
*/
|
|
101
|
+
export declare function loadConfigGraph(root: Project): ConfigGraph;
|
|
102
|
+
/**
|
|
103
|
+
* Merge all plugin configs into a single config.
|
|
104
|
+
* Components and events are merged in topological order with conflict detection.
|
|
105
|
+
*/
|
|
106
|
+
export declare function mergeConfigs(graph: ConfigGraph): MergedConfig;
|
|
107
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/codeg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W,YAAY;IAC3B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gEAAgE;IAChE,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAMD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoB/C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUjD;AAgBD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAsE1D;AAsDD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAqF7D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code generator interface and utilities for codegen.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the Generator interface and provides common utilities
|
|
5
|
+
* for name conversion and type mapping used by language-specific generators.
|
|
6
|
+
*
|
|
7
|
+
* @module codegen/generator
|
|
8
|
+
*/
|
|
9
|
+
import type { CompiledStateSchema, CompiledInputSchema } from '../schema';
|
|
10
|
+
/**
|
|
11
|
+
* Options for code generators.
|
|
12
|
+
*/
|
|
13
|
+
export interface GeneratorOptions {
|
|
14
|
+
/** Optional plugin name for prefixing (e.g., "physics") */
|
|
15
|
+
pluginName?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Code generator interface.
|
|
19
|
+
* Implementations produce language-specific code from compiled schemas.
|
|
20
|
+
*/
|
|
21
|
+
export interface Generator {
|
|
22
|
+
/** The target language */
|
|
23
|
+
readonly language: 'typescript' | 'rust';
|
|
24
|
+
/**
|
|
25
|
+
* Generate state accessor code from a compiled state schema.
|
|
26
|
+
* @param schema - Compiled state schema with layout information
|
|
27
|
+
* @returns Generated source code as a string
|
|
28
|
+
*/
|
|
29
|
+
generateState(schema: CompiledStateSchema): string;
|
|
30
|
+
/**
|
|
31
|
+
* Generate input codec code from a compiled input schema.
|
|
32
|
+
* @param schema - Compiled input schema with control/command information
|
|
33
|
+
* @returns Generated source code as a string
|
|
34
|
+
*/
|
|
35
|
+
generateInput(schema: CompiledInputSchema): string;
|
|
36
|
+
/**
|
|
37
|
+
* Generate combined game module with both state and input.
|
|
38
|
+
* @param state - Compiled state schema
|
|
39
|
+
* @param input - Compiled input schema
|
|
40
|
+
* @returns Generated source code as a string
|
|
41
|
+
*/
|
|
42
|
+
generateGame(state: CompiledStateSchema, input: CompiledInputSchema): string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convert a string from PascalCase/camelCase to UPPER_SNAKE_CASE.
|
|
46
|
+
* @example toUpperSnake("RigidBodyType") // "RIGID_BODY_TYPE"
|
|
47
|
+
* @example toUpperSnake("shapeType") // "SHAPE_TYPE"
|
|
48
|
+
*/
|
|
49
|
+
export declare function toUpperSnake(s: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a string to lower_snake_case.
|
|
52
|
+
* @example toLowerSnake("RigidBodyType") // "rigid_body_type"
|
|
53
|
+
* @example toLowerSnake("PlayerIndex") // "player_index"
|
|
54
|
+
*/
|
|
55
|
+
export declare function toLowerSnake(s: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Convert a string to camelCase.
|
|
58
|
+
* @example toCamelCase("player_index") // "playerIndex"
|
|
59
|
+
* @example toCamelCase("RIGID_BODY_TYPE") // "rigidBodyType"
|
|
60
|
+
*/
|
|
61
|
+
export declare function toCamelCase(s: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Convert a string to PascalCase.
|
|
64
|
+
* @example toPascalCase("player_index") // "PlayerIndex"
|
|
65
|
+
* @example toPascalCase("rigidBodyType") // "RigidBodyType"
|
|
66
|
+
*/
|
|
67
|
+
export declare function toPascalCase(s: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Parse array type string like "uint16[8]" into [elementType, length].
|
|
70
|
+
* Returns null if not a valid array type (must have primitive element type).
|
|
71
|
+
* Matches Go's ParseArrayType behavior which only allows primitive element types.
|
|
72
|
+
*/
|
|
73
|
+
export declare function parseArrayType(type: string): [string, number] | null;
|
|
74
|
+
/** Check if a type needs endianness handling (multi-byte types) */
|
|
75
|
+
export declare function needsEndian(type: string): boolean;
|
|
76
|
+
/** Get the element size for a primitive type */
|
|
77
|
+
export declare function getElementSize(type: string): number;
|
|
78
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/codegen/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAM1E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAAC;IAEzC;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAEnD;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAEnD;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAAC;CAC9E;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU9C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU9C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAiB9C;AAmBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CASpE;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAYjD;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBnD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code generation module for Multitap.
|
|
3
|
+
*
|
|
4
|
+
* Provides TypeScript and Rust code generators from compiled schemas.
|
|
5
|
+
*
|
|
6
|
+
* @module codegen
|
|
7
|
+
*/
|
|
8
|
+
export { type Config, type WasmConfig, type Project, type PluginNode, type ConfigGraph, type MergedConfig, findConfig, loadConfig, loadProject, loadConfigGraph, mergeConfigs, } from './config';
|
|
9
|
+
export { buildPlayerComponent, injectPlayerComponent, buildCommandEvents, injectCommandEvents, prepareStateSchema, } from './inject';
|
|
10
|
+
export { type Generator, type GeneratorOptions, toUpperSnake, toLowerSnake, toCamelCase, toPascalCase, parseArrayType, needsEndian, getElementSize, } from './generator';
|
|
11
|
+
export { TypeScriptGenerator } from './typescript';
|
|
12
|
+
export { RustGenerator } from './rust';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,YAAY,GACb,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC"}
|