feat(flight): Milestone 3 — F-key Drone Flight Mode#16
Merged
Conversation
- PlayerState.Flying bool: tracks flight mode state (serialized to TS) - InputState.FlyToggle bool: edge-triggered F key press (one frame only) - FlySpeed = WalkSpeed * 10 = 75 units/s (10x ground walk speed) - Flight physics: no gravity, moves in full 3D look direction (pitch controls vertical component), Jump key ascends directly - Sprint in flight = 2x fly speed (150 units/s) - Ground mode physics unchanged - InputSystem: flyTogglePending flag fires once per F keydown then resets - FPSCamera.PlayerState: added flying field - 4 new physics tests: toggle, no-gravity, direction, speed constant Controls: F — toggle flight mode WASD — move in look direction (pitch-coupled vertical in flight) Space — ascend directly (flight) Shift — 2x speed boost (flight + ground sprint) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Three fixes for flight-mode terrain pop-in at 75 u/s:
1. Render radius: 1536 → 2560 units (~5 chunk buffer vs 3)
DistanceThreshold: 2560 → 4608 (wider eviction window)
2. Adaptive stream trigger in GameEngine:
- Flying: re-stream every 64 units (was 128)
- Flying: stream position offset 1024 units ahead in look direction
so chunks are pre-generated before the player arrives
- Grounded: unchanged (128 unit trigger)
3. ChunkWorkerPool: 4 parallel WASM workers for chunk generation
- Primary worker handles physics ticks + world state (unchanged)
- Pool workers each load WASM independently, route generateChunk
calls round-robin → up to 4 chunks generate simultaneously
- Pool initialized lazily in WasmClient.initWorld()
- Falls back to primary worker if pool not yet ready
Result: at 75 u/s flight speed, 5-chunk buffer + 1-chunk lookahead
+ 4x parallel generation means terrain stays ahead of the player.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pool workers each have their own WASM instance. goGenerateChunk stores globalHeightmaps in the pool worker's instance, but goUpdatePlayer (physics) runs on the primary worker whose globalHeightmaps was always empty. Result: SampleHeight returned 0 → player grounded at Y≈1.25 → fell through all terrain. Fix: add go_storeHeightmap(cx, cz, Float32Array) to the primary worker. After each pool chunk generation, WasmClient fires a storeHeightmap message to the primary worker (fire-and-forget, id=-1 sentinel). Primary worker stores the heightmap in its globalHeightmaps, making it available to physics. go_storeHeightmap uses Uint8Array view + js.CopyBytesToGo for efficient bulk copy, then reinterprets bytes as float32 (avoids 16641 individual JS→Go float conversions). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
filterByFrustum tested chunks with AABB maxY=HEIGHT_SCALE(64) but mountain terrain reaches HEIGHT_SCALE*10=640 (10x HeightMultiplier). When flying above Y=64, the frustum bottom plane rose above the AABB top, incorrectly culling visible chunks → flicker and disappearing terrain. Fix: maxTerrainHeight = HEIGHT_SCALE * 10 = 640. Also corrects minY from -64 to 0 (terrain is always non-negative). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Milestone 3: Flight Mode
New Feature: Press F to Toggle Flight
How It Works
flyToggleedge event viaInputSystemphysics.Update()togglesPlayerState.Flyingon receiptFlySpeed = WalkSpeed × 10 = 75 u/sTesting