Rust voxel sandbox (wgpu + wasm + axum multiplayer)
Reshape the engine into a functional-core / imperative-shell split.
The 2500-line state.rs blob is now 1700 lines of mostly GPU plumbing
plus a thin tick() shell that composes pure transformations from the
new sim/ and net/ modules.
src/sim/ (no GPU, no winit, no thread-locals — all pure):
body.rs PlayerBody value type + take_damage / respawned_at
collision.rs AABB primitives, sweep_axis returning (Vec3, bool)
instead of mutating &mut Vec3
edit.rs block_from_u8, apply_edit, chunks_for_edit
event.rs SimEvent enum (Landed, VoidDeath, BlockEdited)
input.rs TouchBridge data type + merge_held
physics.rs step_movement(world, body, MoveInput) -> MoveOutcome
— the central morphism: one tick of player movement
+ collision + landing detection + void check, returns
a new body value and a list of events
spawn.rs find_safe_spawn, fall_damage
src/net/:
parse_inbox(Vec<String>) -> Vec<NetEvent>
Malformed lines drop silently; the shell folds typed events into
the world / remote-player map.
src/state.rs:
- App now holds a single PlayerBody value instead of scattered
velocity / on_ground / hp / alive / max_y_since_ground fields.
- tick() is a pipeline: collect input → merge_held → step_movement
→ fold sim events → block interaction → render_frame.
- drain_net_inbox() parses to events first, then applies.
- render_frame() extracted so the paused and active branches share
the upload + cull + draw path.
Tests: 45 passing (up from 33). New coverage for the physics step
itself: airborne gravity, jump-only-when-grounded, long-fall-emits-
Landed, void floor, dead-body-does-not-move. Net parsing tests for
malformed lines and round-trips. Body tests for damage / respawn.
Build: cargo test (45/45), cargo build --target wasm32-unknown-unknown
--lib --release, and the axum server all green.
|
||
|---|---|---|
| server | ||
| src | ||
| web | ||
| .dockerignore | ||
| .gitignore | ||
| build-web.sh | ||
| Caddyfile | ||
| Cargo.lock | ||
| Cargo.toml | ||
| DEPLOY.md | ||
| docker-compose.prod.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| run.sh | ||