create-threenative 0.2.6 → 0.2.7
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 +2 -2
- package/agent-docs/references/build-profiles.md +126 -0
- package/agent-docs/references/capability-reference.md +431 -20
- package/agent-docs/references/performance-basics.md +8 -5
- package/agent-docs/references/sculpt-from-a-reference.md +1 -1
- package/agent-docs/references/trace-a-slow-frame.md +1 -1
- package/agent-docs/references/visual-baseline.md +8 -4
- package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +5 -5
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-context/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +3 -3
- package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
- package/capabilities.json +555 -21
- package/dist/index.d.ts +30 -1
- package/dist/index.js +294 -55
- package/dist/threenative.js +714 -154
- package/package.json +6 -6
- package/template-assets/assets/mannequin-combat.glb +0 -0
- package/template-assets/assets/mannequin.glb +0 -0
- package/template-assets/assets/player-viewmodel.glb +0 -0
- package/template-assets/assets/sky.jpg +0 -0
- package/template-assets/clearwater/README.md +141 -0
- package/template-assets/clearwater/install.mjs +50 -0
- package/template-assets/clearwater/src/clearwater.ts +180 -0
- package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
- package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
- package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
- package/template-assets/clearwater/src/render/clearwater.ts +278 -0
- package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
- package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
- package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
- package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
- package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
- package/template-assets/patches/three@0.185.1.patch +2101 -138
- package/template-assets/worldEnvironment.ts +52 -1
- package/templates/action-rpg/AGENTS.md +42 -42
- package/templates/action-rpg/CLAUDE.md +42 -42
- package/templates/action-rpg/kit.json +1 -1
- package/templates/action-rpg/package.json +13 -7
- package/templates/action-rpg/playtests/combat.playtest.json +162 -23
- package/templates/action-rpg/playtests/performance.playtest.json +4 -3
- package/templates/action-rpg/playtests/survives.playtest.json +25 -8
- package/templates/action-rpg/src/conventions.ts +24 -18
- package/templates/action-rpg/src/entities/Enemy.ts +74 -24
- package/templates/action-rpg/src/entities/Fighter.ts +127 -0
- package/templates/action-rpg/src/entities/Player.ts +102 -32
- package/templates/action-rpg/src/game.ts +3 -3
- package/templates/action-rpg/src/render/camera.ts +18 -16
- package/templates/action-rpg/src/render/dungeon.ts +192 -0
- package/templates/action-rpg/src/render/lighting.ts +45 -28
- package/templates/action-rpg/src/render/loading.ts +4 -4
- package/templates/action-rpg/src/render/materials.ts +191 -47
- package/templates/action-rpg/src/render/palette.ts +14 -13
- package/templates/action-rpg/src/render/postprocessing.ts +12 -2
- package/templates/action-rpg/src/render/props.ts +117 -0
- package/templates/action-rpg/src/render/quality.ts +40 -82
- package/templates/action-rpg/src/render/sky.ts +36 -13
- package/templates/action-rpg/src/render/touch-controls.ts +1 -1
- package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
- package/templates/action-rpg/src/scenes/Play.ts +61 -39
- package/templates/action-rpg/src/style.css +9 -7
- package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
- package/templates/action-rpg/src/ui/Hud.tsx +3 -3
- package/templates/action-rpg/threenative.config.ts +14 -1
- package/templates/action-rpg/vite.config.ts +4 -1
- package/templates/minimal/AGENTS.md +10 -10
- package/templates/minimal/CLAUDE.md +10 -10
- package/templates/minimal/package.json +12 -6
- package/templates/minimal/playtests/play.playtest.json +6 -5
- package/templates/minimal/playtests/sky.playtest.json +27 -0
- package/templates/minimal/src/conventions.ts +6 -3
- package/templates/minimal/src/entities/Player.ts +73 -27
- package/templates/minimal/src/main.ts +2 -3
- package/templates/minimal/src/render/camera.ts +22 -4
- package/templates/minimal/src/render/lighting.ts +24 -48
- package/templates/minimal/src/render/materials.ts +158 -13
- package/templates/minimal/src/render/palette.ts +10 -7
- package/templates/minimal/src/render/postprocessing.ts +12 -25
- package/templates/minimal/src/render/quality.ts +35 -69
- package/templates/minimal/src/render/sky.ts +35 -54
- package/templates/minimal/src/render/touch-controls.ts +1 -1
- package/templates/minimal/src/render/worldEnvironment.ts +52 -1
- package/templates/minimal/src/scenes/Play.ts +121 -111
- package/templates/minimal/src/state.ts +0 -4
- package/templates/minimal/src/style.css +0 -10
- package/templates/minimal/threenative.config.ts +14 -1
- package/templates/minimal/vite.config.ts +4 -1
- package/templates/platformer/AGENTS.md +18 -56
- package/templates/platformer/CLAUDE.md +18 -56
- package/templates/platformer/kit.json +2 -2
- package/templates/platformer/package.json +13 -9
- package/templates/platformer/playtests/buffer.playtest.json +15 -5
- package/templates/platformer/playtests/collect.playtest.json +8 -34
- package/templates/platformer/playtests/coyote.playtest.json +12 -34
- package/templates/platformer/playtests/damage.playtest.json +40 -15
- package/templates/platformer/playtests/hud.playtest.json +34 -0
- package/templates/platformer/playtests/move.playtest.json +24 -0
- package/templates/platformer/playtests/performance.playtest.json +24 -7
- package/templates/platformer/playtests/respawn.playtest.json +46 -11
- package/templates/platformer/playtests/stomp.playtest.json +49 -12
- package/templates/platformer/playtests/survives.playtest.json +3 -19
- package/templates/platformer/playtests/world.playtest.json +26 -0
- package/templates/platformer/src/entities/Fox.ts +273 -0
- package/templates/platformer/src/entities/Pickup.ts +43 -60
- package/templates/platformer/src/entities/Walker.ts +88 -0
- package/templates/platformer/src/game.ts +11 -8
- package/templates/platformer/src/level/Checkpoints.ts +29 -16
- package/templates/platformer/src/level/Stage.ts +469 -0
- package/templates/platformer/src/render/blocks.ts +94 -0
- package/templates/platformer/src/render/camera.ts +28 -3
- package/templates/platformer/src/render/fox.ts +196 -0
- package/templates/platformer/src/render/lighting.ts +42 -33
- package/templates/platformer/src/render/materials.ts +115 -5
- package/templates/platformer/src/render/palette.ts +68 -53
- package/templates/platformer/src/render/pickups.ts +142 -0
- package/templates/platformer/src/render/postprocessing.ts +12 -2
- package/templates/platformer/src/render/props.ts +147 -0
- package/templates/platformer/src/render/quality.ts +47 -99
- package/templates/platformer/src/render/scenery.ts +172 -0
- package/templates/platformer/src/render/sky.ts +120 -31
- package/templates/platformer/src/render/touch-controls.ts +5 -2
- package/templates/platformer/src/render/walkers.ts +96 -0
- package/templates/platformer/src/render/waterfall.ts +85 -0
- package/templates/platformer/src/render/worldEnvironment.ts +52 -1
- package/templates/platformer/src/scenes/Boot.ts +3 -4
- package/templates/platformer/src/scenes/Play.ts +362 -0
- package/templates/platformer/src/state.ts +16 -14
- package/templates/platformer/src/style.css +9 -8
- package/templates/platformer/src/ui/Hud.tsx +62 -29
- package/templates/platformer/src/ui/Menu.tsx +2 -2
- package/templates/platformer/threenative.config.ts +14 -1
- package/templates/platformer/vite.config.ts +4 -1
- package/templates/puzzle/AGENTS.md +19 -20
- package/templates/puzzle/CLAUDE.md +19 -20
- package/templates/puzzle/assets/native-proof.glb +0 -0
- package/templates/puzzle/assets/native-proof.png +0 -0
- package/templates/puzzle/kit.json +1 -1
- package/templates/puzzle/package.json +13 -7
- package/templates/puzzle/playtests/axis.playtest.json +20 -0
- package/templates/puzzle/playtests/blocked.playtest.json +73 -0
- package/templates/puzzle/playtests/caused.playtest.json +65 -0
- package/templates/puzzle/playtests/lit.playtest.json +74 -0
- package/templates/puzzle/playtests/performance.playtest.json +24 -7
- package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
- package/templates/puzzle/playtests/replay.playtest.json +81 -0
- package/templates/puzzle/playtests/restart.playtest.json +108 -0
- package/templates/puzzle/playtests/seal.playtest.json +98 -0
- package/templates/puzzle/playtests/settle.playtest.json +100 -0
- package/templates/puzzle/playtests/survives.playtest.json +6 -29
- package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
- package/templates/puzzle/src/entities/Crate.ts +99 -42
- package/templates/puzzle/src/entities/Seal.ts +69 -0
- package/templates/puzzle/src/entities/Warden.ts +135 -0
- package/templates/puzzle/src/game.ts +15 -11
- package/templates/puzzle/src/render/camera.ts +66 -31
- package/templates/puzzle/src/render/crateShape.ts +70 -0
- package/templates/puzzle/src/render/lighting.ts +41 -41
- package/templates/puzzle/src/render/loading.ts +4 -4
- package/templates/puzzle/src/render/materials.ts +131 -27
- package/templates/puzzle/src/render/palette.ts +19 -29
- package/templates/puzzle/src/render/postprocessing.ts +15 -3
- package/templates/puzzle/src/render/quality.ts +71 -80
- package/templates/puzzle/src/render/shapes.ts +109 -108
- package/templates/puzzle/src/render/sky.ts +18 -10
- package/templates/puzzle/src/render/touch-controls.ts +8 -51
- package/templates/puzzle/src/render/vault.ts +315 -0
- package/templates/puzzle/src/render/warden.ts +46 -0
- package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
- package/templates/puzzle/src/scenes/Play.ts +793 -0
- package/templates/puzzle/src/state.ts +55 -24
- package/templates/puzzle/src/style.css +7 -8
- package/templates/puzzle/src/ui/App.tsx +2 -2
- package/templates/puzzle/src/ui/Hud.tsx +92 -40
- package/templates/puzzle/src/ui/Menu.tsx +40 -2
- package/templates/puzzle/threenative.config.ts +14 -1
- package/templates/puzzle/vite.config.ts +4 -1
- package/templates/racing/AGENTS.md +19 -20
- package/templates/racing/CLAUDE.md +19 -20
- package/templates/racing/package.json +13 -7
- package/templates/racing/playtests/boost.playtest.json +33 -12
- package/templates/racing/playtests/outcome.playtest.json +32 -50
- package/templates/racing/playtests/performance.playtest.json +2 -1
- package/templates/racing/playtests/ranking.playtest.json +5 -14
- package/templates/racing/playtests/rescue.playtest.json +2 -2
- package/templates/racing/playtests/reverse.playtest.json +30 -8
- package/templates/racing/playtests/shortcut.playtest.json +54 -9
- package/templates/racing/playtests/touch-controls.playtest.json +32 -5
- package/templates/racing/src/entities/CarBody.ts +327 -0
- package/templates/racing/src/entities/LineDriver.ts +220 -0
- package/templates/racing/src/entities/RacingCar.ts +150 -89
- package/templates/racing/src/entities/Rival.ts +61 -24
- package/templates/racing/src/game.ts +5 -0
- package/templates/racing/src/render/camera.ts +49 -7
- package/templates/racing/src/render/lighting.ts +36 -37
- package/templates/racing/src/render/materials.ts +239 -19
- package/templates/racing/src/render/palette.ts +19 -21
- package/templates/racing/src/render/postprocessing.ts +12 -2
- package/templates/racing/src/render/quality.ts +43 -82
- package/templates/racing/src/render/shapes.ts +20 -6
- package/templates/racing/src/render/sky.ts +47 -39
- package/templates/racing/src/render/touch-controls.ts +1 -1
- package/templates/racing/src/render/worldEnvironment.ts +52 -1
- package/templates/racing/src/scenes/Race.ts +107 -54
- package/templates/racing/src/state.ts +2 -0
- package/templates/racing/src/track/Checkline.ts +22 -7
- package/templates/racing/src/track/Lap.ts +64 -36
- package/templates/racing/src/track/Ranking.ts +20 -11
- package/templates/racing/src/track/Track.ts +809 -361
- package/templates/racing/src/track/TrackSector.ts +40 -11
- package/templates/racing/src/track/circuit.ts +477 -0
- package/templates/racing/src/track/rescue.ts +16 -4
- package/templates/racing/threenative.config.ts +14 -1
- package/templates/racing/vite.config.ts +4 -1
- package/templates/rts/AGENTS.md +96 -0
- package/templates/rts/CLAUDE.md +98 -0
- package/templates/rts/kit.json +7 -0
- package/templates/{defense → rts}/package.json +13 -7
- package/templates/{defense → rts}/playtests/performance.playtest.json +28 -26
- package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
- package/templates/rts/playtests/rts-attack.playtest.json +75 -0
- package/templates/rts/playtests/rts-build.playtest.json +68 -0
- package/templates/rts/playtests/rts-orders.playtest.json +150 -0
- package/templates/rts/playtests/rts-train.playtest.json +62 -0
- package/templates/rts/playtests/survives.playtest.json +58 -0
- package/templates/rts/public/favicon.svg +4 -0
- package/templates/rts/src/game.ts +64 -0
- package/templates/rts/src/orders.ts +22 -0
- package/templates/rts/src/render/army.ts +346 -0
- package/templates/rts/src/render/camera.ts +123 -0
- package/templates/rts/src/render/lighting.ts +61 -0
- package/templates/rts/src/render/loading.ts +33 -0
- package/templates/rts/src/render/materials.ts +152 -0
- package/templates/rts/src/render/models.ts +705 -0
- package/templates/rts/src/render/palette.ts +17 -0
- package/templates/rts/src/render/picking.ts +93 -0
- package/templates/{defense → rts}/src/render/postprocessing.ts +15 -3
- package/templates/rts/src/render/quality.ts +128 -0
- package/templates/rts/src/render/resources.ts +141 -0
- package/templates/rts/src/render/sky.ts +44 -0
- package/templates/rts/src/render/terrain.ts +116 -0
- package/templates/{defense → rts}/src/render/worldEnvironment.ts +52 -1
- package/templates/rts/src/scenes/Play.ts +650 -0
- package/templates/rts/src/sim/ai.ts +1140 -0
- package/templates/rts/src/sim/combat.ts +416 -0
- package/templates/rts/src/sim/construction.ts +374 -0
- package/templates/rts/src/sim/economy.ts +167 -0
- package/templates/rts/src/sim/game.ts +1082 -0
- package/templates/rts/src/sim/movement.ts +371 -0
- package/templates/rts/src/sim/nav.ts +276 -0
- package/templates/rts/src/sim/production.ts +180 -0
- package/templates/rts/src/sim/terrain.ts +170 -0
- package/templates/rts/src/sim/types.ts +647 -0
- package/templates/rts/src/sim/vision.ts +46 -0
- package/templates/rts/src/state.ts +100 -0
- package/templates/{defense → rts}/src/style.css +21 -8
- package/templates/rts/src/ui/App.tsx +21 -0
- package/templates/rts/src/ui/Commands.tsx +129 -0
- package/templates/rts/src/ui/GameUi.tsx +22 -0
- package/templates/rts/src/ui/Hud.tsx +165 -0
- package/templates/rts/src/ui/Minimap.tsx +84 -0
- package/templates/rts/tailwind.config.ts +2 -0
- package/templates/rts/threenative.config.ts +56 -0
- package/templates/rts/tsconfig.json +17 -0
- package/templates/{defense → rts}/vite.config.ts +4 -1
- package/templates/runner/AGENTS.md +6 -10
- package/templates/runner/CLAUDE.md +6 -10
- package/templates/runner/README.md +3 -3
- package/templates/runner/package.json +13 -7
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +4 -3
- package/templates/runner/src/entities/Runner.ts +54 -7
- package/templates/runner/src/game.ts +2 -0
- package/templates/runner/src/render/camera.ts +4 -2
- package/templates/runner/src/render/dust.ts +5 -2
- package/templates/runner/src/render/lighting.ts +41 -45
- package/templates/runner/src/render/loading.ts +2 -2
- package/templates/runner/src/render/materials.ts +165 -25
- package/templates/runner/src/render/palette.ts +17 -28
- package/templates/runner/src/render/postprocessing.ts +12 -2
- package/templates/runner/src/render/quality.ts +42 -96
- package/templates/runner/src/render/shapes.ts +59 -37
- package/templates/runner/src/render/sky.ts +32 -41
- package/templates/runner/src/render/touch-controls.ts +1 -1
- package/templates/runner/src/render/worldEnvironment.ts +52 -1
- package/templates/runner/src/scenes/Run.ts +26 -6
- package/templates/runner/src/track.ts +6 -1
- package/templates/runner/threenative.config.ts +14 -1
- package/templates/runner/vite.config.ts +4 -1
- package/templates/sailing/AGENTS.md +12 -12
- package/templates/sailing/CLAUDE.md +12 -12
- package/templates/sailing/assets/ship.glb +0 -0
- package/templates/sailing/package.json +13 -7
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
- package/templates/sailing/playtests/sails.playtest.json +33 -0
- package/templates/sailing/playtests/win.playtest.json +156 -8
- package/templates/sailing/src/conventions.ts +29 -2
- package/templates/sailing/src/entities/Ship.ts +381 -57
- package/templates/sailing/src/game.ts +14 -0
- package/templates/sailing/src/render/camera.ts +63 -9
- package/templates/sailing/src/render/lighting.ts +49 -27
- package/templates/sailing/src/render/materials.ts +50 -15
- package/templates/sailing/src/render/ocean.ts +647 -60
- package/templates/sailing/src/render/palette.ts +16 -12
- package/templates/sailing/src/render/postprocessing.ts +12 -2
- package/templates/sailing/src/render/props.ts +316 -442
- package/templates/sailing/src/render/quality.ts +14 -4
- package/templates/sailing/src/render/sky.ts +116 -23
- package/templates/sailing/src/render/worldEnvironment.ts +52 -1
- package/templates/sailing/src/scenes/Boot.ts +21 -0
- package/templates/sailing/src/scenes/Sailing.ts +173 -39
- package/templates/sailing/src/state.ts +6 -0
- package/templates/sailing/src/ui/Hud.tsx +41 -9
- package/templates/sailing/threenative.config.ts +14 -1
- package/templates/sailing/vite.config.ts +4 -1
- package/templates/shooter/AGENTS.md +27 -42
- package/templates/shooter/CLAUDE.md +27 -42
- package/templates/shooter/index.html +1 -0
- package/templates/shooter/package.json +13 -7
- package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
- package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
- package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
- package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
- package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
- package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
- package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
- package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
- package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
- package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
- package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
- package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
- package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
- package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
- package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
- package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
- package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
- package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
- package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
- package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
- package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
- package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
- package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
- package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
- package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
- package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
- package/templates/shooter/playtests/input-control.playtest.json +43 -98
- package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
- package/templates/shooter/playtests/performance.playtest.json +62 -26
- package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
- package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
- package/templates/shooter/playtests/survives.playtest.json +36 -30
- package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
- package/templates/shooter/src/entities/Breakables.ts +412 -0
- package/templates/shooter/src/entities/Enemy.ts +2095 -0
- package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
- package/templates/shooter/src/entities/Rifle.ts +442 -0
- package/templates/shooter/src/entities/Target.ts +199 -83
- package/templates/shooter/src/entities/TouchControls.ts +276 -0
- package/templates/shooter/src/game.ts +75 -41
- package/templates/shooter/src/main.ts +0 -1
- package/templates/shooter/src/postPhysics.ts +36 -0
- package/templates/shooter/src/render/camera.ts +78 -74
- package/templates/shooter/src/render/decals.ts +142 -82
- package/templates/shooter/src/render/facade.ts +1373 -0
- package/templates/shooter/src/render/gunfx.ts +704 -0
- package/templates/shooter/src/render/lighting.ts +52 -38
- package/templates/shooter/src/render/loading.ts +2 -2
- package/templates/shooter/src/render/materials.ts +100 -88
- package/templates/shooter/src/render/occlusion.ts +108 -0
- package/templates/shooter/src/render/palette.ts +10 -10
- package/templates/shooter/src/render/palm.ts +455 -0
- package/templates/shooter/src/render/pooled-billboards.ts +144 -0
- package/templates/shooter/src/render/postprocessing.ts +15 -3
- package/templates/shooter/src/render/quality.ts +40 -82
- package/templates/shooter/src/render/scale.ts +148 -15
- package/templates/shooter/src/render/shapes.ts +138 -613
- package/templates/shooter/src/render/sky.ts +35 -35
- package/templates/shooter/src/render/town-schematic.ts +120 -0
- package/templates/shooter/src/render/town.ts +986 -0
- package/templates/shooter/src/render/townMaterials.ts +160 -0
- package/templates/shooter/src/render/vehicles.ts +741 -0
- package/templates/shooter/src/render/worldEnvironment.ts +52 -1
- package/templates/shooter/src/scenes/Play.ts +727 -650
- package/templates/shooter/src/state.ts +26 -41
- package/templates/shooter/src/style.css +207 -11
- package/templates/shooter/src/surfaces.ts +131 -0
- package/templates/shooter/src/ui/App.tsx +9 -10
- package/templates/shooter/src/ui/Crosshair.tsx +25 -18
- package/templates/shooter/src/ui/GameUi.tsx +6 -9
- package/templates/shooter/src/ui/Hud.tsx +428 -39
- package/templates/shooter/src/ui/Minimap.tsx +164 -0
- package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
- package/templates/shooter/src/ui/main.tsx +2 -3
- package/templates/shooter/threenative.config.ts +14 -1
- package/templates/shooter/vite.config.ts +4 -1
- package/templates/starter/AGENTS.md +17 -17
- package/templates/starter/CLAUDE.md +17 -17
- package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
- package/templates/starter/package.json +13 -7
- package/templates/starter/playtests/play.playtest.json +2 -1
- package/templates/starter/playtests/survives.playtest.json +1 -1
- package/templates/starter/src/conventions.ts +6 -3
- package/templates/starter/src/entities/Goal.ts +35 -42
- package/templates/starter/src/entities/Player.ts +99 -16
- package/templates/starter/src/render/arena.ts +131 -0
- package/templates/starter/src/render/lighting.ts +27 -44
- package/templates/starter/src/render/materials.ts +164 -35
- package/templates/starter/src/render/palette.ts +16 -16
- package/templates/starter/src/render/postprocessing.ts +6 -7
- package/templates/starter/src/render/quality.ts +43 -101
- package/templates/starter/src/render/shapes.ts +1 -1
- package/templates/starter/src/render/sky.ts +39 -45
- package/templates/starter/src/render/touch-controls.ts +3 -1
- package/templates/starter/src/render/worldEnvironment.ts +52 -1
- package/templates/starter/src/scenes/Play.ts +82 -81
- package/templates/starter/threenative.config.ts +14 -1
- package/templates/starter/vite.config.ts +4 -1
- package/templates/tower-defense/.codex/config.toml +19 -0
- package/templates/tower-defense/.cursor/mcp.json +32 -0
- package/templates/tower-defense/.gemini/settings.json +32 -0
- package/templates/tower-defense/.mcp.json +32 -0
- package/templates/tower-defense/.vscode/mcp.json +36 -0
- package/templates/tower-defense/.zed/settings.json +36 -0
- package/templates/{defense → tower-defense}/AGENTS.md +14 -12
- package/templates/{defense → tower-defense}/CLAUDE.md +14 -12
- package/templates/tower-defense/README.md +16 -0
- package/templates/tower-defense/index.html +12 -0
- package/templates/tower-defense/kit.json +7 -0
- package/templates/tower-defense/opencode.json +41 -0
- package/templates/tower-defense/package.json +56 -0
- package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
- package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
- package/templates/tower-defense/playtests/look.playtest.json +130 -0
- package/templates/tower-defense/playtests/performance.playtest.json +77 -0
- package/templates/tower-defense/playtests/placement.playtest.json +115 -0
- package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
- package/templates/tower-defense/playtests/strike.playtest.json +98 -0
- package/templates/tower-defense/playtests/survives.playtest.json +85 -0
- package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
- package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
- package/templates/tower-defense/playtests/victory.playtest.json +810 -0
- package/templates/tower-defense/src/balance.ts +187 -0
- package/templates/tower-defense/src/board/Board.ts +100 -0
- package/templates/tower-defense/src/board/Route.ts +84 -0
- package/templates/tower-defense/src/camera-rig.ts +62 -0
- package/templates/tower-defense/src/economy.ts +64 -0
- package/templates/tower-defense/src/effects/Effects.ts +284 -0
- package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
- package/templates/tower-defense/src/game.ts +72 -0
- package/templates/tower-defense/src/intents.ts +21 -0
- package/templates/tower-defense/src/main.ts +15 -0
- package/templates/tower-defense/src/physics.ts +6 -0
- package/templates/tower-defense/src/render/camera.ts +38 -0
- package/templates/tower-defense/src/render/lighting.ts +42 -0
- package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
- package/templates/tower-defense/src/render/materials.ts +103 -0
- package/templates/tower-defense/src/render/palette.ts +58 -0
- package/templates/tower-defense/src/render/postprocessing.ts +46 -0
- package/templates/tower-defense/src/render/quality.ts +128 -0
- package/templates/tower-defense/src/render/shapes.ts +550 -0
- package/templates/tower-defense/src/render/sky.ts +27 -0
- package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
- package/templates/tower-defense/src/scenes/Battle.ts +539 -0
- package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
- package/templates/tower-defense/src/state.ts +88 -0
- package/templates/tower-defense/src/style.css +137 -0
- package/templates/tower-defense/src/towers/Tower.ts +230 -0
- package/templates/tower-defense/src/towers/targeting.ts +97 -0
- package/templates/tower-defense/src/ui/Hud.tsx +270 -0
- package/templates/tower-defense/src/ui/Menu.tsx +134 -0
- package/templates/tower-defense/src/ui/icons.tsx +54 -0
- package/templates/tower-defense/src/ui/main.tsx +14 -0
- package/templates/tower-defense/src/waves.ts +90 -0
- package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
- package/templates/tower-defense/vite.config.ts +41 -0
- package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
- package/agent-files/.claude/skills/ponytail/SKILL.md +0 -68
- package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
- package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -53
- package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
- package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -65
- package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -58
- package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
- package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
- package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
- package/agent-files/AGENT-ROLES.md +0 -26
- package/templates/action-rpg/src/render/shapes.ts +0 -269
- package/templates/action-rpg/src/render/types.ts +0 -3
- package/templates/action-rpg/src/scenes/Boot.ts +0 -12
- package/templates/defense/README.md +0 -10
- package/templates/defense/kit.json +0 -7
- package/templates/defense/playtests/leak.playtest.json +0 -23
- package/templates/defense/playtests/placement.playtest.json +0 -40
- package/templates/defense/playtests/scan.playtest.json +0 -20
- package/templates/defense/playtests/survive.playtest.json +0 -45
- package/templates/defense/playtests/survives.playtest.json +0 -36
- package/templates/defense/src/attackers/Attacker.ts +0 -120
- package/templates/defense/src/board/Route.ts +0 -94
- package/templates/defense/src/conventions.ts +0 -18
- package/templates/defense/src/economy.ts +0 -36
- package/templates/defense/src/entities/Player.ts +0 -52
- package/templates/defense/src/game.ts +0 -51
- package/templates/defense/src/physics.ts +0 -13
- package/templates/defense/src/placement/Buildable.ts +0 -49
- package/templates/defense/src/render/camera.ts +0 -16
- package/templates/defense/src/render/lighting.ts +0 -37
- package/templates/defense/src/render/materials.ts +0 -22
- package/templates/defense/src/render/palette.ts +0 -28
- package/templates/defense/src/render/quality.ts +0 -170
- package/templates/defense/src/render/shapes.ts +0 -246
- package/templates/defense/src/render/sky.ts +0 -45
- package/templates/defense/src/scenes/Boot.ts +0 -12
- package/templates/defense/src/scenes/Defense.ts +0 -231
- package/templates/defense/src/state.ts +0 -56
- package/templates/defense/src/towers/Tower.ts +0 -95
- package/templates/defense/src/towers/targeting.ts +0 -53
- package/templates/defense/src/ui/Hud.tsx +0 -62
- package/templates/defense/src/ui/Menu.tsx +0 -7
- package/templates/defense/src/waves.ts +0 -40
- package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
- package/templates/minimal/src/render/hud.ts +0 -69
- package/templates/platformer/playtests/avoidance.playtest.json +0 -28
- package/templates/platformer/playtests/chase.playtest.json +0 -21
- package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
- package/templates/platformer/playtests/oneway.playtest.json +0 -44
- package/templates/platformer/playtests/patrol.playtest.json +0 -13
- package/templates/platformer/playtests/physics.playtest.json +0 -14
- package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
- package/templates/platformer/src/conventions.ts +0 -18
- package/templates/platformer/src/entities/Character.ts +0 -286
- package/templates/platformer/src/entities/Chaser.ts +0 -118
- package/templates/platformer/src/entities/Patrol.ts +0 -93
- package/templates/platformer/src/level/Platform.ts +0 -46
- package/templates/platformer/src/render/rig.ts +0 -60
- package/templates/platformer/src/render/terrain.ts +0 -31
- package/templates/platformer/src/scenes/Level.ts +0 -241
- package/templates/puzzle/README.md +0 -43
- package/templates/puzzle/playtests/carry.playtest.json +0 -71
- package/templates/puzzle/playtests/swing.playtest.json +0 -38
- package/templates/puzzle/src/conventions.ts +0 -25
- package/templates/puzzle/src/entities/Ball.ts +0 -70
- package/templates/puzzle/src/entities/Gripper.ts +0 -69
- package/templates/puzzle/src/entities/Pendulum.ts +0 -89
- package/templates/puzzle/src/physics.ts +0 -19
- package/templates/puzzle/src/room.ts +0 -83
- package/templates/puzzle/src/scenes/Boot.ts +0 -12
- package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
- package/templates/shooter/playtests/combat.playtest.json +0 -48
- package/templates/shooter/playtests/fail.playtest.json +0 -31
- package/templates/shooter/playtests/per-item.playtest.json +0 -59
- package/templates/shooter/playtests/shooter.playtest.json +0 -99
- package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
- package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
- package/templates/shooter/src/combat/damage.ts +0 -40
- package/templates/shooter/src/conventions.ts +0 -51
- package/templates/shooter/src/entities/Pickup.ts +0 -70
- package/templates/shooter/src/entities/Player.ts +0 -310
- package/templates/shooter/src/level/SpawnPoints.ts +0 -28
- package/templates/shooter/src/playtest-events.ts +0 -15
- package/templates/shooter/src/render/touch-controls.ts +0 -305
- package/templates/shooter/src/render/types.ts +0 -3
- package/templates/shooter/src/render/ui.css +0 -330
- package/templates/shooter/src/render/ui.ts +0 -75
- package/templates/shooter/src/render/vfx.ts +0 -215
- package/templates/shooter/src/ui/Menu.tsx +0 -41
- package/templates/shooter/src/waves.ts +0 -50
- package/templates/shooter/src/weapons/Hitscan.ts +0 -42
- package/templates/shooter/src/weapons/Projectile.ts +0 -92
- package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
- package/templates/starter/playtests/assets.playtest.json +0 -65
- package/templates/starter/playtests/buffer.playtest.json +0 -79
- package/templates/starter/playtests/cloth.playtest.json +0 -113
- package/templates/starter/playtests/coyote.playtest.json +0 -87
- package/templates/starter/playtests/gameover.playtest.json +0 -66
- package/templates/starter/playtests/goal.playtest.json +0 -67
- package/templates/starter/playtests/look.playtest.json +0 -175
- package/templates/starter/playtests/models-baseline.png +0 -0
- package/templates/starter/playtests/models.playtest.json +0 -74
- package/templates/starter/playtests/monitoring.playtest.json +0 -72
- package/templates/starter/playtests/odometer.playtest.json +0 -54
- package/templates/starter/playtests/restart.playtest.json +0 -91
- package/templates/starter/playtests/seed.playtest.json +0 -54
- package/templates/starter/playtests/textures-baseline.png +0 -0
- package/templates/starter/playtests/textures.playtest.json +0 -74
- package/templates/starter/playtests/touch-controls.playtest.json +0 -42
- package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
- package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
- package/templates/starter/src/render/coast.ts +0 -199
- package/templates/starter/src/render/hero.ts +0 -88
- package/templates/starter/src/render/implicitSurface.ts +0 -199
- package/templates/starter/src/render/kuwahara.ts +0 -174
- package/templates/starter/src/render/outline.ts +0 -141
- package/templates/starter/src/render/painterly.ts +0 -86
- package/templates/starter/src/render/rockRidge.ts +0 -198
- package/templates/starter/src/render/rockRidge.worker.ts +0 -77
- package/templates/starter/src/render/scenery.ts +0 -40
- package/templates/starter/src/render/textureLifetime.ts +0 -53
- package/templates/starter/src/render/water.ts +0 -38
- package/templates/starter/src/render/watercolor.ts +0 -85
- /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
- /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
- /package/templates/{defense → rts}/.codex/config.toml +0 -0
- /package/templates/{defense → rts}/.cursor/mcp.json +0 -0
- /package/templates/{defense → rts}/.gemini/settings.json +0 -0
- /package/templates/{defense → rts}/.mcp.json +0 -0
- /package/templates/{defense → rts}/.vscode/mcp.json +0 -0
- /package/templates/{defense → rts}/.zed/settings.json +0 -0
- /package/templates/{defense → rts}/index.html +0 -0
- /package/templates/{defense → rts}/opencode.json +0 -0
- /package/templates/{defense → rts}/src/main.ts +0 -0
- /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
- /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
- /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
- /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
- /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
- /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
- /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/** Ground navigation, separate flight layer and safe production exits. */
|
|
2
|
+
|
|
3
|
+
import type { Game } from "./game.js";
|
|
4
|
+
import { HALF, waterBlocked } from "./terrain.js";
|
|
5
|
+
import {
|
|
6
|
+
type EntityType,
|
|
7
|
+
type IEntity,
|
|
8
|
+
type IObstacle,
|
|
9
|
+
type IPoint,
|
|
10
|
+
type IResourceNode,
|
|
11
|
+
TYPES,
|
|
12
|
+
clamp,
|
|
13
|
+
dist,
|
|
14
|
+
} from "./types.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A unit's own waypoint store, born empty and grown by `travelEntity` to the longest route that
|
|
18
|
+
* unit has actually walked. It used to be born at a measured 96 points per unit — the longest route
|
|
19
|
+
* over three seeded matches is 78 cells — which meant 96 point objects for every entity in the game
|
|
20
|
+
* whether it ever walked 2 cells or 78. Growth is what makes it honest: a unit that never routes
|
|
21
|
+
* pays nothing, one that routes 5 cells pays 5, and a map that wants a longer detour grows the
|
|
22
|
+
* store instead of minting a point on the step that walked it. The store is kept after the path
|
|
23
|
+
* drops its points, so this runs at most once per record-high route length per unit.
|
|
24
|
+
*/
|
|
25
|
+
export function newPathPool(): IPoint[] {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function clearMovement(entity: IEntity): void {
|
|
30
|
+
// Length, not a fresh array: every order change and every retarget empties a path, and the
|
|
31
|
+
// array the entity already owns holds the points this one is dropping.
|
|
32
|
+
entity.path.length = 0;
|
|
33
|
+
entity.pathClock = 0;
|
|
34
|
+
entity.pathGoal = null;
|
|
35
|
+
entity.pathEnd = null;
|
|
36
|
+
entity.pathAdjusted = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Steps toward `(x, z)` on the ground layer. Returns true once the stop radius is reached. */
|
|
40
|
+
export function travelEntity(
|
|
41
|
+
game: Game,
|
|
42
|
+
entity: IEntity,
|
|
43
|
+
x: number,
|
|
44
|
+
z: number,
|
|
45
|
+
dt: number,
|
|
46
|
+
stop = 0.5,
|
|
47
|
+
): boolean {
|
|
48
|
+
if (!Number.isFinite(x) || !Number.isFinite(z) || !Number.isFinite(dt) || dt <= 0) return false;
|
|
49
|
+
const toX = x - entity.x;
|
|
50
|
+
const toZ = z - entity.z;
|
|
51
|
+
const distance = Math.sqrt(toX * toX + toZ * toZ);
|
|
52
|
+
if (distance <= stop + 0.2) {
|
|
53
|
+
entity.moving = false;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const speed = TYPES[entity.type].speed ?? 0;
|
|
57
|
+
if (entity.air) {
|
|
58
|
+
const dx = toX;
|
|
59
|
+
const dz = toZ;
|
|
60
|
+
const step = Math.min(speed * dt, Math.max(0, distance - stop));
|
|
61
|
+
entity.x = clamp(entity.x + (dx / distance) * step, -HALF + entity.r + 1, HALF - entity.r - 1);
|
|
62
|
+
entity.z = clamp(entity.z + (dz / distance) * step, -HALF + entity.r + 1, HALF - entity.r - 1);
|
|
63
|
+
entity.angle = Math.atan2(dx, dz);
|
|
64
|
+
entity.moving = step > 0;
|
|
65
|
+
const left = x - entity.x;
|
|
66
|
+
const near = z - entity.z;
|
|
67
|
+
return Math.sqrt(left * left + near * near) <= stop + 0.2;
|
|
68
|
+
}
|
|
69
|
+
// The destination, in the entity's own point rather than a fresh one: this runs for every
|
|
70
|
+
// travelling unit every step, and sixty units a frame is sixty objects a frame for two numbers.
|
|
71
|
+
// It never outlives the call — `pathGoalPoint` and `pathEndPoint` are separate objects the replan
|
|
72
|
+
// copies it into, so a later call cannot move the goal a path was planned for.
|
|
73
|
+
const dest = entity.goalPoint;
|
|
74
|
+
dest.x = x;
|
|
75
|
+
dest.z = z;
|
|
76
|
+
if (stop > 1) {
|
|
77
|
+
dest.x = x + ((entity.x - x) / distance) * stop * 0.98;
|
|
78
|
+
dest.z = z + ((entity.z - z) / distance) * stop * 0.98;
|
|
79
|
+
}
|
|
80
|
+
const changed = !entity.pathGoal || dist(dest, entity.pathGoal) > 2.5;
|
|
81
|
+
const revisionChanged = entity.pathRevision !== game.navRevision;
|
|
82
|
+
if (
|
|
83
|
+
entity.pathAdjusted &&
|
|
84
|
+
entity.pathEnd &&
|
|
85
|
+
!changed &&
|
|
86
|
+
!revisionChanged &&
|
|
87
|
+
dist(entity, entity.pathEnd) < 0.75
|
|
88
|
+
) {
|
|
89
|
+
entity.moving = false;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (revisionChanged || changed || (!entity.path.length && entity.pathClock <= 0)) {
|
|
93
|
+
entity.pathRevision = game.navRevision;
|
|
94
|
+
// The goal this path was planned for, kept as the entity's own copy of `dest`. It has to be a
|
|
95
|
+
// separate object: `dest` is rewritten by the very next call, and a goal that moved with it
|
|
96
|
+
// would report every step as a new destination and replan forever. `changed` above compares
|
|
97
|
+
// against this, so dropping the assignment also drops the cache it maintains.
|
|
98
|
+
const goal = entity.pathGoalPoint;
|
|
99
|
+
goal.x = dest.x;
|
|
100
|
+
goal.z = dest.z;
|
|
101
|
+
entity.pathGoal = goal;
|
|
102
|
+
// `findRoute` answers from a shared scratch, so the route is copied here into the array and the
|
|
103
|
+
// points the entity already owns — after this, nothing outside the entity holds it, which is
|
|
104
|
+
// what lets the next replan reuse both.
|
|
105
|
+
const route = game.lineClear(entity, dest, entity.r)
|
|
106
|
+
? null
|
|
107
|
+
: game.pathfind(entity, dest, entity.r);
|
|
108
|
+
// The waypoints come out of the unit's own `pathPool`, grown here to fit: a route one cell
|
|
109
|
+
// longer than any this unit has walked would otherwise mint a point, and a path is replanned
|
|
110
|
+
// whenever its length changes. Nothing outside the entity holds a pool point, so handing the
|
|
111
|
+
// same one back on the next replan cannot move a path another unit is walking.
|
|
112
|
+
const length = route === null ? 1 : route.length;
|
|
113
|
+
const pool = entity.pathPool;
|
|
114
|
+
// Doubling rather than growing by one: a route that lengthens a cell at a time would otherwise
|
|
115
|
+
// mint a point on the step that walked it, which is ordinary replanning, not an event. The
|
|
116
|
+
// store is kept after the path drops its points, so a unit pays this at most once per doubling
|
|
117
|
+
// of its longest route — a handful of allocations across a whole match, not one per detour.
|
|
118
|
+
if (length > pool.length) {
|
|
119
|
+
const target = Math.max(length, pool.length * 2);
|
|
120
|
+
for (let i = pool.length; i < target; i++) pool.push({ x: 0, z: 0 });
|
|
121
|
+
}
|
|
122
|
+
const waypoints = entity.path;
|
|
123
|
+
waypoints.length = length;
|
|
124
|
+
for (let i = 0; i < length; i++) {
|
|
125
|
+
const source = route === null ? dest : route[i];
|
|
126
|
+
const slot = pool[i];
|
|
127
|
+
if (source === undefined || slot === undefined) continue;
|
|
128
|
+
slot.x = source.x;
|
|
129
|
+
slot.z = source.z;
|
|
130
|
+
waypoints[i] = slot;
|
|
131
|
+
}
|
|
132
|
+
const last = waypoints[length - 1];
|
|
133
|
+
if (last) {
|
|
134
|
+
const end = entity.pathEndPoint;
|
|
135
|
+
end.x = last.x;
|
|
136
|
+
end.z = last.z;
|
|
137
|
+
entity.pathEnd = end;
|
|
138
|
+
} else {
|
|
139
|
+
entity.pathEnd = null;
|
|
140
|
+
}
|
|
141
|
+
entity.pathAdjusted = !!entity.pathEnd && dist(dest, entity.pathEnd) > 0.4;
|
|
142
|
+
entity.pathClock = entity.path.length ? 0.4 : 1.25;
|
|
143
|
+
}
|
|
144
|
+
if (!entity.path.length) {
|
|
145
|
+
entity.moving = false;
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
while (entity.path.length > 1) {
|
|
149
|
+
const head = entity.path[0];
|
|
150
|
+
if (!head || dist(entity, head) >= 0.3) break;
|
|
151
|
+
entity.path.shift();
|
|
152
|
+
}
|
|
153
|
+
const p = entity.path[0];
|
|
154
|
+
if (!p) return false;
|
|
155
|
+
const dx = p.x - entity.x;
|
|
156
|
+
const dz = p.z - entity.z;
|
|
157
|
+
const dd = Math.sqrt(dx * dx + dz * dz);
|
|
158
|
+
if (dd < 0.3) {
|
|
159
|
+
entity.path.shift();
|
|
160
|
+
return entity.pathAdjusted || distance <= stop + 0.4;
|
|
161
|
+
}
|
|
162
|
+
const move = Math.min(speed * dt, dd);
|
|
163
|
+
const nx = entity.x + (dx / dd) * move;
|
|
164
|
+
const nz = entity.z + (dz / dd) * move;
|
|
165
|
+
if (game.blocked(nx, nz, entity.r) && !game.blocked(entity.x, entity.z, entity.r)) {
|
|
166
|
+
entity.path.length = 0;
|
|
167
|
+
entity.pathClock = 0.35;
|
|
168
|
+
entity.moving = false;
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
entity.x = nx;
|
|
172
|
+
entity.z = nz;
|
|
173
|
+
entity.angle = Math.atan2(dx, dz);
|
|
174
|
+
entity.moving = true;
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The first free spot around a producer that a freshly trained unit can stand on. */
|
|
179
|
+
export function spawnExit(
|
|
180
|
+
game: Game,
|
|
181
|
+
building: IEntity,
|
|
182
|
+
type: EntityType = "worker",
|
|
183
|
+
): IPoint | null {
|
|
184
|
+
const d = TYPES[type];
|
|
185
|
+
for (let ring = 0; ring < 5; ring++) {
|
|
186
|
+
for (let i = 0; i < 32; i++) {
|
|
187
|
+
const angle = Math.PI * 0.5 + (i % 2 ? 1 : -1) * Math.ceil(i / 2) * (Math.PI / 16);
|
|
188
|
+
const radius = building.r + d.r + 1.25 + ring * 2;
|
|
189
|
+
const p = {
|
|
190
|
+
x: building.x + Math.cos(angle) * radius,
|
|
191
|
+
z: building.z + Math.sin(angle) * radius,
|
|
192
|
+
};
|
|
193
|
+
if (Math.abs(p.x) > HALF - d.r - 1 || Math.abs(p.z) > HALF - d.r - 1) continue;
|
|
194
|
+
if (!d.air && game.blocked(p.x, p.z, d.r)) continue;
|
|
195
|
+
if (
|
|
196
|
+
game.entities.some(
|
|
197
|
+
(u) =>
|
|
198
|
+
!u.building &&
|
|
199
|
+
!u.garrisonId &&
|
|
200
|
+
u.hp > 0 &&
|
|
201
|
+
!!u.air === !!d.air &&
|
|
202
|
+
dist(u, p) < u.r + d.r + 0.12,
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
continue;
|
|
206
|
+
return p;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The perimeter candidate `approachInteraction` is testing, reused so the ring costs no objects. */
|
|
213
|
+
const _candidate: IPoint = { x: 0, z: 0 };
|
|
214
|
+
|
|
215
|
+
/** Reused by `separateEntities`, which runs every step: the buffers are the whole reason it is free. */
|
|
216
|
+
const _units: IEntity[] = [];
|
|
217
|
+
const _solids: (IEntity | IObstacle)[] = [];
|
|
218
|
+
|
|
219
|
+
export function separateEntities(game: Game, dt: number): void {
|
|
220
|
+
_units.length = 0;
|
|
221
|
+
_solids.length = 0;
|
|
222
|
+
const entities = game.entities;
|
|
223
|
+
for (let i = 0; i < entities.length; i++) {
|
|
224
|
+
const entity = entities[i];
|
|
225
|
+
if (entity === undefined || entity.hp <= 0) continue;
|
|
226
|
+
if (entity.building) _solids.push(entity);
|
|
227
|
+
else if (!entity.garrisonId) _units.push(entity);
|
|
228
|
+
}
|
|
229
|
+
for (let i = 0; i < game.obstacles.length; i++) {
|
|
230
|
+
const o = game.obstacles[i];
|
|
231
|
+
if (o !== undefined) _solids.push(o);
|
|
232
|
+
}
|
|
233
|
+
const units = _units;
|
|
234
|
+
const solids = _solids;
|
|
235
|
+
for (let i = 0; i < units.length; i++) {
|
|
236
|
+
const a = units[i];
|
|
237
|
+
if (!a) continue;
|
|
238
|
+
// The pre-push position, as two numbers: the water rollback below is the only reader, and a
|
|
239
|
+
// point object per unit per step is sixty objects a frame for a value read once.
|
|
240
|
+
const oldX = a.x;
|
|
241
|
+
const oldZ = a.z;
|
|
242
|
+
for (let j = i + 1; j < units.length; j++) {
|
|
243
|
+
const b = units[j];
|
|
244
|
+
if (!b) continue;
|
|
245
|
+
if (!!a.air !== !!b.air) continue;
|
|
246
|
+
let dx = a.x - b.x;
|
|
247
|
+
let dz = a.z - b.z;
|
|
248
|
+
let d = Math.sqrt(dx * dx + dz * dz);
|
|
249
|
+
const min = (a.r + b.r) * 0.83;
|
|
250
|
+
if (d >= min) continue;
|
|
251
|
+
if (d < 0.0001) {
|
|
252
|
+
const angle = (a.id * 2.399963 + b.id * 0.741) % 6.283185;
|
|
253
|
+
dx = Math.cos(angle) * 0.001;
|
|
254
|
+
dz = Math.sin(angle) * 0.001;
|
|
255
|
+
d = 0.001;
|
|
256
|
+
}
|
|
257
|
+
const push = (min - d) * Math.min(0.5, dt * 5);
|
|
258
|
+
a.x += (dx / d) * push;
|
|
259
|
+
a.z += (dz / d) * push;
|
|
260
|
+
b.x -= (dx / d) * push;
|
|
261
|
+
b.z -= (dz / d) * push;
|
|
262
|
+
}
|
|
263
|
+
if (!a.air) {
|
|
264
|
+
for (let s = 0; s < solids.length; s++) {
|
|
265
|
+
const o = solids[s];
|
|
266
|
+
if (o === undefined) continue;
|
|
267
|
+
let dx = a.x - o.x;
|
|
268
|
+
let dz = a.z - o.z;
|
|
269
|
+
let d = Math.sqrt(dx * dx + dz * dz);
|
|
270
|
+
const min = o.r + a.r + 0.035;
|
|
271
|
+
if (d >= min) continue;
|
|
272
|
+
if (d < 0.0001) {
|
|
273
|
+
const angle = a.id * 2.399963;
|
|
274
|
+
dx = Math.cos(angle) * 0.001;
|
|
275
|
+
dz = Math.sin(angle) * 0.001;
|
|
276
|
+
d = 0.001;
|
|
277
|
+
}
|
|
278
|
+
a.x = o.x + (dx / d) * min;
|
|
279
|
+
a.z = o.z + (dz / d) * min;
|
|
280
|
+
}
|
|
281
|
+
if (
|
|
282
|
+
waterBlocked(a.x, a.z, game.pools, a.r * 0.7) &&
|
|
283
|
+
!waterBlocked(oldX, oldZ, game.pools, a.r * 0.7)
|
|
284
|
+
) {
|
|
285
|
+
a.x = oldX;
|
|
286
|
+
a.z = oldZ;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
a.x = clamp(a.x, -HALF + a.r + 1, HALF - a.r - 1);
|
|
290
|
+
a.z = clamp(a.z, -HALF + a.r + 1, HALF - a.r - 1);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Reach a usable side of a resource or drop-off, rather than a blocked radial goal.
|
|
295
|
+
* Cache the chosen perimeter while travelling; impossible sites retry slowly.
|
|
296
|
+
*/
|
|
297
|
+
export function approachInteraction(
|
|
298
|
+
game: Game,
|
|
299
|
+
unit: IEntity,
|
|
300
|
+
target: IEntity | IResourceNode,
|
|
301
|
+
range: number,
|
|
302
|
+
dt: number,
|
|
303
|
+
): boolean {
|
|
304
|
+
if (dist(unit, target) <= range) {
|
|
305
|
+
unit.moving = false;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
// The cache key is three numbers compared in place, not a template string: this runs for every
|
|
309
|
+
// harvesting worker, every step, and a key is a fresh string each time.
|
|
310
|
+
let cached = unit.interactionGoal;
|
|
311
|
+
if (
|
|
312
|
+
!cached ||
|
|
313
|
+
cached.targetId !== target.id ||
|
|
314
|
+
cached.range !== range ||
|
|
315
|
+
cached.revision !== game.navRevision ||
|
|
316
|
+
(!cached.point && game.time >= cached.retryAt)
|
|
317
|
+
) {
|
|
318
|
+
const angle = Math.atan2(unit.z - target.z, unit.x - target.x);
|
|
319
|
+
const radius = range - 0.35;
|
|
320
|
+
// The candidate ring, in place: `Array.from(...).filter()` was 25 objects and an array per
|
|
321
|
+
// worker per step to walk a ring this loop walks anyway. An unreachable site still caches as
|
|
322
|
+
// no point, exactly as the filtered ring did. The point itself is the unit's own, so a
|
|
323
|
+
// retarget rewrites it instead of minting one per worker per retarget.
|
|
324
|
+
const point = unit.interactionPoint;
|
|
325
|
+
let found = false;
|
|
326
|
+
for (let i = 0; i < 24 && !found; i++) {
|
|
327
|
+
const a = angle + (i % 2 ? 1 : -1) * Math.ceil(i / 2) * (Math.PI / 12);
|
|
328
|
+
_candidate.x = target.x + Math.cos(a) * radius;
|
|
329
|
+
_candidate.z = target.z + Math.sin(a) * radius;
|
|
330
|
+
if (game.blocked(_candidate.x, _candidate.z, unit.r)) continue;
|
|
331
|
+
if (game.lineClear(unit, _candidate, unit.r)) {
|
|
332
|
+
point.x = _candidate.x;
|
|
333
|
+
point.z = _candidate.z;
|
|
334
|
+
found = true;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
const route = game.pathfind(unit, _candidate, unit.r);
|
|
338
|
+
const end = route[route.length - 1];
|
|
339
|
+
let walked = true;
|
|
340
|
+
let previous: IPoint = unit;
|
|
341
|
+
for (const step of route) {
|
|
342
|
+
if (!game.lineClear(previous, step, unit.r)) {
|
|
343
|
+
walked = false;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
previous = step;
|
|
347
|
+
}
|
|
348
|
+
if (end && dist(end, _candidate) < 0.35 && walked) {
|
|
349
|
+
point.x = _candidate.x;
|
|
350
|
+
point.z = _candidate.z;
|
|
351
|
+
found = true;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// The cache record is the unit's own, born with it and rewritten here: a retarget is an event,
|
|
356
|
+
// but the record outlives it, so a fresh one per retarget is garbage the moment the next lands.
|
|
357
|
+
cached = unit.interactionGoal;
|
|
358
|
+
cached.point = found ? point : null;
|
|
359
|
+
cached.range = range;
|
|
360
|
+
cached.retryAt = game.time + 1.5;
|
|
361
|
+
cached.revision = game.navRevision;
|
|
362
|
+
cached.targetId = target.id;
|
|
363
|
+
clearMovement(unit);
|
|
364
|
+
}
|
|
365
|
+
if (!cached.point) {
|
|
366
|
+
unit.moving = false;
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
game.travel(unit, cached.point.x, cached.point.z, dt, 0.18);
|
|
370
|
+
return dist(unit, target) <= range;
|
|
371
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/** Binary-heap A*, sized from the map rather than hard-coded to the original map. */
|
|
2
|
+
|
|
3
|
+
import type { Game } from "./game.js";
|
|
4
|
+
import type { IPoint } from "./types.js";
|
|
5
|
+
|
|
6
|
+
const ORTHOGONAL: readonly (readonly [number, number])[] = [
|
|
7
|
+
[1, 0],
|
|
8
|
+
[-1, 0],
|
|
9
|
+
[0, 1],
|
|
10
|
+
[0, -1],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The search's scratch, sized once per map and reused by every query.
|
|
15
|
+
*
|
|
16
|
+
* A* runs when a unit's route is replanned, which on a marching army is a few times a second across
|
|
17
|
+
* sixty units: three typed arrays of `size * size` and a heap node per push were 200 KB and
|
|
18
|
+
* hundreds of objects per replan, on a path the entity then owns. `findRoute` is synchronous and
|
|
19
|
+
* non-reentrant, so one shared set is enough — the map size never changes for a game.
|
|
20
|
+
*/
|
|
21
|
+
let _size = 0;
|
|
22
|
+
let _costs: Float32Array = new Float32Array(0);
|
|
23
|
+
let _parents: Int32Array = new Int32Array(0);
|
|
24
|
+
let _closed: Uint8Array = new Uint8Array(0);
|
|
25
|
+
/** The heap as two parallel arrays rather than a node object per entry. */
|
|
26
|
+
let _heapIds: Int32Array = new Int32Array(0);
|
|
27
|
+
let _heapFs: Float64Array = new Float64Array(0);
|
|
28
|
+
let _heapLength = 0;
|
|
29
|
+
|
|
30
|
+
function ensureScratch(size: number): void {
|
|
31
|
+
if (_size === size) return;
|
|
32
|
+
_size = size;
|
|
33
|
+
const cells = size * size;
|
|
34
|
+
_costs = new Float32Array(cells);
|
|
35
|
+
_parents = new Int32Array(cells);
|
|
36
|
+
_closed = new Uint8Array(cells);
|
|
37
|
+
_heapIds = new Int32Array(cells);
|
|
38
|
+
_heapFs = new Float64Array(cells);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The world position of cell `i`, written into `out`. */
|
|
42
|
+
function cellPoint(i: number, size: number, cell: number, half: number, out: IPoint): IPoint {
|
|
43
|
+
out.x = (i % size) * cell - half + cell / 2;
|
|
44
|
+
out.z = Math.floor(i / size) * cell - half + cell / 2;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The mask probe's scratch point, reused across the whole map. */
|
|
49
|
+
const _probe: IPoint = { x: 0, z: 0 };
|
|
50
|
+
/** The connector's candidate point, reused per probe. */
|
|
51
|
+
const _candidate: IPoint = { x: 0, z: 0 };
|
|
52
|
+
/** The start centre, read once per query. */
|
|
53
|
+
const _start: IPoint = { x: 0, z: 0 };
|
|
54
|
+
/** The raw cell centre, read while the mask is built. */
|
|
55
|
+
const _center: IPoint = { x: 0, z: 0 };
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The route, rebuilt in place for whoever asks.
|
|
59
|
+
*
|
|
60
|
+
* A* runs whenever a unit's route is replanned, which on a marching army is several times a second
|
|
61
|
+
* across sixty units, and each search allocated an array plus a point per waypoint. The caller
|
|
62
|
+
* copies the route into the entity's own path before it steps again (see `travelEntity`), so this
|
|
63
|
+
* scratch never escapes past the call that filled it.
|
|
64
|
+
*/
|
|
65
|
+
const _route: IPoint[] = [];
|
|
66
|
+
const _routePool: IPoint[] = [];
|
|
67
|
+
let _routeUsed = 0;
|
|
68
|
+
|
|
69
|
+
/** No route: the shared array, emptied, so a caller never reads the previous query's waypoints. */
|
|
70
|
+
function empty(): IPoint[] {
|
|
71
|
+
_route.length = 0;
|
|
72
|
+
_routeUsed = 0;
|
|
73
|
+
return _route;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function routePoint(x: number, z: number): IPoint {
|
|
77
|
+
const pooled = _routePool[_routeUsed];
|
|
78
|
+
if (pooled === undefined) _routePool[_routeUsed] = { x, z };
|
|
79
|
+
const point = _routePool[_routeUsed] ?? { x, z };
|
|
80
|
+
_routeUsed += 1;
|
|
81
|
+
point.x = x;
|
|
82
|
+
point.z = z;
|
|
83
|
+
return point;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function findRoute(
|
|
87
|
+
game: Game,
|
|
88
|
+
startPoint: IPoint,
|
|
89
|
+
endPoint: IPoint,
|
|
90
|
+
radius = 0.8,
|
|
91
|
+
): IPoint[] {
|
|
92
|
+
const size = game.gridSize;
|
|
93
|
+
const cellSize = game.cell;
|
|
94
|
+
const half = game.worldSize / 2;
|
|
95
|
+
const category = radius > 0.9 ? 1.25 : 0.8;
|
|
96
|
+
const key = `${game.navRevision}:${category}`;
|
|
97
|
+
const masks = game.navMasks;
|
|
98
|
+
if (!masks.has(key)) {
|
|
99
|
+
const mask = new Uint8Array(size * size);
|
|
100
|
+
for (let i = 0; i < mask.length; i++) {
|
|
101
|
+
const p = cellPoint(i, size, cellSize, half, _probe);
|
|
102
|
+
mask[i] = game.blocked(p.x, p.z, category) ? 1 : 0;
|
|
103
|
+
}
|
|
104
|
+
if (masks.size > 4) masks.clear();
|
|
105
|
+
masks.set(key, mask);
|
|
106
|
+
}
|
|
107
|
+
const mask = masks.get(key);
|
|
108
|
+
if (!mask) return empty();
|
|
109
|
+
|
|
110
|
+
// World-space positions on a building edge can be valid even when their
|
|
111
|
+
// coarse grid cell is blocked. Connect to a visible free cell at BOTH ends.
|
|
112
|
+
const hasExit = (id: number): boolean => {
|
|
113
|
+
const x = id % size;
|
|
114
|
+
const z = Math.floor(id / size);
|
|
115
|
+
for (let k = 0; k < ORTHOGONAL.length; k++) {
|
|
116
|
+
const step = ORTHOGONAL[k];
|
|
117
|
+
if (step === undefined) continue;
|
|
118
|
+
const nx = x + step[0];
|
|
119
|
+
const nz = z + step[1];
|
|
120
|
+
if (nx > 0 && nz > 0 && nx < size - 1 && nz < size - 1 && !mask[nz * size + nx]) return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const cell = (v: number): number =>
|
|
126
|
+
Math.max(0, Math.min(size - 1, Math.floor((v + half) / cellSize)));
|
|
127
|
+
const connector = (position: IPoint, requireClear: boolean): number => {
|
|
128
|
+
const raw = cell(position.z) * size + cell(position.x);
|
|
129
|
+
const center = cellPoint(raw, size, cellSize, half, _center);
|
|
130
|
+
if (!mask[raw] && hasExit(raw) && (!requireClear || game.lineClear(position, center, radius))) {
|
|
131
|
+
return raw;
|
|
132
|
+
}
|
|
133
|
+
let score = Number.POSITIVE_INFINITY;
|
|
134
|
+
let best = -1;
|
|
135
|
+
const gx = raw % size;
|
|
136
|
+
const gz = Math.floor(raw / size);
|
|
137
|
+
for (let dz = -7; dz <= 7; dz++) {
|
|
138
|
+
for (let dx = -7; dx <= 7; dx++) {
|
|
139
|
+
const x = gx + dx;
|
|
140
|
+
const z = gz + dz;
|
|
141
|
+
if (x < 1 || z < 1 || x >= size - 1 || z >= size - 1) continue;
|
|
142
|
+
const id = z * size + x;
|
|
143
|
+
if (mask[id] || !hasExit(id)) continue;
|
|
144
|
+
const p = cellPoint(id, size, cellSize, half, _candidate);
|
|
145
|
+
const d = Math.hypot(p.x - position.x, p.z - position.z);
|
|
146
|
+
if (d < score && (!requireClear || game.lineClear(position, p, radius))) {
|
|
147
|
+
score = d;
|
|
148
|
+
best = id;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return best;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const canReachExactEnd = !game.blocked(endPoint.x, endPoint.z, radius);
|
|
156
|
+
const start = connector(startPoint, true);
|
|
157
|
+
const goal = connector(endPoint, canReachExactEnd);
|
|
158
|
+
if (start < 0 || goal < 0) return empty();
|
|
159
|
+
|
|
160
|
+
ensureScratch(size);
|
|
161
|
+
const costs = _costs;
|
|
162
|
+
const parent = _parents;
|
|
163
|
+
const closed = _closed;
|
|
164
|
+
// Refilled by a generation stamp rather than by rewriting every cell: a `fill` per query is a
|
|
165
|
+
// second pass over the whole grid for a search that usually visits a few hundred cells.
|
|
166
|
+
costs.fill(Number.POSITIVE_INFINITY);
|
|
167
|
+
closed.fill(0);
|
|
168
|
+
_heapLength = 0;
|
|
169
|
+
const h = (i: number): number => {
|
|
170
|
+
const dx = Math.abs((i % size) - (goal % size));
|
|
171
|
+
const dz = Math.abs(Math.floor(i / size) - Math.floor(goal / size));
|
|
172
|
+
return Math.max(dx, dz) + (Math.SQRT2 - 1) * Math.min(dx, dz);
|
|
173
|
+
};
|
|
174
|
+
const push = (id: number, f: number): void => {
|
|
175
|
+
let i = _heapLength++;
|
|
176
|
+
while (i) {
|
|
177
|
+
const p = (i - 1) >> 1;
|
|
178
|
+
const upF = _heapFs[p] ?? 0;
|
|
179
|
+
if (upF <= f) break;
|
|
180
|
+
_heapIds[i] = _heapIds[p] ?? -1;
|
|
181
|
+
_heapFs[i] = upF;
|
|
182
|
+
i = p;
|
|
183
|
+
}
|
|
184
|
+
_heapIds[i] = id;
|
|
185
|
+
_heapFs[i] = f;
|
|
186
|
+
};
|
|
187
|
+
const pop = (): number => {
|
|
188
|
+
if (_heapLength === 0) return -1;
|
|
189
|
+
const root = _heapIds[0] ?? -1;
|
|
190
|
+
_heapLength -= 1;
|
|
191
|
+
const lastId = _heapIds[_heapLength] ?? -1;
|
|
192
|
+
const lastF = _heapFs[_heapLength] ?? 0;
|
|
193
|
+
if (_heapLength > 0) {
|
|
194
|
+
let i = 0;
|
|
195
|
+
while (true) {
|
|
196
|
+
let c = i * 2 + 1;
|
|
197
|
+
if (c >= _heapLength) break;
|
|
198
|
+
const right = c + 1;
|
|
199
|
+
if (right < _heapLength && (_heapFs[right] ?? 0) < (_heapFs[c] ?? 0)) c = right;
|
|
200
|
+
const childF = _heapFs[c] ?? 0;
|
|
201
|
+
if (childF >= lastF) break;
|
|
202
|
+
_heapIds[i] = _heapIds[c] ?? -1;
|
|
203
|
+
_heapFs[i] = childF;
|
|
204
|
+
i = c;
|
|
205
|
+
}
|
|
206
|
+
_heapIds[i] = lastId;
|
|
207
|
+
_heapFs[i] = lastF;
|
|
208
|
+
}
|
|
209
|
+
return root;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
costs[start] = 0;
|
|
213
|
+
push(start, h(start));
|
|
214
|
+
let found = false;
|
|
215
|
+
for (let loops = 0; _heapLength > 0 && loops < size * size * 2; loops++) {
|
|
216
|
+
const cur = pop();
|
|
217
|
+
if (cur < 0 || closed[cur]) continue;
|
|
218
|
+
if (cur === goal) {
|
|
219
|
+
found = true;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
closed[cur] = 1;
|
|
223
|
+
const cx = cur % size;
|
|
224
|
+
const cz = Math.floor(cur / size);
|
|
225
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
226
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
227
|
+
if (!dx && !dz) continue;
|
|
228
|
+
const x = cx + dx;
|
|
229
|
+
const z = cz + dz;
|
|
230
|
+
if (x < 1 || z < 1 || x >= size - 1 || z >= size - 1) continue;
|
|
231
|
+
const id = z * size + x;
|
|
232
|
+
if (mask[id] || closed[id] || (dx && dz && (mask[cz * size + x] || mask[z * size + cx]))) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const cost = (costs[cur] ?? Number.POSITIVE_INFINITY) + (dx && dz ? Math.SQRT2 : 1);
|
|
236
|
+
if (cost >= (costs[id] ?? Number.POSITIVE_INFINITY)) continue;
|
|
237
|
+
costs[id] = cost;
|
|
238
|
+
parent[id] = cur;
|
|
239
|
+
push(id, cost + h(id));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// No route: the shared array, emptied, so a caller never reads the previous query's waypoints.
|
|
244
|
+
if (!found) {
|
|
245
|
+
_route.length = 0;
|
|
246
|
+
_routeUsed = 0;
|
|
247
|
+
return _route;
|
|
248
|
+
}
|
|
249
|
+
// The parent chain runs goal -> start. It is counted there, then written **back to front**, so
|
|
250
|
+
// `_route[0]` is the cell next to the unit and the last entry is the goal. Writing it front-first
|
|
251
|
+
// reads as a valid route — every cell of the right path, no hole — but puts the goal at index 1
|
|
252
|
+
// and walks the unit the wrong way, which is what the seeded-navigation test catches.
|
|
253
|
+
_routeUsed = 0;
|
|
254
|
+
const startCenter = cellPoint(start, size, cellSize, half, _start);
|
|
255
|
+
const offset =
|
|
256
|
+
Math.hypot(startCenter.x - startPoint.x, startCenter.z - startPoint.z) > 0.1 ? 1 : 0;
|
|
257
|
+
let length = offset;
|
|
258
|
+
for (let cursor = goal; cursor !== start && cursor >= 0; cursor = parent[cursor] ?? -1) {
|
|
259
|
+
length += 1;
|
|
260
|
+
}
|
|
261
|
+
if (canReachExactEnd) length += 1;
|
|
262
|
+
_route.length = length;
|
|
263
|
+
if (offset === 1) _route[0] = routePoint(startCenter.x, startCenter.z);
|
|
264
|
+
// The chain's last cell is the one adjacent to the start, and `offset` claims index 0 for the
|
|
265
|
+
// start-centre prefix when the unit is not already standing on its cell. So the chain is written
|
|
266
|
+
// from its own last slot downwards, stopping above whatever the prefix and the exact end own.
|
|
267
|
+
let index = length - (canReachExactEnd ? 1 : 0) - 1;
|
|
268
|
+
for (let cursor = goal; cursor !== start && cursor >= 0; cursor = parent[cursor] ?? -1) {
|
|
269
|
+
const p = cellPoint(cursor, size, cellSize, half, _candidate);
|
|
270
|
+
_route[index] = routePoint(p.x, p.z);
|
|
271
|
+
index -= 1;
|
|
272
|
+
if (index < offset) break;
|
|
273
|
+
}
|
|
274
|
+
if (canReachExactEnd) _route[length - 1] = routePoint(endPoint.x, endPoint.z);
|
|
275
|
+
return _route;
|
|
276
|
+
}
|