murow 0.0.60 → 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/loop → types/core/driver}/drivers/immediate.d.ts +1 -1
- package/dist/{core/loop → types/core/driver}/drivers/raf.d.ts +1 -1
- package/dist/{core/loop → types/core/driver}/drivers/timeout.d.ts +1 -1
- package/dist/{core/loop → types/core/driver}/index.d.ts +1 -1
- package/dist/{core → types/core}/events/event-system.d.ts +14 -33
- package/dist/{core → types/core}/fixed-ticker/fixed-ticker.d.ts +1 -1
- 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 +7 -1
- package/dist/types/core/input/index.d.ts +3 -0
- package/dist/types/core/input/manager.d.ts +56 -0
- package/dist/types/core/input/sources/browser.d.ts +9 -0
- package/dist/types/core/input/sources/index.d.ts +1 -0
- package/dist/types/core/input/types.d.ts +36 -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}/system-builder.d.ts +20 -9
- package/dist/{ecs → types/ecs}/world.d.ts +11 -0
- package/dist/types/game/index.d.ts +1 -0
- package/dist/types/game/loop/index.d.ts +1 -0
- package/dist/types/game/loop/loop.d.ts +175 -0
- package/dist/{index.d.ts → types/index.d.ts} +2 -0
- package/dist/{net → types/net}/index.d.ts +2 -2
- package/dist/{net → types/net}/server.d.ts +39 -19
- package/dist/{protocol → types/protocol}/intent/define-intent.d.ts +15 -0
- package/dist/{protocol → types/protocol}/intent/index.d.ts +1 -1
- 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/2d/sprite-accessor.test.d.ts +1 -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/events/event-system.js +0 -88
- package/dist/core/events/index.js +0 -1
- package/dist/core/fixed-ticker/fixed-ticker.js +0 -101
- 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 -9
- package/dist/core/lerp/index.js +0 -1
- package/dist/core/lerp/lerp.js +0 -42
- package/dist/core/loop/drivers/immediate.js +0 -61
- package/dist/core/loop/drivers/index.js +0 -3
- package/dist/core/loop/drivers/raf.js +0 -62
- package/dist/core/loop/drivers/timeout.js +0 -71
- package/dist/core/loop/index.js +0 -2
- package/dist/core/loop/loop.js +0 -47
- 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 -180
- package/dist/ecs/system.d.ts +0 -63
- package/dist/ecs/system.js +0 -92
- package/dist/ecs/world-systems.js +0 -79
- package/dist/ecs/world.js +0 -684
- package/dist/index.js +0 -24
- 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 -938
- 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/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 -169
- 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 -9
- 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/loop/README.md +0 -97
- package/src/core/loop/drivers/immediate.ts +0 -66
- package/src/core/loop/drivers/index.ts +0 -3
- package/src/core/loop/drivers/raf.ts +0 -67
- package/src/core/loop/drivers/timeout.ts +0 -77
- package/src/core/loop/index.ts +0 -2
- package/src/core/loop/loop.test.ts +0 -414
- package/src/core/loop/loop.ts +0 -71
- 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 -309
- package/src/ecs/system.ts +0 -111
- package/src/ecs/world-systems.ts +0 -83
- package/src/ecs/world.test.ts +0 -310
- package/src/ecs/world.ts +0 -828
- package/src/index.ts +0 -28
- 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 -1116
- 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 -182
- 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/loop/loop.d.ts → types/core/driver/driver.d.ts} +0 -0
- /package/dist/{core/loop → types/core/driver}/drivers/index.d.ts +0 -0
- /package/dist/{core → types/core}/events/index.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}/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}/world-systems.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}/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/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/{protocol/intent/intent.js → webgpu/types/2d/animation.test.d.ts} +0 -0
package/src/ecs/entity-handle.ts
DELETED
|
@@ -1,563 +0,0 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
2
|
-
import { Entity, World } from "./world";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Syntactic sugar wrapper for entity operations.
|
|
6
|
-
*
|
|
7
|
-
* **Optimized for performance** - Uses raw component store access with inline caching
|
|
8
|
-
* to bypass validation overhead in the public World API.
|
|
9
|
-
*
|
|
10
|
-
* Performance optimizations:
|
|
11
|
-
* - Inline caching: Component indices cached on first access (~29% faster)
|
|
12
|
-
* - Direct store access: Skips validation checks (has-component, error throwing)
|
|
13
|
-
* - Zero allocations: No intermediate objects created
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Fluent chaining API
|
|
18
|
-
* const player = world.entity(world.spawn())
|
|
19
|
-
* .add(Transform, { x: 0, y: 0, rotation: 0 })
|
|
20
|
-
* .add(Health, { current: 100, max: 100 })
|
|
21
|
-
* .add(Velocity, { vx: 0, vy: 0 });
|
|
22
|
-
*
|
|
23
|
-
* // Use the handle - with inline cached store access
|
|
24
|
-
* player.update(Transform, { x: 10 });
|
|
25
|
-
* const health = player.get(Health);
|
|
26
|
-
*
|
|
27
|
-
* // Access raw entity ID
|
|
28
|
-
* console.log(player.id); // number
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // EntityHandle with inline caching is faster:
|
|
34
|
-
* // World API - validates every call:
|
|
35
|
-
* world.update(entity, Transform, { x: 10 }); // Map.get() + hasComponentBit + validation
|
|
36
|
-
* world.update(entity, Transform, { x: 20 }); // Map.get() + hasComponentBit + validation
|
|
37
|
-
*
|
|
38
|
-
* // EntityHandle - cached direct access:
|
|
39
|
-
* handle.update(Transform, { x: 10 }); // Map.get() + cache + store.update
|
|
40
|
-
* handle.update(Transform, { x: 20 }); // Cached! store.update only
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export class EntityHandle {
|
|
44
|
-
// Reusable update batch - parallel arrays for better cache locality
|
|
45
|
-
private static batchArrays: any[] = [];
|
|
46
|
-
private static batchIndices: number[] = [];
|
|
47
|
-
private static batchValues: any[] = [];
|
|
48
|
-
private static batchLength = 0;
|
|
49
|
-
|
|
50
|
-
// Track prepared components to clear cache
|
|
51
|
-
private static preparedComponents: Component<any>[] = [];
|
|
52
|
-
private static preparedCount = 0;
|
|
53
|
-
|
|
54
|
-
// Instance batching state
|
|
55
|
-
private isBatching = false;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Creates an entity handle wrapping a world and entity ID.
|
|
59
|
-
*
|
|
60
|
-
* **Note**: Prefer using `world.entity(id)` factory method for cleaner code.
|
|
61
|
-
*
|
|
62
|
-
* @param world - The world managing this entity
|
|
63
|
-
* @param id - The entity ID
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* // Direct construction (verbose)
|
|
68
|
-
* const handle = new EntityHandle(world, world.spawn());
|
|
69
|
-
*
|
|
70
|
-
* // Preferred factory method (cleaner)
|
|
71
|
-
* const handle = world.entity(world.spawn());
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
constructor(
|
|
75
|
-
private readonly world: World,
|
|
76
|
-
private _id: Entity
|
|
77
|
-
) {}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Internal method to reset the entity ID for handle reuse.
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
83
|
-
_reset(id: Entity): void {
|
|
84
|
-
this._id = id;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get component index with inline caching on the Component object.
|
|
89
|
-
* First call does Map.get() and caches on component.__cachedIndex.
|
|
90
|
-
* Subsequent calls use the cached value (~29% faster).
|
|
91
|
-
*
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
private getComponentIndex<T extends object>(component: Component<T>): number {
|
|
95
|
-
// Check if index is already cached on the component object
|
|
96
|
-
let index = (component as any).__cachedIndex;
|
|
97
|
-
if (index === undefined) {
|
|
98
|
-
// First access: lookup and cache
|
|
99
|
-
index = component.__worldIndex;
|
|
100
|
-
(component as any).__cachedIndex = index;
|
|
101
|
-
}
|
|
102
|
-
return index;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get direct TypedArray access to a specific field.
|
|
107
|
-
* Cached on Component object for maximum performance.
|
|
108
|
-
*
|
|
109
|
-
* **Zero-cost abstraction** - Same speed as RAW API after first access.
|
|
110
|
-
*
|
|
111
|
-
* @param component - Component definition
|
|
112
|
-
* @param field - Field name
|
|
113
|
-
* @returns TypedArray with direct access to the field
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const transformX = entity.field(Transform, 'x');
|
|
118
|
-
* const velocityVx = entity.field(Velocity, 'vx');
|
|
119
|
-
*
|
|
120
|
-
* // Direct array access - same as RAW API!
|
|
121
|
-
* transformX[entity.id] += velocityVx[entity.id] * dt;
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
field<T extends object, K extends keyof T>(
|
|
125
|
-
component: Component<T>,
|
|
126
|
-
field: K
|
|
127
|
-
): Float32Array | Int32Array | Uint32Array | Uint16Array | Uint8Array {
|
|
128
|
-
// Cache key on component object
|
|
129
|
-
const cacheKey = `__fieldCache_${String(field)}`;
|
|
130
|
-
let array = (component as any)[cacheKey];
|
|
131
|
-
|
|
132
|
-
if (array === undefined) {
|
|
133
|
-
// First access: get store and cache array
|
|
134
|
-
const index = this.getComponentIndex(component);
|
|
135
|
-
array = this.world.componentStoresArray[index]!.getFieldArray(field);
|
|
136
|
-
(component as any)[cacheKey] = array;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return array;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Add a component to this entity with initial data.
|
|
144
|
-
* Returns `this` for method chaining.
|
|
145
|
-
*
|
|
146
|
-
* @param component - Component definition to add
|
|
147
|
-
* @param data - Initial component data
|
|
148
|
-
* @returns This handle for chaining
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* entity
|
|
153
|
-
* .add(Transform, { x: 0, y: 0, rotation: 0 })
|
|
154
|
-
* .add(Health, { current: 100, max: 100 });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
add<T extends object>(component: Component<T>, data: T): this {
|
|
158
|
-
this.world.add(this._id, component, data);
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Get component data for this entity.
|
|
164
|
-
* Returns a readonly reusable object (zero allocations).
|
|
165
|
-
*
|
|
166
|
-
* In batch mode, returns cached data if available (from prepare() call).
|
|
167
|
-
*
|
|
168
|
-
* @param component - Component to retrieve
|
|
169
|
-
* @returns Readonly component data
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* const transform = entity.get(Transform);
|
|
174
|
-
* console.log(transform.x, transform.y);
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
get<T extends object>(component: Component<T>): Readonly<T> {
|
|
178
|
-
// In batch mode, check inline cache first
|
|
179
|
-
if (this.isBatching) {
|
|
180
|
-
const cached = (component as any).__batchCache;
|
|
181
|
-
if (cached !== undefined) {
|
|
182
|
-
return cached;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const index = this.getComponentIndex(component);
|
|
187
|
-
return this.world.componentStoresArray[index]!.get(this._id);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Pre-fetch and cache component data for batch mode.
|
|
192
|
-
* Use this before get() calls in beginUpdate() blocks for better performance.
|
|
193
|
-
*
|
|
194
|
-
* Only has effect in batch mode - does nothing when called outside beginUpdate().
|
|
195
|
-
*
|
|
196
|
-
* @param components - Components to pre-fetch
|
|
197
|
-
* @returns This handle for chaining
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```typescript
|
|
201
|
-
* entity.beginUpdate().prepare(Transform, Velocity);
|
|
202
|
-
*
|
|
203
|
-
* const transform = entity.get(Transform); // Uses cached data
|
|
204
|
-
* const velocity = entity.get(Velocity); // Uses cached data
|
|
205
|
-
*
|
|
206
|
-
* entity
|
|
207
|
-
* .setField(Transform, 'x', transform.x + velocity.vx * dt)
|
|
208
|
-
* .setField(Transform, 'y', transform.y + velocity.vy * dt)
|
|
209
|
-
* .flush();
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
prepare(...components: Component<any>[]): this {
|
|
213
|
-
if (this.isBatching) {
|
|
214
|
-
const prepared = EntityHandle.preparedComponents;
|
|
215
|
-
let count = EntityHandle.preparedCount;
|
|
216
|
-
|
|
217
|
-
for (let i = 0; i < components.length; i++) {
|
|
218
|
-
const component = components[i]!;
|
|
219
|
-
const index = this.getComponentIndex(component);
|
|
220
|
-
const data = this.world.componentStoresArray[index]!.get(this._id);
|
|
221
|
-
(component as any).__batchCache = data;
|
|
222
|
-
|
|
223
|
-
// Track for cleanup
|
|
224
|
-
if (count < prepared.length) {
|
|
225
|
-
prepared[count] = component;
|
|
226
|
-
} else {
|
|
227
|
-
prepared.push(component);
|
|
228
|
-
}
|
|
229
|
-
count++;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
EntityHandle.preparedCount = count;
|
|
233
|
-
}
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Update specific fields of a component.
|
|
239
|
-
* Returns `this` for method chaining.
|
|
240
|
-
*
|
|
241
|
-
* More efficient than get + set for partial changes.
|
|
242
|
-
*
|
|
243
|
-
* @param component - Component to update
|
|
244
|
-
* @param data - Partial data to update
|
|
245
|
-
* @returns This handle for chaining
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```typescript
|
|
249
|
-
* // Update single field
|
|
250
|
-
* entity.update(Transform, { x: 150 });
|
|
251
|
-
*
|
|
252
|
-
* // Chain multiple updates
|
|
253
|
-
* entity
|
|
254
|
-
* .update(Transform, { x: 100, y: 200 })
|
|
255
|
-
* .update(Health, { current: 50 });
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
update<T extends object>(component: Component<T>, data: Partial<T>): this {
|
|
259
|
-
const index = this.getComponentIndex(component);
|
|
260
|
-
this.world.componentStoresArray[index]!.update(this._id, data);
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Update fields using an updater function that mutates the component data directly.
|
|
266
|
-
* Zero allocations - the function mutates the mutable data object in place.
|
|
267
|
-
*
|
|
268
|
-
* @param component - Component to update
|
|
269
|
-
* @param updater - Function that receives mutable data and mutates it directly
|
|
270
|
-
* @returns This handle for chaining
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```typescript
|
|
274
|
-
* // Mutate fields directly
|
|
275
|
-
* entity.setFields(Transform, function (t) {
|
|
276
|
-
* t.x += velocity.vx * dt;
|
|
277
|
-
* t.y += velocity.vy * dt;
|
|
278
|
-
* });
|
|
279
|
-
*
|
|
280
|
-
* // Conditional mutation
|
|
281
|
-
* entity.setFields(Health, function (h) {
|
|
282
|
-
* if (h.current < h.max) {
|
|
283
|
-
* h.current += 5;
|
|
284
|
-
* }
|
|
285
|
-
* });
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
setFields<T extends object>(
|
|
289
|
-
component: Component<T>,
|
|
290
|
-
updater: (current: T) => void
|
|
291
|
-
): this {
|
|
292
|
-
const index = this.getComponentIndex(component);
|
|
293
|
-
const store = this.world.componentStoresArray[index]!;
|
|
294
|
-
const mutable = store.getMutable(this._id);
|
|
295
|
-
updater(mutable);
|
|
296
|
-
store.set(this._id, mutable);
|
|
297
|
-
return this;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Set a single field directly without allocating an object.
|
|
302
|
-
* Zero-cost operation - same speed as RAW API.
|
|
303
|
-
*
|
|
304
|
-
* When batching is enabled (via beginUpdate()), this queues the update
|
|
305
|
-
* instead of applying it immediately. Call flush() to apply batched updates.
|
|
306
|
-
*
|
|
307
|
-
* @param component - Component to update
|
|
308
|
-
* @param field - Field name
|
|
309
|
-
* @param value - New value
|
|
310
|
-
* @returns This handle for chaining
|
|
311
|
-
*
|
|
312
|
-
* @example
|
|
313
|
-
* ```typescript
|
|
314
|
-
* // Immediate update
|
|
315
|
-
* entity.setField(Transform, 'x', 150);
|
|
316
|
-
*
|
|
317
|
-
* // Batched updates (reduced allocations, better JIT)
|
|
318
|
-
* entity.beginUpdate()
|
|
319
|
-
* .setField(Transform, 'x', 150)
|
|
320
|
-
* .setField(Transform, 'y', 200)
|
|
321
|
-
* .setField(Health, 'current', 50)
|
|
322
|
-
* .flush();
|
|
323
|
-
* ```
|
|
324
|
-
*/
|
|
325
|
-
setField<T extends object, K extends keyof T>(
|
|
326
|
-
component: Component<T>,
|
|
327
|
-
field: K,
|
|
328
|
-
value: T[K]
|
|
329
|
-
): this {
|
|
330
|
-
const index = this.getComponentIndex(component);
|
|
331
|
-
const store = this.world.componentStoresArray[index]!;
|
|
332
|
-
const array = store.getFieldArray(field);
|
|
333
|
-
|
|
334
|
-
if (this.isBatching) {
|
|
335
|
-
// Queue update for batching using parallel arrays
|
|
336
|
-
const len = EntityHandle.batchLength;
|
|
337
|
-
EntityHandle.batchArrays[len] = array;
|
|
338
|
-
EntityHandle.batchIndices[len] = this._id;
|
|
339
|
-
EntityHandle.batchValues[len] = value;
|
|
340
|
-
EntityHandle.batchLength++;
|
|
341
|
-
} else {
|
|
342
|
-
// Apply immediately
|
|
343
|
-
array[this._id] = value as any;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return this;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Get a single field value directly.
|
|
351
|
-
* More efficient than get() when you only need one field.
|
|
352
|
-
*
|
|
353
|
-
* @param component - Component to read from
|
|
354
|
-
* @param field - Field name
|
|
355
|
-
* @returns Field value
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```typescript
|
|
359
|
-
* const x = entity.getField(Transform, 'x');
|
|
360
|
-
* const health = entity.getField(Health, 'current');
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
getField<T extends object, K extends keyof T>(
|
|
364
|
-
component: Component<T>,
|
|
365
|
-
field: K
|
|
366
|
-
): T[K] {
|
|
367
|
-
const index = this.getComponentIndex(component);
|
|
368
|
-
const store = this.world.componentStoresArray[index]!;
|
|
369
|
-
const array = store.getFieldArray(field);
|
|
370
|
-
return array[this._id] as T[K];
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Set component data for this entity, overwriting all fields.
|
|
375
|
-
* Returns `this` for method chaining.
|
|
376
|
-
*
|
|
377
|
-
* @param component - Component to set
|
|
378
|
-
* @param data - Complete component data
|
|
379
|
-
* @returns This handle for chaining
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```typescript
|
|
383
|
-
* entity.set(Transform, { x: 100, y: 200, rotation: 0 });
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
set<T extends object>(component: Component<T>, data: T): this {
|
|
387
|
-
const index = this.getComponentIndex(component);
|
|
388
|
-
this.world.componentStoresArray[index]!.set(this._id, data);
|
|
389
|
-
return this;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Check if this entity has a specific component.
|
|
394
|
-
*
|
|
395
|
-
* @param component - Component to check
|
|
396
|
-
* @returns True if entity has the component
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* ```typescript
|
|
400
|
-
* if (entity.has(Health)) {
|
|
401
|
-
* const health = entity.get(Health);
|
|
402
|
-
* }
|
|
403
|
-
* ```
|
|
404
|
-
*/
|
|
405
|
-
has<T extends object>(component: Component<T>): boolean {
|
|
406
|
-
return this.world.has(this._id, component);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Remove a component from this entity.
|
|
411
|
-
* Returns `this` for method chaining.
|
|
412
|
-
*
|
|
413
|
-
* @param component - Component to remove
|
|
414
|
-
* @returns This handle for chaining
|
|
415
|
-
*
|
|
416
|
-
* @example
|
|
417
|
-
* ```typescript
|
|
418
|
-
* entity
|
|
419
|
-
* .remove(Velocity)
|
|
420
|
-
* .remove(Health);
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
remove<T extends object>(component: Component<T>): this {
|
|
424
|
-
this.world.remove(this._id, component);
|
|
425
|
-
return this;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Despawn this entity, removing all components.
|
|
430
|
-
* The entity ID will be reused.
|
|
431
|
-
*
|
|
432
|
-
* **Note**: This handle becomes invalid after despawning.
|
|
433
|
-
*
|
|
434
|
-
* @example
|
|
435
|
-
* ```typescript
|
|
436
|
-
* entity.despawn();
|
|
437
|
-
* // entity is now invalid - don't use it!
|
|
438
|
-
* ```
|
|
439
|
-
*/
|
|
440
|
-
despawn(): void {
|
|
441
|
-
this.world.despawn(this._id);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Check if this entity is alive.
|
|
446
|
-
*
|
|
447
|
-
* @returns True if entity exists in the world
|
|
448
|
-
*
|
|
449
|
-
* @example
|
|
450
|
-
* ```typescript
|
|
451
|
-
* if (entity.isAlive()) {
|
|
452
|
-
* entity.update(Health, { current: 0 });
|
|
453
|
-
* }
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
isAlive(): boolean {
|
|
457
|
-
return this.world.isAlive(this._id);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Get the raw entity ID.
|
|
462
|
-
*
|
|
463
|
-
* Use this when you need to pass the entity to raw World API methods
|
|
464
|
-
* or store the ID for later use.
|
|
465
|
-
*
|
|
466
|
-
* @example
|
|
467
|
-
* ```typescript
|
|
468
|
-
* const id = entity.id;
|
|
469
|
-
* world.add(id, Transform, { x: 0, y: 0, rotation: 0 });
|
|
470
|
-
* ```
|
|
471
|
-
*/
|
|
472
|
-
get id(): Entity {
|
|
473
|
-
return this._id;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Get a mutable copy of component data.
|
|
478
|
-
*
|
|
479
|
-
* **Note**: This allocates a new object. Use sparingly in hot paths.
|
|
480
|
-
*
|
|
481
|
-
* @param component - Component to retrieve
|
|
482
|
-
* @returns Mutable copy of component data
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
* ```typescript
|
|
486
|
-
* const transform = entity.getMutable(Transform);
|
|
487
|
-
* transform.x = 100; // OK to mutate
|
|
488
|
-
* entity.set(Transform, transform);
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
|
-
getMutable<T extends object>(component: Component<T>): T {
|
|
492
|
-
const index = this.getComponentIndex(component);
|
|
493
|
-
return this.world.componentStoresArray[index]!.getMutable(this._id);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Begin batching updates for better performance.
|
|
498
|
-
* All setField() calls will be queued until flush() is called.
|
|
499
|
-
*
|
|
500
|
-
* **Benefits:**
|
|
501
|
-
* - Reduced allocations (reusable batch array)
|
|
502
|
-
* - Better JIT optimization (predictable pattern)
|
|
503
|
-
* - Reduced GC pressure
|
|
504
|
-
*
|
|
505
|
-
* @returns This handle for chaining
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* ```typescript
|
|
509
|
-
* // Batch multiple field updates
|
|
510
|
-
* entity.beginUpdate()
|
|
511
|
-
* .setField(Transform, 'x', 150)
|
|
512
|
-
* .setField(Transform, 'y', 200)
|
|
513
|
-
* .setField(Transform, 'rotation', 1.5)
|
|
514
|
-
* .flush();
|
|
515
|
-
* ```
|
|
516
|
-
*/
|
|
517
|
-
beginUpdate(): this {
|
|
518
|
-
this.isBatching = true;
|
|
519
|
-
EntityHandle.batchLength = 0;
|
|
520
|
-
return this;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Apply all batched updates.
|
|
525
|
-
* Resets batching mode - subsequent setField() calls apply immediately.
|
|
526
|
-
*
|
|
527
|
-
* @returns This handle for chaining
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* ```typescript
|
|
531
|
-
* entity.beginUpdate()
|
|
532
|
-
* .setField(Transform, 'x', 150)
|
|
533
|
-
* .setField(Health, 'current', 50)
|
|
534
|
-
* .flush(); // Applies both updates
|
|
535
|
-
* ```
|
|
536
|
-
*/
|
|
537
|
-
flush(): this {
|
|
538
|
-
const arrays = EntityHandle.batchArrays;
|
|
539
|
-
const indices = EntityHandle.batchIndices;
|
|
540
|
-
const values = EntityHandle.batchValues;
|
|
541
|
-
const len = EntityHandle.batchLength;
|
|
542
|
-
|
|
543
|
-
// Apply all batched updates
|
|
544
|
-
for (let i = 0; i < len; i++) {
|
|
545
|
-
arrays[i][indices[i]] = values[i];
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
// Clear prepared component caches
|
|
549
|
-
const prepared = EntityHandle.preparedComponents;
|
|
550
|
-
const prepCount = EntityHandle.preparedCount;
|
|
551
|
-
for (let i = 0; i < prepCount; i++) {
|
|
552
|
-
const component = prepared[i]!;
|
|
553
|
-
(component as any).__batchCache = undefined;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Reset batching state
|
|
557
|
-
this.isBatching = false;
|
|
558
|
-
EntityHandle.batchLength = 0;
|
|
559
|
-
EntityHandle.preparedCount = 0;
|
|
560
|
-
|
|
561
|
-
return this;
|
|
562
|
-
}
|
|
563
|
-
}
|
package/src/ecs/example.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECS Usage Example
|
|
3
|
-
*
|
|
4
|
-
* This example demonstrates how to use the ECS for a simple game.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { defineComponent, World } from "./index";
|
|
8
|
-
import { BinaryCodec } from "../core/binary-codec";
|
|
9
|
-
|
|
10
|
-
// 1. Define components using BinaryCodec schemas
|
|
11
|
-
const Transform = defineComponent("Transform", {
|
|
12
|
-
x: BinaryCodec.f32,
|
|
13
|
-
y: BinaryCodec.f32,
|
|
14
|
-
rotation: BinaryCodec.f32,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const Velocity = defineComponent("Velocity", {
|
|
18
|
-
vx: BinaryCodec.f32,
|
|
19
|
-
vy: BinaryCodec.f32,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const Health = defineComponent("Health", {
|
|
23
|
-
current: BinaryCodec.u16,
|
|
24
|
-
max: BinaryCodec.u16,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const Damage = defineComponent("Damage", {
|
|
28
|
-
amount: BinaryCodec.u16,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// 2. Create systems
|
|
32
|
-
class MovementSystem {
|
|
33
|
-
update(world: World, deltaTime: number) {
|
|
34
|
-
for (const entity of world.query(Transform, Velocity)) {
|
|
35
|
-
const transform = world.get(entity, Transform); // Readonly!
|
|
36
|
-
const velocity = world.get(entity, Velocity); // Readonly!
|
|
37
|
-
|
|
38
|
-
// Update position using update() (efficient partial update)
|
|
39
|
-
world.update(entity, Transform, {
|
|
40
|
-
x: transform.x + velocity.vx * deltaTime,
|
|
41
|
-
y: transform.y + velocity.vy * deltaTime,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class HealthSystem {
|
|
48
|
-
update(world: World) {
|
|
49
|
-
for (const entity of world.query(Health)) {
|
|
50
|
-
const health = world.get(entity, Health);
|
|
51
|
-
|
|
52
|
-
// Despawn dead entities
|
|
53
|
-
if (health.current <= 0) {
|
|
54
|
-
console.log(`Entity ${entity} died`);
|
|
55
|
-
world.despawn(entity);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
class CombatSystem {
|
|
62
|
-
update(world: World) {
|
|
63
|
-
// Simple collision-based damage (in real game, use spatial partitioning)
|
|
64
|
-
const combatants = Array.from(world.query(Transform, Health, Damage));
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < combatants.length; i++) {
|
|
67
|
-
for (let j = i + 1; j < combatants.length; j++) {
|
|
68
|
-
const e1 = combatants[i];
|
|
69
|
-
const e2 = combatants[j];
|
|
70
|
-
|
|
71
|
-
const t1 = world.get(e1, Transform);
|
|
72
|
-
const t2 = world.get(e2, Transform);
|
|
73
|
-
|
|
74
|
-
// Check collision (simple distance check)
|
|
75
|
-
const dx = t1.x - t2.x;
|
|
76
|
-
const dy = t1.y - t2.y;
|
|
77
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
78
|
-
|
|
79
|
-
if (dist < 10) {
|
|
80
|
-
// Apply damage
|
|
81
|
-
const d1 = world.get(e1, Damage);
|
|
82
|
-
const d2 = world.get(e2, Damage);
|
|
83
|
-
|
|
84
|
-
world.update(e1, Health, { current: world.get(e1, Health).current - d2.amount });
|
|
85
|
-
world.update(e2, Health, { current: world.get(e2, Health).current - d1.amount });
|
|
86
|
-
|
|
87
|
-
console.log(`Entities ${e1} and ${e2} collided! Applying damage.`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 3. Create world and spawn entities
|
|
95
|
-
function runExample() {
|
|
96
|
-
const world = new World({
|
|
97
|
-
maxEntities: 1000,
|
|
98
|
-
components: [Transform, Velocity, Health, Damage],
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// Spawn player
|
|
102
|
-
const player = world.spawn();
|
|
103
|
-
world.add(player, Transform, { x: 0, y: 0, rotation: 0 });
|
|
104
|
-
world.add(player, Velocity, { vx: 100, vy: 0 });
|
|
105
|
-
world.add(player, Health, { current: 100, max: 100 });
|
|
106
|
-
world.add(player, Damage, { amount: 10 });
|
|
107
|
-
|
|
108
|
-
// Spawn enemies
|
|
109
|
-
for (let i = 0; i < 5; i++) {
|
|
110
|
-
const enemy = world.spawn();
|
|
111
|
-
world.add(enemy, Transform, { x: 200 + i * 50, y: 0, rotation: 0 });
|
|
112
|
-
world.add(enemy, Velocity, { vx: -50, vy: 0 });
|
|
113
|
-
world.add(enemy, Health, { current: 50, max: 50 });
|
|
114
|
-
world.add(enemy, Damage, { amount: 5 });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
console.log(`Spawned ${world.getEntityCount()} entities`);
|
|
118
|
-
|
|
119
|
-
// 4. Create systems
|
|
120
|
-
const movementSystem = new MovementSystem();
|
|
121
|
-
const combatSystem = new CombatSystem();
|
|
122
|
-
const healthSystem = new HealthSystem();
|
|
123
|
-
|
|
124
|
-
// 5. Game loop
|
|
125
|
-
const deltaTime = 0.016; // 60 FPS
|
|
126
|
-
let tick = 0;
|
|
127
|
-
|
|
128
|
-
const interval = setInterval(() => {
|
|
129
|
-
tick++;
|
|
130
|
-
|
|
131
|
-
// Update systems
|
|
132
|
-
movementSystem.update(world, deltaTime);
|
|
133
|
-
combatSystem.update(world);
|
|
134
|
-
healthSystem.update(world);
|
|
135
|
-
|
|
136
|
-
// Log stats every 10 ticks
|
|
137
|
-
if (tick % 10 === 0) {
|
|
138
|
-
console.log(`Tick ${tick}: ${world.getEntityCount()} entities alive`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Stop after 100 ticks or when all entities are dead
|
|
142
|
-
if (tick >= 100 || world.getEntityCount() === 0) {
|
|
143
|
-
clearInterval(interval);
|
|
144
|
-
console.log("Simulation ended");
|
|
145
|
-
}
|
|
146
|
-
}, deltaTime * 1000);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Run the example
|
|
150
|
-
if (import.meta.main) {
|
|
151
|
-
runExample();
|
|
152
|
-
}
|
package/src/ecs/index.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { defineComponent, type Component, type InferComponentType, type ComponentMeta } from "./component";
|
|
2
|
-
export { ComponentStore } from "./component-store";
|
|
3
|
-
export { World, type Entity, type WorldConfig } from "./world";
|
|
4
|
-
export { EntityHandle } from "./entity-handle";
|