murow 0.0.70 → 0.0.71
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 +52 -37
- package/dist/cjs/core/binary-codec/binary-codec.js +1 -0
- package/dist/cjs/core/binary-codec/index.js +1 -0
- package/dist/cjs/core/driver/driver.js +1 -0
- package/dist/cjs/core/driver/drivers/immediate.js +1 -0
- package/dist/cjs/core/driver/drivers/index.js +1 -0
- package/dist/cjs/core/driver/drivers/raf.js +1 -0
- package/dist/cjs/core/driver/drivers/timeout.js +1 -0
- package/dist/cjs/core/driver/index.js +1 -0
- package/dist/cjs/core/events/event-system.js +1 -0
- package/dist/cjs/core/events/index.js +1 -0
- package/dist/cjs/core/fixed-ticker/fixed-ticker.js +1 -0
- package/dist/cjs/core/fixed-ticker/index.js +1 -0
- package/dist/cjs/core/free-list/free-list.js +1 -0
- package/dist/cjs/core/free-list/index.js +1 -0
- package/dist/cjs/core/generate-id/generate-id.js +1 -0
- package/dist/cjs/core/generate-id/index.js +1 -0
- package/dist/cjs/core/index.js +1 -0
- package/dist/cjs/core/input/index.js +1 -0
- package/dist/cjs/core/input/manager.js +1 -0
- package/dist/cjs/core/input/sources/browser.js +1 -0
- package/dist/cjs/core/input/sources/index.js +1 -0
- package/dist/cjs/core/input/types.js +1 -0
- package/dist/cjs/core/lerp/index.js +1 -0
- package/dist/cjs/core/lerp/lerp.js +1 -0
- package/dist/cjs/core/navmesh/index.js +1 -0
- package/dist/cjs/core/navmesh/navmesh-worker-pool.js +1 -0
- package/dist/cjs/core/navmesh/navmesh.js +1 -0
- package/dist/cjs/core/navmesh/navmesh.worker.js +1 -0
- package/dist/cjs/core/pooled-codec/index.js +1 -0
- package/dist/cjs/core/pooled-codec/pooled-codec.js +1 -0
- package/dist/cjs/core/prediction/index.js +1 -0
- package/dist/cjs/core/prediction/prediction.js +1 -0
- package/dist/cjs/core/ray/index.js +1 -0
- package/dist/cjs/core/ray/ray-2d.js +1 -0
- package/dist/cjs/core/ray/ray-3d.js +1 -0
- package/dist/cjs/core/simple-rng/index.js +1 -0
- package/dist/cjs/core/simple-rng/simple-rng.js +1 -0
- package/dist/cjs/core/sparse-batcher/index.js +1 -0
- package/dist/cjs/core/sparse-batcher/sparse-batcher.js +1 -0
- package/dist/cjs/ecs/component-store.js +1 -0
- package/dist/cjs/ecs/component.js +1 -0
- package/dist/cjs/ecs/entity-handle.js +1 -0
- package/dist/cjs/ecs/index.js +1 -0
- package/dist/cjs/ecs/system-builder.js +1 -0
- package/dist/cjs/ecs/world-systems.js +1 -0
- package/dist/cjs/ecs/world.js +1 -0
- package/dist/cjs/game/index.js +1 -0
- package/dist/cjs/game/loop/index.js +1 -0
- package/dist/cjs/game/loop/loop.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/net/adapters/browser-websocket.js +1 -0
- package/dist/cjs/net/adapters/bun-websocket.js +1 -0
- package/dist/cjs/net/buffer-pool.js +1 -0
- package/dist/cjs/net/client.js +1 -0
- package/dist/cjs/net/index.js +1 -0
- package/dist/cjs/net/server.js +1 -0
- package/dist/cjs/net/types.js +1 -0
- package/dist/cjs/net/validators.js +1 -0
- package/dist/cjs/protocol/index.js +1 -0
- package/dist/cjs/protocol/intent/define-intent.js +1 -0
- package/dist/cjs/protocol/intent/index.js +1 -0
- package/dist/cjs/protocol/intent/intent-registry.js +1 -0
- package/dist/cjs/protocol/intent/intent.js +1 -0
- package/dist/cjs/protocol/rpc/define-rpc.js +1 -0
- package/dist/cjs/protocol/rpc/index.js +1 -0
- package/dist/cjs/protocol/rpc/rpc-registry.js +1 -0
- package/dist/cjs/protocol/rpc/rpc.js +1 -0
- package/dist/cjs/protocol/snapshot/index.js +1 -0
- package/dist/cjs/protocol/snapshot/snapshot-codec.js +1 -0
- package/dist/cjs/protocol/snapshot/snapshot-registry.js +1 -0
- package/dist/cjs/protocol/snapshot/snapshot.js +1 -0
- package/dist/cjs/renderer/base-2d-renderer.js +1 -0
- package/dist/cjs/renderer/base-3d-renderer.js +1 -0
- package/dist/cjs/renderer/base-renderer.js +1 -0
- package/dist/cjs/renderer/index.js +1 -0
- package/dist/cjs/renderer/types.js +1 -0
- package/dist/esm/core/binary-codec/binary-codec.js +1 -0
- package/dist/esm/core/binary-codec/index.js +1 -0
- package/dist/esm/core/driver/driver.js +1 -0
- package/dist/esm/core/driver/drivers/immediate.js +1 -0
- package/dist/esm/core/driver/drivers/index.js +1 -0
- package/dist/esm/core/driver/drivers/raf.js +1 -0
- package/dist/esm/core/driver/drivers/timeout.js +1 -0
- package/dist/esm/core/driver/index.js +1 -0
- package/dist/esm/core/events/event-system.js +1 -0
- package/dist/esm/core/events/index.js +1 -0
- package/dist/esm/core/fixed-ticker/fixed-ticker.js +1 -0
- package/dist/esm/core/fixed-ticker/index.js +1 -0
- package/dist/esm/core/free-list/free-list.js +1 -0
- package/dist/esm/core/free-list/index.js +1 -0
- package/dist/esm/core/generate-id/generate-id.js +1 -0
- package/dist/esm/core/generate-id/index.js +1 -0
- package/dist/esm/core/index.js +1 -0
- package/dist/esm/core/input/index.js +1 -0
- package/dist/esm/core/input/manager.js +1 -0
- package/dist/esm/core/input/sources/browser.js +1 -0
- package/dist/esm/core/input/sources/index.js +1 -0
- package/dist/esm/core/input/types.js +0 -0
- package/dist/esm/core/lerp/index.js +1 -0
- package/dist/esm/core/lerp/lerp.js +1 -0
- package/dist/esm/core/navmesh/index.js +1 -0
- package/dist/esm/core/navmesh/navmesh-worker-pool.js +1 -0
- package/dist/esm/core/navmesh/navmesh.js +1 -0
- package/dist/esm/core/navmesh/navmesh.worker.js +1 -0
- package/dist/esm/core/pooled-codec/index.js +1 -0
- package/dist/esm/core/pooled-codec/pooled-codec.js +1 -0
- package/dist/esm/core/prediction/index.js +1 -0
- package/dist/esm/core/prediction/prediction.js +1 -0
- package/dist/esm/core/ray/index.js +1 -0
- package/dist/esm/core/ray/ray-2d.js +1 -0
- package/dist/esm/core/ray/ray-3d.js +1 -0
- package/dist/esm/core/simple-rng/index.js +1 -0
- package/dist/esm/core/simple-rng/simple-rng.js +1 -0
- package/dist/esm/core/sparse-batcher/index.js +1 -0
- package/dist/esm/core/sparse-batcher/sparse-batcher.js +1 -0
- package/dist/esm/ecs/component-store.js +1 -0
- package/dist/esm/ecs/component.js +1 -0
- package/dist/esm/ecs/entity-handle.js +1 -0
- package/dist/esm/ecs/index.js +1 -0
- package/dist/esm/ecs/system-builder.js +1 -0
- package/dist/esm/ecs/world-systems.js +1 -0
- package/dist/esm/ecs/world.js +1 -0
- package/dist/esm/game/index.js +1 -0
- package/dist/esm/game/loop/index.js +1 -0
- package/dist/esm/game/loop/loop.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/net/adapters/browser-websocket.js +1 -0
- package/dist/esm/net/adapters/bun-websocket.js +1 -0
- package/dist/esm/net/buffer-pool.js +1 -0
- package/dist/esm/net/client.js +1 -0
- package/dist/esm/net/index.js +1 -0
- package/dist/esm/net/server.js +1 -0
- package/dist/esm/net/types.js +1 -0
- package/dist/esm/net/validators.js +1 -0
- package/dist/esm/protocol/index.js +1 -0
- package/dist/esm/protocol/intent/define-intent.js +1 -0
- package/dist/esm/protocol/intent/index.js +1 -0
- package/dist/esm/protocol/intent/intent-registry.js +1 -0
- package/dist/esm/protocol/intent/intent.js +0 -0
- package/dist/esm/protocol/rpc/define-rpc.js +1 -0
- package/dist/esm/protocol/rpc/index.js +1 -0
- package/dist/esm/protocol/rpc/rpc-registry.js +1 -0
- package/dist/esm/protocol/rpc/rpc.js +0 -0
- package/dist/esm/protocol/snapshot/index.js +1 -0
- package/dist/esm/protocol/snapshot/snapshot-codec.js +1 -0
- package/dist/esm/protocol/snapshot/snapshot-registry.js +1 -0
- package/dist/esm/protocol/snapshot/snapshot.js +1 -0
- package/dist/esm/renderer/base-2d-renderer.js +1 -0
- package/dist/esm/renderer/base-3d-renderer.js +1 -0
- package/dist/esm/renderer/base-renderer.js +1 -0
- package/dist/esm/renderer/index.js +1 -0
- package/dist/esm/renderer/types.js +0 -0
- package/dist/{core → types/core}/binary-codec/binary-codec.d.ts +4 -0
- package/dist/{core → types/core}/events/event-system.d.ts +14 -33
- package/dist/types/core/free-list/free-list.d.ts +31 -0
- package/dist/types/core/free-list/index.d.ts +1 -0
- package/dist/{core → types/core}/index.d.ts +5 -0
- package/dist/{core → types/core}/input/index.d.ts +1 -0
- package/dist/{core → types/core}/input/manager.d.ts +2 -0
- package/dist/{core → types/core}/navmesh/navmesh.d.ts +1 -21
- package/dist/types/core/ray/index.d.ts +2 -0
- package/dist/types/core/ray/ray-2d.d.ts +37 -0
- package/dist/types/core/ray/ray-3d.d.ts +42 -0
- package/dist/types/core/simple-rng/index.d.ts +1 -0
- package/dist/types/core/simple-rng/simple-rng.d.ts +36 -0
- package/dist/types/core/sparse-batcher/index.d.ts +1 -0
- package/dist/types/core/sparse-batcher/sparse-batcher.d.ts +55 -0
- package/dist/{ecs → types/ecs}/world.d.ts +11 -0
- package/dist/{game → types/game}/loop/loop.d.ts +33 -29
- package/dist/{index.d.ts → types/index.d.ts} +1 -0
- package/dist/{net → types/net}/index.d.ts +2 -2
- package/dist/types/renderer/base-2d-renderer.d.ts +13 -0
- package/dist/types/renderer/base-3d-renderer.d.ts +10 -0
- package/dist/types/renderer/base-renderer.d.ts +21 -0
- package/dist/types/renderer/index.d.ts +4 -0
- package/dist/types/renderer/types.d.ts +79 -0
- package/dist/webgpu/cjs/index.js +6004 -0
- package/dist/webgpu/esm/index.js +5972 -0
- package/dist/webgpu/types/2d/animation.d.ts +97 -0
- package/dist/webgpu/types/2d/renderer.d.ts +55 -0
- package/dist/webgpu/types/2d/shader.d.ts +61 -0
- package/dist/webgpu/types/2d/sprite-accessor.d.ts +47 -0
- package/dist/webgpu/types/3d/gltf-skin-parser.d.ts +101 -0
- package/dist/webgpu/types/3d/morph-animation.d.ts +69 -0
- package/dist/webgpu/types/3d/morph-animation.test.d.ts +1 -0
- package/dist/webgpu/types/3d/renderer.d.ts +216 -0
- package/dist/webgpu/types/3d/shader.d.ts +136 -0
- package/dist/webgpu/types/3d/skeletal-animation-compute/index.d.ts +2 -0
- package/dist/webgpu/types/3d/skeletal-animation-compute/kernel.d.ts +8 -0
- package/dist/webgpu/types/3d/skeletal-animation-compute/packer.d.ts +32 -0
- package/dist/webgpu/types/3d/skeletal-animation.d.ts +90 -0
- package/dist/webgpu/types/camera/camera-2d.d.ts +53 -0
- package/dist/webgpu/types/camera/camera-2d.test.d.ts +1 -0
- package/dist/webgpu/types/camera/camera-3d.d.ts +81 -0
- package/dist/webgpu/types/camera/camera-3d.test.d.ts +1 -0
- package/dist/webgpu/types/camera/index.d.ts +2 -0
- package/dist/webgpu/types/compute/compute-builder.d.ts +123 -0
- package/dist/webgpu/types/compute/compute-builder.test.d.ts +1 -0
- package/dist/webgpu/types/core/constants.d.ts +59 -0
- package/dist/webgpu/types/core/constants.test.d.ts +1 -0
- package/dist/webgpu/types/core/index.d.ts +2 -0
- package/dist/webgpu/types/core/math.d.ts +37 -0
- package/dist/webgpu/types/core/types.d.ts +125 -0
- package/dist/webgpu/types/core/types.test.d.ts +1 -0
- package/dist/webgpu/types/geometry/built-in.d.ts +58 -0
- package/dist/webgpu/types/geometry/built-in.test.d.ts +1 -0
- package/dist/webgpu/types/geometry/geometry-builder.d.ts +281 -0
- package/dist/webgpu/types/geometry/geometry-builder.test.d.ts +1 -0
- package/dist/webgpu/types/geometry/index.d.ts +2 -0
- package/dist/webgpu/types/index.d.ts +32 -0
- package/dist/webgpu/types/particle/emitter.d.ts +36 -0
- package/dist/webgpu/types/shaders/index.d.ts +2 -0
- package/dist/webgpu/types/shaders/runtime-transpile.d.ts +18 -0
- package/dist/webgpu/types/shaders/sprite-2d.wgsl.d.ts +10 -0
- package/dist/webgpu/types/shaders/typegpu.d.ts +9 -0
- package/dist/webgpu/types/shaders/utils.d.ts +28 -0
- package/dist/webgpu/types/shaders/utils.test.d.ts +1 -0
- package/dist/webgpu/types/spritesheet/index.d.ts +1 -0
- package/dist/webgpu/types/spritesheet/spritesheet.d.ts +57 -0
- package/dist/webgpu/types/spritesheet/spritesheet.test.d.ts +1 -0
- package/package.json +96 -26
- package/dist/core/binary-codec/binary-codec.js +0 -354
- package/dist/core/binary-codec/index.js +0 -1
- package/dist/core/driver/driver.js +0 -47
- package/dist/core/driver/drivers/immediate.js +0 -61
- package/dist/core/driver/drivers/index.js +0 -3
- package/dist/core/driver/drivers/raf.js +0 -62
- package/dist/core/driver/drivers/timeout.js +0 -71
- package/dist/core/driver/index.js +0 -2
- package/dist/core/events/event-system.js +0 -88
- package/dist/core/events/index.js +0 -1
- package/dist/core/fixed-ticker/fixed-ticker.js +0 -105
- package/dist/core/fixed-ticker/index.js +0 -1
- package/dist/core/generate-id/generate-id.js +0 -25
- package/dist/core/generate-id/index.js +0 -1
- package/dist/core/index.js +0 -10
- package/dist/core/input/index.js +0 -2
- package/dist/core/input/manager.js +0 -211
- package/dist/core/input/sources/browser.js +0 -29
- package/dist/core/input/sources/index.js +0 -1
- package/dist/core/lerp/index.js +0 -1
- package/dist/core/lerp/lerp.js +0 -42
- package/dist/core/navmesh/index.js +0 -1
- package/dist/core/navmesh/navmesh-worker-pool.js +0 -180
- package/dist/core/navmesh/navmesh.js +0 -799
- package/dist/core/navmesh/navmesh.worker.js +0 -79
- package/dist/core/pooled-codec/index.js +0 -1
- package/dist/core/pooled-codec/pooled-codec.js +0 -410
- package/dist/core/prediction/index.js +0 -1
- package/dist/core/prediction/prediction.js +0 -99
- package/dist/core.esm.js +0 -1
- package/dist/core.js +0 -1
- package/dist/ecs/component-store.js +0 -175
- package/dist/ecs/component.js +0 -43
- package/dist/ecs/entity-handle.js +0 -515
- package/dist/ecs/example.js +0 -125
- package/dist/ecs/index.js +0 -4
- package/dist/ecs/system-builder.js +0 -249
- package/dist/ecs/world-systems.js +0 -79
- package/dist/ecs/world.js +0 -767
- package/dist/game/index.js +0 -1
- package/dist/game/loop/index.js +0 -1
- package/dist/game/loop/loop.js +0 -108
- package/dist/index.js +0 -26
- package/dist/net/adapters/browser-websocket.js +0 -74
- package/dist/net/adapters/bun-websocket.js +0 -245
- package/dist/net/buffer-pool.js +0 -89
- package/dist/net/client.js +0 -586
- package/dist/net/index.js +0 -58
- package/dist/net/server.js +0 -974
- package/dist/net/types.js +0 -31
- package/dist/net/validators.js +0 -88
- package/dist/protocol/index.js +0 -92
- package/dist/protocol/intent/define-intent.js +0 -125
- package/dist/protocol/intent/index.js +0 -91
- package/dist/protocol/intent/intent-registry.js +0 -91
- package/dist/protocol/rpc/define-rpc.js +0 -84
- package/dist/protocol/rpc/index.js +0 -3
- package/dist/protocol/rpc/rpc-registry.js +0 -159
- package/dist/protocol/rpc/rpc.js +0 -12
- package/dist/protocol/snapshot/index.js +0 -43
- package/dist/protocol/snapshot/snapshot-codec.js +0 -67
- package/dist/protocol/snapshot/snapshot-registry.js +0 -168
- package/dist/protocol/snapshot/snapshot.js +0 -30
- package/src/core/binary-codec/README.md +0 -60
- package/src/core/binary-codec/binary-codec.test.ts +0 -300
- package/src/core/binary-codec/binary-codec.ts +0 -448
- package/src/core/binary-codec/index.ts +0 -1
- package/src/core/driver/README.md +0 -97
- package/src/core/driver/driver.test.ts +0 -414
- package/src/core/driver/driver.ts +0 -71
- package/src/core/driver/drivers/immediate.ts +0 -66
- package/src/core/driver/drivers/index.ts +0 -3
- package/src/core/driver/drivers/raf.ts +0 -67
- package/src/core/driver/drivers/timeout.ts +0 -77
- package/src/core/driver/index.ts +0 -2
- package/src/core/events/README.md +0 -47
- package/src/core/events/event-system.test.ts +0 -243
- package/src/core/events/event-system.ts +0 -140
- package/src/core/events/index.ts +0 -1
- package/src/core/fixed-ticker/README.md +0 -77
- package/src/core/fixed-ticker/fixed-ticker.test.ts +0 -151
- package/src/core/fixed-ticker/fixed-ticker.ts +0 -174
- package/src/core/fixed-ticker/index.ts +0 -1
- package/src/core/generate-id/README.md +0 -18
- package/src/core/generate-id/generate-id.test.ts +0 -79
- package/src/core/generate-id/generate-id.ts +0 -37
- package/src/core/generate-id/index.ts +0 -1
- package/src/core/index.ts +0 -10
- package/src/core/input/README.md +0 -24
- package/src/core/input/index.ts +0 -2
- package/src/core/input/manager.ts +0 -259
- package/src/core/input/sources/browser.ts +0 -39
- package/src/core/input/sources/index.ts +0 -1
- package/src/core/input/types.ts +0 -40
- package/src/core/lerp/README.md +0 -79
- package/src/core/lerp/index.ts +0 -1
- package/src/core/lerp/lerp.test.ts +0 -90
- package/src/core/lerp/lerp.ts +0 -42
- package/src/core/navmesh/README.md +0 -164
- package/src/core/navmesh/index.ts +0 -1
- package/src/core/navmesh/navmesh-worker-pool.ts +0 -236
- package/src/core/navmesh/navmesh-workers.test.ts +0 -356
- package/src/core/navmesh/navmesh.test.ts +0 -344
- package/src/core/navmesh/navmesh.ts +0 -1047
- package/src/core/navmesh/navmesh.worker.ts +0 -147
- package/src/core/pooled-codec/README.md +0 -70
- package/src/core/pooled-codec/index.ts +0 -1
- package/src/core/pooled-codec/pooled-codec.test.ts +0 -862
- package/src/core/pooled-codec/pooled-codec.ts +0 -504
- package/src/core/prediction/README.md +0 -64
- package/src/core/prediction/index.ts +0 -1
- package/src/core/prediction/prediction.test.ts +0 -423
- package/src/core/prediction/prediction.ts +0 -112
- package/src/ecs/README.md +0 -427
- package/src/ecs/benchmark.test.ts +0 -1645
- package/src/ecs/component-store.ts +0 -198
- package/src/ecs/component.ts +0 -90
- package/src/ecs/entity-handle.test.ts +0 -393
- package/src/ecs/entity-handle.ts +0 -563
- package/src/ecs/example.ts +0 -152
- package/src/ecs/index.ts +0 -4
- package/src/ecs/system-builder.ts +0 -404
- package/src/ecs/world-systems.ts +0 -83
- package/src/ecs/world.test.ts +0 -310
- package/src/ecs/world.ts +0 -904
- package/src/game/index.ts +0 -1
- package/src/game/loop/README.md +0 -32
- package/src/game/loop/index.ts +0 -1
- package/src/game/loop/loop.ts +0 -236
- package/src/index.ts +0 -32
- package/src/net/README.md +0 -474
- package/src/net/adapters/browser-websocket.ts +0 -86
- package/src/net/adapters/bun-websocket.ts +0 -292
- package/src/net/buffer-pool.ts +0 -106
- package/src/net/client.test.ts +0 -807
- package/src/net/client.ts +0 -695
- package/src/net/index.ts +0 -60
- package/src/net/server.test.ts +0 -799
- package/src/net/server.ts +0 -1152
- package/src/net/types.ts +0 -228
- package/src/net/validators.ts +0 -104
- package/src/protocol/README.md +0 -469
- package/src/protocol/index.ts +0 -93
- package/src/protocol/intent/define-intent.test.ts +0 -397
- package/src/protocol/intent/define-intent.ts +0 -201
- package/src/protocol/intent/index.ts +0 -94
- package/src/protocol/intent/intent-registry.test.ts +0 -198
- package/src/protocol/intent/intent-registry.ts +0 -112
- package/src/protocol/intent/intent.ts +0 -12
- package/src/protocol/rpc/define-rpc.test.ts +0 -141
- package/src/protocol/rpc/define-rpc.ts +0 -113
- package/src/protocol/rpc/index.ts +0 -3
- package/src/protocol/rpc/rpc-registry.test.ts +0 -168
- package/src/protocol/rpc/rpc-registry.ts +0 -176
- package/src/protocol/rpc/rpc.ts +0 -37
- package/src/protocol/snapshot/index.ts +0 -45
- package/src/protocol/snapshot/snapshot-codec.test.ts +0 -138
- package/src/protocol/snapshot/snapshot-codec.ts +0 -87
- package/src/protocol/snapshot/snapshot-registry.test.ts +0 -310
- package/src/protocol/snapshot/snapshot-registry.ts +0 -201
- package/src/protocol/snapshot/snapshot.test.ts +0 -76
- package/src/protocol/snapshot/snapshot.ts +0 -41
- /package/dist/{core → types/core}/binary-codec/index.d.ts +0 -0
- /package/dist/{core → types/core}/driver/driver.d.ts +0 -0
- /package/dist/{core → types/core}/driver/drivers/immediate.d.ts +0 -0
- /package/dist/{core → types/core}/driver/drivers/index.d.ts +0 -0
- /package/dist/{core → types/core}/driver/drivers/raf.d.ts +0 -0
- /package/dist/{core → types/core}/driver/drivers/timeout.d.ts +0 -0
- /package/dist/{core → types/core}/driver/index.d.ts +0 -0
- /package/dist/{core → types/core}/events/index.d.ts +0 -0
- /package/dist/{core → types/core}/fixed-ticker/fixed-ticker.d.ts +0 -0
- /package/dist/{core → types/core}/fixed-ticker/index.d.ts +0 -0
- /package/dist/{core → types/core}/generate-id/generate-id.d.ts +0 -0
- /package/dist/{core → types/core}/generate-id/index.d.ts +0 -0
- /package/dist/{core → types/core}/input/sources/browser.d.ts +0 -0
- /package/dist/{core → types/core}/input/sources/index.d.ts +0 -0
- /package/dist/{core → types/core}/input/types.d.ts +0 -0
- /package/dist/{core → types/core}/lerp/index.d.ts +0 -0
- /package/dist/{core → types/core}/lerp/lerp.d.ts +0 -0
- /package/dist/{core → types/core}/navmesh/index.d.ts +0 -0
- /package/dist/{core → types/core}/navmesh/navmesh-worker-pool.d.ts +0 -0
- /package/dist/{core → types/core}/navmesh/navmesh.worker.d.ts +0 -0
- /package/dist/{core → types/core}/pooled-codec/index.d.ts +0 -0
- /package/dist/{core → types/core}/pooled-codec/pooled-codec.d.ts +0 -0
- /package/dist/{core → types/core}/prediction/index.d.ts +0 -0
- /package/dist/{core → types/core}/prediction/prediction.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/component-store.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/component.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/entity-handle.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/example.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/index.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/system-builder.d.ts +0 -0
- /package/dist/{ecs → types/ecs}/world-systems.d.ts +0 -0
- /package/dist/{game → types/game}/index.d.ts +0 -0
- /package/dist/{game → types/game}/loop/index.d.ts +0 -0
- /package/dist/{net → types/net}/adapters/browser-websocket.d.ts +0 -0
- /package/dist/{net → types/net}/adapters/bun-websocket.d.ts +0 -0
- /package/dist/{net → types/net}/buffer-pool.d.ts +0 -0
- /package/dist/{net → types/net}/client.d.ts +0 -0
- /package/dist/{net → types/net}/server.d.ts +0 -0
- /package/dist/{net → types/net}/types.d.ts +0 -0
- /package/dist/{net → types/net}/validators.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/index.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/intent/define-intent.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/intent/index.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/intent/intent-registry.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/intent/intent.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/rpc/define-rpc.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/rpc/index.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/rpc/rpc-registry.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/rpc/rpc.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/snapshot/index.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/snapshot/snapshot-codec.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/snapshot/snapshot-registry.d.ts +0 -0
- /package/dist/{protocol → types/protocol}/snapshot/snapshot.d.ts +0 -0
- /package/dist/{core/input/types.js → webgpu/types/2d/animation.test.d.ts} +0 -0
- /package/dist/{protocol/intent/intent.js → webgpu/types/2d/sprite-accessor.test.d.ts} +0 -0
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* A utility class for managing fixed-rate update ticks, useful for deterministic behaviour
|
|
4
|
-
* in both client and server.
|
|
5
|
-
*
|
|
6
|
-
* The `FixedTicker` accumulates elapsed time and determines how many fixed-interval "ticks"
|
|
7
|
-
* should be processed based on a specified tick rate. It also limits the maximum number of
|
|
8
|
-
* ticks per frame to prevent runaway update loops when frame times are long.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* - The `tick` method should be called once per frame, passing the elapsed time in seconds.
|
|
13
|
-
* - The class ensures that no more than a safe number of ticks are processed per frame.
|
|
14
|
-
*/
|
|
15
|
-
export class FixedTicker {
|
|
16
|
-
/**
|
|
17
|
-
* @description Accumulator for the time passed since the last tick (in milliseconds)
|
|
18
|
-
*/
|
|
19
|
-
private accumulator = 0;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @description Rate of ticks per second
|
|
23
|
-
*/
|
|
24
|
-
rate: number;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @description
|
|
28
|
-
* Interval in milliseconds per tick
|
|
29
|
-
*/
|
|
30
|
-
intervalMs: number;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @description
|
|
34
|
-
* Maximum amount of ticks to run per frame, to avoid
|
|
35
|
-
* running too many ticks in a single frame.
|
|
36
|
-
*/
|
|
37
|
-
private maxTicksPerFrame: number;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @description
|
|
41
|
-
* Callback to execute on each tick
|
|
42
|
-
*/
|
|
43
|
-
private onTick: (deltaTime: number, tick?: number) => void;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @description
|
|
47
|
-
* Optional callback to execute when ticks are skipped due to high delta time.
|
|
48
|
-
* This can be useful for debugging or logging purposes.
|
|
49
|
-
*/
|
|
50
|
-
private onTickSkipped?: (skippedTicks: number) => void;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @description
|
|
54
|
-
* Internal counter for the number of ticks processed.
|
|
55
|
-
*/
|
|
56
|
-
private _tickCount = 0;
|
|
57
|
-
|
|
58
|
-
constructor({ rate, onTick }: FixedTickerProps) {
|
|
59
|
-
this.rate = rate;
|
|
60
|
-
this.intervalMs = 1000 / this.rate;
|
|
61
|
-
this.onTick = onTick;
|
|
62
|
-
|
|
63
|
-
// Allow up to rate/2 ticks per frame, but at least 1.
|
|
64
|
-
// Prevents runaway loops if delta is too large.
|
|
65
|
-
this.maxTicksPerFrame = Math.max(1, Math.floor(rate / 2));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @description
|
|
70
|
-
* Returns how many ticks to run.
|
|
71
|
-
*
|
|
72
|
-
* @param deltaTime Delta time in seconds
|
|
73
|
-
* @returns {number} Amount of ticks to run
|
|
74
|
-
*/
|
|
75
|
-
private getTicks(deltaTime: number): number {
|
|
76
|
-
this.accumulator += deltaTime * 1000;
|
|
77
|
-
|
|
78
|
-
let ticks = 0;
|
|
79
|
-
|
|
80
|
-
// Use a small epsilon relative to interval to handle floating point precision errors
|
|
81
|
-
// Without this, accumulator might be 0.9999999 when it should be 1.0
|
|
82
|
-
const epsilon = this.intervalMs * 0.001;
|
|
83
|
-
|
|
84
|
-
while (
|
|
85
|
-
this.accumulator >= this.intervalMs - epsilon &&
|
|
86
|
-
ticks < this.maxTicksPerFrame
|
|
87
|
-
) {
|
|
88
|
-
this.accumulator -= this.intervalMs;
|
|
89
|
-
ticks++;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const skippedTicks = Math.floor(this.accumulator / this.intervalMs);
|
|
93
|
-
if (skippedTicks > 0 && this.onTickSkipped) {
|
|
94
|
-
this.onTickSkipped(skippedTicks);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return ticks;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @description
|
|
102
|
-
* Processes the ticks based on the elapsed time.
|
|
103
|
-
*
|
|
104
|
-
* @param deltaTime Delta time in seconds
|
|
105
|
-
*/
|
|
106
|
-
tick(deltaTime: number): void {
|
|
107
|
-
const ticks = this.getTicks(deltaTime);
|
|
108
|
-
|
|
109
|
-
for (let i = 0; i < ticks; i++) {
|
|
110
|
-
this.onTick(1 / this.rate, this._tickCount++);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @description
|
|
116
|
-
* Returns the number of ticks processed since the last reset.
|
|
117
|
-
*
|
|
118
|
-
* @returns {number} Number of ticks processed
|
|
119
|
-
*/
|
|
120
|
-
get tickCount(): number {
|
|
121
|
-
return this._tickCount;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @description
|
|
126
|
-
* Resets the tick count to zero.
|
|
127
|
-
*/
|
|
128
|
-
resetTickCount(): void {
|
|
129
|
-
this._tickCount = 0;
|
|
130
|
-
this.accumulator = 0;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @description
|
|
135
|
-
* Returns the accumulated time in seconds, useful for interpolation.
|
|
136
|
-
*
|
|
137
|
-
* @returns {number} Accumulated time in seconds
|
|
138
|
-
*/
|
|
139
|
-
get accumulatedTime(): number {
|
|
140
|
-
return this.accumulator / 1000; // Convert to seconds
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @description
|
|
145
|
-
* Returns the interpolation factor between 0 and 1 for smooth rendering between ticks.
|
|
146
|
-
* Clamped to prevent extrapolation when ticks are skipped.
|
|
147
|
-
*
|
|
148
|
-
* @returns {number} Alpha value between 0 and 1
|
|
149
|
-
*/
|
|
150
|
-
get alpha(): number {
|
|
151
|
-
return Math.min(this.accumulatedTime / (1 / this.rate), 1.0);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
interface FixedTickerProps {
|
|
156
|
-
/**
|
|
157
|
-
* @description
|
|
158
|
-
* Rate of ticks per second
|
|
159
|
-
*/
|
|
160
|
-
rate: number;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @description
|
|
164
|
-
* Callback to execute on each tick
|
|
165
|
-
*/
|
|
166
|
-
onTick: (deltaTime: number, tick?: number) => void;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @description
|
|
170
|
-
* Optional callback to execute when ticks are skipped due to high delta time.
|
|
171
|
-
* This can be useful for debugging or logging purposes.
|
|
172
|
-
*/
|
|
173
|
-
onTickSkipped?: (skippedTicks: number) => void
|
|
174
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fixed-ticker';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# generateId
|
|
2
|
-
|
|
3
|
-
A simple utility function to generate unique 64-bit identifiers using the Web Crypto API.
|
|
4
|
-
The IDs are returned as hexadecimal strings and work in both modern browsers and Node.js (v15+).
|
|
5
|
-
|
|
6
|
-
## Features
|
|
7
|
-
|
|
8
|
-
- Generates cryptographically strong 64-bit IDs.
|
|
9
|
-
- Returns hexadecimal strings (always padded to 16 characters).
|
|
10
|
-
- Works in browsers and Node ≥15 without any imports.
|
|
11
|
-
- Fast and clean using BigInt arithmetic.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { generateId } from './generate-id';
|
|
17
|
-
const id = generateId(); // akwats 16-character hex string
|
|
18
|
-
```
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { generateId } from "./generate-id";
|
|
3
|
-
|
|
4
|
-
describe("generateId", () => {
|
|
5
|
-
test("should generate an ID with default length of 16", () => {
|
|
6
|
-
const id = generateId();
|
|
7
|
-
expect(id.length).toBe(16);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("should generate a hexadecimal string", () => {
|
|
11
|
-
const id = generateId();
|
|
12
|
-
expect(id).toMatch(/^[0-9a-f]+$/);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("should generate unique IDs", () => {
|
|
16
|
-
const ids = new Set();
|
|
17
|
-
for (let i = 0; i < 1000; i++) {
|
|
18
|
-
ids.add(generateId());
|
|
19
|
-
}
|
|
20
|
-
expect(ids.size).toBe(1000);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("should include prefix when provided", () => {
|
|
24
|
-
const prefix = "user_";
|
|
25
|
-
const id = generateId({ prefix });
|
|
26
|
-
expect(id.startsWith(prefix)).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("should maintain total size including prefix", () => {
|
|
30
|
-
const prefix = "user_";
|
|
31
|
-
const size = 20;
|
|
32
|
-
const id = generateId({ prefix, size });
|
|
33
|
-
expect(id.length).toBe(size);
|
|
34
|
-
expect(id.startsWith(prefix)).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("should generate custom size without prefix", () => {
|
|
38
|
-
const size = 32;
|
|
39
|
-
const id = generateId({ size });
|
|
40
|
-
expect(id.length).toBe(size);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("should enforce minimum of 8 hex characters", () => {
|
|
44
|
-
const prefix = "verylongprefix_";
|
|
45
|
-
const size = 10; // shorter than prefix + 8
|
|
46
|
-
const id = generateId({ prefix, size });
|
|
47
|
-
// Should be prefix + at least 8 hex chars
|
|
48
|
-
expect(id.length).toBeGreaterThanOrEqual(prefix.length + 8);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("should pad ID to desired length", () => {
|
|
52
|
-
const size = 24;
|
|
53
|
-
const id = generateId({ size });
|
|
54
|
-
expect(id.length).toBe(size);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("should generate different IDs on consecutive calls", () => {
|
|
58
|
-
const id1 = generateId();
|
|
59
|
-
const id2 = generateId();
|
|
60
|
-
expect(id1).not.toBe(id2);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("should work with various prefix lengths", () => {
|
|
64
|
-
const prefixes = ["a", "ab", "abc", "player_", "super_long_prefix_"];
|
|
65
|
-
prefixes.forEach((prefix) => {
|
|
66
|
-
const id = generateId({ prefix });
|
|
67
|
-
expect(id.startsWith(prefix)).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("should generate valid hex with leading zeros preserved", () => {
|
|
72
|
-
// Generate many IDs to ensure padding works correctly
|
|
73
|
-
for (let i = 0; i < 100; i++) {
|
|
74
|
-
const id = generateId({ size: 16 });
|
|
75
|
-
expect(id.length).toBe(16);
|
|
76
|
-
expect(id).toMatch(/^[0-9a-f]{16}$/);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
interface GenerateIdOptions {
|
|
2
|
-
/** Optional prefix to prepend to the ID */
|
|
3
|
-
prefix?: string;
|
|
4
|
-
/** Total length of the returned ID including prefix (default 16) */
|
|
5
|
-
size?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @description
|
|
10
|
-
* Generates a unique identifier as a hexadecimal string.
|
|
11
|
-
* Can include a prefix and a custom total length.
|
|
12
|
-
*
|
|
13
|
-
* @param options Optional configuration: prefix and total size
|
|
14
|
-
* @returns A unique identifier string
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* generateId(); // "f3a2b1c4d5e67890"
|
|
18
|
-
* generateId({ prefix: 'user_' }); // "user_f3a2b1c4d5e67890"
|
|
19
|
-
* generateId({ prefix: 'user_', size: 24 }); // "user_00f3a2b1c4d5e67890"
|
|
20
|
-
*/
|
|
21
|
-
export function generateId(options: GenerateIdOptions = {}): string {
|
|
22
|
-
const { prefix = "", size = 16 } = options;
|
|
23
|
-
|
|
24
|
-
// compute number of hex characters to generate (subtract prefix length)
|
|
25
|
-
const hexLength = Math.max(size - prefix.length, 8); // min 8 hex chars
|
|
26
|
-
|
|
27
|
-
// number of 32-bit integers needed to cover the hexLength
|
|
28
|
-
const numInts = Math.ceil(hexLength / 8);
|
|
29
|
-
|
|
30
|
-
const arr = crypto.getRandomValues(new Uint32Array(numInts));
|
|
31
|
-
let id = arr.reduce((acc, val) => acc + val.toString(16).padStart(8, "0"), "");
|
|
32
|
-
|
|
33
|
-
// truncate/pad to desired length
|
|
34
|
-
id = id.slice(0, hexLength).padStart(hexLength, "0");
|
|
35
|
-
|
|
36
|
-
return `${prefix}${id}`;
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './generate-id';
|
package/src/core/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './binary-codec';
|
|
2
|
-
export * from './events';
|
|
3
|
-
export * from './fixed-ticker';
|
|
4
|
-
export * from './generate-id';
|
|
5
|
-
export * from './lerp';
|
|
6
|
-
export * from './driver';
|
|
7
|
-
export * from './navmesh';
|
|
8
|
-
export * from './pooled-codec';
|
|
9
|
-
export * from './prediction';
|
|
10
|
-
export * from './input';
|
package/src/core/input/README.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Input
|
|
2
|
-
|
|
3
|
-
The input system is responsible for managing user input from various sources, such as keyboard and mouse events. It provides a unified interface for querying the current state of input devices and handling input events.
|
|
4
|
-
|
|
5
|
-
## Key Components
|
|
6
|
-
|
|
7
|
-
- **InputManager**: The main class for managing input state and events. It tracks the state of keyboard and mouse inputs and provides methods for querying this state.
|
|
8
|
-
- **InputSnapshot**: A snapshot of the current input state, including the state of all keys and mouse buttons.
|
|
9
|
-
- **InputEventSource**: An interface for different input event sources (e.g., browser events, gamepad events) to provide input data to the InputManager.
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
To use the input system, create an instance of the InputManager and listen for input events from the desired input source. You can then query the current input state using the `snapshot()` and `peek()` methods.
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
const inputManager = new InputManager();
|
|
17
|
-
const inputSource = new BrowserInputSource(document, document.body);
|
|
18
|
-
inputManager.listen(inputSource);
|
|
19
|
-
|
|
20
|
-
// In your game loop
|
|
21
|
-
const inputSnapshot = inputManager.snapshot();
|
|
22
|
-
if (inputSnapshot.keys['Space'].hit) {
|
|
23
|
-
// Handle space key hit
|
|
24
|
-
}
|
package/src/core/input/index.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ButtonState,
|
|
3
|
-
InputEventSource,
|
|
4
|
-
InputHandlers,
|
|
5
|
-
InputSnapshot,
|
|
6
|
-
} from "./types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Manages keyboard and mouse input.
|
|
10
|
-
*
|
|
11
|
-
* Design goals:
|
|
12
|
-
* - Zero allocations per frame/tick
|
|
13
|
-
* - Render reads live state (peek)
|
|
14
|
-
* - Simulation reads frozen state (snapshot)
|
|
15
|
-
* - Deterministic hit/release semantics
|
|
16
|
-
*/
|
|
17
|
-
export class InputManager {
|
|
18
|
-
private keys: Record<string, ButtonState> = Object.create(null);
|
|
19
|
-
private prevKeys: Record<string, boolean> = Object.create(null);
|
|
20
|
-
|
|
21
|
-
private mouse = {
|
|
22
|
-
x: 0,
|
|
23
|
-
y: 0,
|
|
24
|
-
dx: 0,
|
|
25
|
-
dy: 0,
|
|
26
|
-
left: false,
|
|
27
|
-
right: false,
|
|
28
|
-
middle: false,
|
|
29
|
-
scrollX: 0,
|
|
30
|
-
scrollY: 0,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
private prevMouse = {
|
|
34
|
-
left: false,
|
|
35
|
-
right: false,
|
|
36
|
-
middle: false,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
private snapshotA: InputSnapshot;
|
|
40
|
-
private snapshotB: InputSnapshot;
|
|
41
|
-
private snapshotFlip = false;
|
|
42
|
-
private inputSource!: InputEventSource;
|
|
43
|
-
|
|
44
|
-
private handlers: InputHandlers = {
|
|
45
|
-
keydown: (e) => this.onKeyDown(e),
|
|
46
|
-
keyup: (e) => this.onKeyUp(e),
|
|
47
|
-
mousemove: (e) => this.onMouseMove(e),
|
|
48
|
-
mousedown: (e) => this.onMouseDown(e),
|
|
49
|
-
mouseup: (e) => this.onMouseUp(e),
|
|
50
|
-
wheel: (e) => this.onMouseWheel(e),
|
|
51
|
-
swipe: (dir) => this.onSwipe(dir),
|
|
52
|
-
pinch: (scale) => this.onPinch(scale),
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
constructor() {
|
|
56
|
-
this.snapshotA = createEmptySnapshot();
|
|
57
|
-
this.snapshotB = createEmptySnapshot();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Returns a live, non-allocating view of the current input state.
|
|
62
|
-
*
|
|
63
|
-
* - No hit/release detection
|
|
64
|
-
* - No resets
|
|
65
|
-
* - Safe for render passes
|
|
66
|
-
*/
|
|
67
|
-
peek(): Readonly<InputSnapshot> {
|
|
68
|
-
const snap = this.snapshotFlip ? this.snapshotA : this.snapshotB;
|
|
69
|
-
fillLiveView(snap, this.keys, this.mouse);
|
|
70
|
-
return snap;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Produces a frozen snapshot of the input state.
|
|
75
|
-
*
|
|
76
|
-
* - Computes hit/release
|
|
77
|
-
* - Resets deltas
|
|
78
|
-
* - Safe to store for the duration of the tick
|
|
79
|
-
*/
|
|
80
|
-
snapshot(): InputSnapshot {
|
|
81
|
-
const snap = this.snapshotFlip ? this.snapshotA : this.snapshotB;
|
|
82
|
-
this.snapshotFlip = !this.snapshotFlip;
|
|
83
|
-
|
|
84
|
-
fillSnapshot(
|
|
85
|
-
snap,
|
|
86
|
-
this.keys,
|
|
87
|
-
this.prevKeys,
|
|
88
|
-
this.mouse,
|
|
89
|
-
this.prevMouse
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
this.mouse.dx = 0;
|
|
93
|
-
this.mouse.dy = 0;
|
|
94
|
-
this.mouse.scrollX = 0;
|
|
95
|
-
this.mouse.scrollY = 0;
|
|
96
|
-
|
|
97
|
-
this.prevMouse.left = this.mouse.left;
|
|
98
|
-
this.prevMouse.right = this.mouse.right;
|
|
99
|
-
this.prevMouse.middle = this.mouse.middle;
|
|
100
|
-
|
|
101
|
-
return snap;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Starts listening to an input event source
|
|
106
|
-
*/
|
|
107
|
-
listen(source: InputEventSource) {
|
|
108
|
-
if (this.inputSource) this.inputSource.detach();
|
|
109
|
-
this.inputSource = source;
|
|
110
|
-
source.attach(this.handlers);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Stops listening to the current input source.
|
|
115
|
-
*/
|
|
116
|
-
unlisten() {
|
|
117
|
-
if (!this.inputSource) return;
|
|
118
|
-
this.inputSource.detach();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private onKeyDown(e: KeyboardEvent) {
|
|
122
|
-
const key = (this.keys[e.code] ??= { down: false, hit: false, released: false });
|
|
123
|
-
key.down = true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private onKeyUp(e: KeyboardEvent) {
|
|
127
|
-
const key = (this.keys[e.code] ??= { down: false, hit: false, released: false });
|
|
128
|
-
key.down = false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private onMouseMove(e: MouseEvent) {
|
|
132
|
-
const rect = (e.target as HTMLElement).getBoundingClientRect();
|
|
133
|
-
const x = e.clientX - rect.left;
|
|
134
|
-
const y = e.clientY - rect.top;
|
|
135
|
-
|
|
136
|
-
this.mouse.dx += x - this.mouse.x;
|
|
137
|
-
this.mouse.dy += y - this.mouse.y;
|
|
138
|
-
|
|
139
|
-
this.mouse.x = x;
|
|
140
|
-
this.mouse.y = y;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private onMouseDown(e: MouseEvent) {
|
|
144
|
-
if (e.button === 0) this.mouse.left = true;
|
|
145
|
-
if (e.button === 1) this.mouse.middle = true;
|
|
146
|
-
if (e.button === 2) this.mouse.right = true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private onMouseUp(e: MouseEvent) {
|
|
150
|
-
if (e.button === 0) this.mouse.left = false;
|
|
151
|
-
if (e.button === 1) this.mouse.middle = false;
|
|
152
|
-
if (e.button === 2) this.mouse.right = false;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private onMouseWheel(e: WheelEvent) {
|
|
156
|
-
this.mouse.scrollX += e.deltaX;
|
|
157
|
-
this.mouse.scrollY += e.deltaY;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private onSwipe(_dir: "up" | "down" | "left" | "right") {
|
|
161
|
-
// Gesture layer lives above core input
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private onPinch(_scale: number) {
|
|
165
|
-
// Gesture layer lives above core input
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Creates a reusable, fully-initialized snapshot object.
|
|
171
|
-
*/
|
|
172
|
-
function createEmptySnapshot(): InputSnapshot {
|
|
173
|
-
return {
|
|
174
|
-
mouse: {
|
|
175
|
-
position: { x: 0, y: 0 },
|
|
176
|
-
delta: {
|
|
177
|
-
position: { x: 0, y: 0 },
|
|
178
|
-
scroll: { x: 0, y: 0 },
|
|
179
|
-
},
|
|
180
|
-
left: { down: false, hit: false, released: false },
|
|
181
|
-
right: { down: false, hit: false, released: false },
|
|
182
|
-
middle: { down: false, hit: false, released: false },
|
|
183
|
-
},
|
|
184
|
-
keys: Object.create(null),
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Fills a snapshot with live input state.
|
|
190
|
-
* No hit/release, no resets.
|
|
191
|
-
*/
|
|
192
|
-
function fillLiveView(
|
|
193
|
-
snap: InputSnapshot,
|
|
194
|
-
keys: Record<string, ButtonState>,
|
|
195
|
-
mouse: InputManager["mouse"]
|
|
196
|
-
) {
|
|
197
|
-
for (const k in keys) {
|
|
198
|
-
const dst = (snap.keys[k] ??= { down: false, hit: false, released: false });
|
|
199
|
-
dst.down = keys[k].down;
|
|
200
|
-
dst.hit = false;
|
|
201
|
-
dst.released = false;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
snap.mouse.position.x = mouse.x;
|
|
205
|
-
snap.mouse.position.y = mouse.y;
|
|
206
|
-
snap.mouse.delta.position.x = mouse.dx;
|
|
207
|
-
snap.mouse.delta.position.y = mouse.dy;
|
|
208
|
-
snap.mouse.delta.scroll.x = mouse.scrollX;
|
|
209
|
-
snap.mouse.delta.scroll.y = mouse.scrollY;
|
|
210
|
-
|
|
211
|
-
snap.mouse.left.down = mouse.left;
|
|
212
|
-
snap.mouse.right.down = mouse.right;
|
|
213
|
-
snap.mouse.middle.down = mouse.middle;
|
|
214
|
-
|
|
215
|
-
snap.mouse.left.hit = snap.mouse.left.released = false;
|
|
216
|
-
snap.mouse.right.hit = snap.mouse.right.released = false;
|
|
217
|
-
snap.mouse.middle.hit = snap.mouse.middle.released = false;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Fills a snapshot with frozen input state.
|
|
222
|
-
* Computes hit/release and updates previous state.
|
|
223
|
-
*/
|
|
224
|
-
function fillSnapshot(
|
|
225
|
-
snap: InputSnapshot,
|
|
226
|
-
keys: Record<string, ButtonState>,
|
|
227
|
-
prevKeys: Record<string, boolean>,
|
|
228
|
-
mouse: InputManager["mouse"],
|
|
229
|
-
prevMouse: InputManager["prevMouse"]
|
|
230
|
-
) {
|
|
231
|
-
for (const k in keys) {
|
|
232
|
-
const now = keys[k].down;
|
|
233
|
-
const prev = prevKeys[k] ?? false;
|
|
234
|
-
|
|
235
|
-
const dst = (snap.keys[k] ??= { down: false, hit: false, released: false });
|
|
236
|
-
dst.down = now;
|
|
237
|
-
dst.hit = now && !prev;
|
|
238
|
-
dst.released = !now && prev;
|
|
239
|
-
|
|
240
|
-
prevKeys[k] = now;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
snap.mouse.position.x = mouse.x;
|
|
244
|
-
snap.mouse.position.y = mouse.y;
|
|
245
|
-
snap.mouse.delta.position.x = mouse.dx;
|
|
246
|
-
snap.mouse.delta.position.y = mouse.dy;
|
|
247
|
-
snap.mouse.delta.scroll.x = mouse.scrollX;
|
|
248
|
-
snap.mouse.delta.scroll.y = mouse.scrollY;
|
|
249
|
-
|
|
250
|
-
applyButton(snap.mouse.left, mouse.left, prevMouse.left);
|
|
251
|
-
applyButton(snap.mouse.right, mouse.right, prevMouse.right);
|
|
252
|
-
applyButton(snap.mouse.middle, mouse.middle, prevMouse.middle);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function applyButton(dst: ButtonState, now: boolean, prev: boolean) {
|
|
256
|
-
dst.down = now;
|
|
257
|
-
dst.hit = now && !prev;
|
|
258
|
-
dst.released = !now && prev;
|
|
259
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { InputHandlers, InputEventSource } from "../types";
|
|
2
|
-
|
|
3
|
-
export class BrowserInputSource implements InputEventSource {
|
|
4
|
-
private handlers!: InputHandlers;
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
private keyboardTarget: Document | Window,
|
|
8
|
-
private mouseTarget: HTMLElement
|
|
9
|
-
) { }
|
|
10
|
-
|
|
11
|
-
attach(h: InputHandlers) {
|
|
12
|
-
if (this.handlers) {
|
|
13
|
-
this.detach();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.handlers = h;
|
|
17
|
-
|
|
18
|
-
this.keyboardTarget.addEventListener('keydown', h.keydown);
|
|
19
|
-
this.keyboardTarget.addEventListener('keyup', h.keyup);
|
|
20
|
-
|
|
21
|
-
this.mouseTarget.addEventListener('mousemove', h.mousemove);
|
|
22
|
-
this.mouseTarget.addEventListener('mousedown', h.mousedown);
|
|
23
|
-
this.mouseTarget.addEventListener('mouseup', h.mouseup);
|
|
24
|
-
this.mouseTarget.addEventListener('wheel', h.wheel);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
detach() {
|
|
28
|
-
const h = this.handlers;
|
|
29
|
-
if (!h) return;
|
|
30
|
-
|
|
31
|
-
this.keyboardTarget.removeEventListener('keydown', h.keydown);
|
|
32
|
-
this.keyboardTarget.removeEventListener('keyup', h.keyup);
|
|
33
|
-
|
|
34
|
-
this.mouseTarget.removeEventListener('mousemove', h.mousemove);
|
|
35
|
-
this.mouseTarget.removeEventListener('mousedown', h.mousedown);
|
|
36
|
-
this.mouseTarget.removeEventListener('mouseup', h.mouseup);
|
|
37
|
-
this.mouseTarget.removeEventListener('wheel', h.wheel);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./browser";
|
package/src/core/input/types.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export type InputHandlers = {
|
|
2
|
-
keydown: (e: KeyboardEvent) => void;
|
|
3
|
-
keyup: (e: KeyboardEvent) => void;
|
|
4
|
-
|
|
5
|
-
mousemove: (e: MouseEvent) => void;
|
|
6
|
-
mousedown: (e: MouseEvent) => void;
|
|
7
|
-
mouseup: (e: MouseEvent) => void;
|
|
8
|
-
|
|
9
|
-
wheel: (e: WheelEvent) => void;
|
|
10
|
-
|
|
11
|
-
swipe: (direction: 'up' | 'down' | 'left' | 'right') => void;
|
|
12
|
-
pinch: (scale: number) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export interface InputEventSource {
|
|
16
|
-
attach(handlers: InputHandlers): void;
|
|
17
|
-
detach(): void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type ButtonState = {
|
|
21
|
-
down: boolean;
|
|
22
|
-
hit: boolean;
|
|
23
|
-
released: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type Vector2 = {
|
|
27
|
-
x: number;
|
|
28
|
-
y: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type InputSnapshot = {
|
|
32
|
-
keys: Record<string, ButtonState>;
|
|
33
|
-
mouse: {
|
|
34
|
-
position: Vector2;
|
|
35
|
-
delta: { position: Vector2, scroll: Vector2 };
|
|
36
|
-
left: ButtonState;
|
|
37
|
-
middle: ButtonState;
|
|
38
|
-
right: ButtonState;
|
|
39
|
-
};
|
|
40
|
-
};
|