Commit graph

10 commits

Author SHA1 Message Date
Maximus Gorog
8aafc7a939 Add ARCHITECTURE.md mapping the functional-core/imperative-shell split
Documents every module's responsibility, the tick pipeline, the
sim::lighting shared-truth invariant (sun direction shared between
Rust and WGSL via shader_source.rs), and the test coverage. Companion
to DEPLOY.md — that one covers ops, this one covers code.
2026-05-23 23:33:02 -06:00
Maximus Gorog
55276b7ce0 Phase 4: split state.rs → bridges.rs + app.rs
state.rs is gone. Its content split by responsibility:

  src/bridges.rs (~290 lines)
    The only place we own shared mutable state. Holds the four
    thread_locals (touch input, game status, network, settings) and
    the wasm-bindgen JS interface that mutates them. Exposes a typed
    accessor API — current_settings(), snapshot_touch_bridge(),
    with_touch_bridge(f), is_touch_mode(), clear_touch_inputs(),
    take_respawn_request(), set_status(hp, alive), take_inbox(),
    push_outbox(msg), with_net_bridge(f), net_connection_snapshot(),
    is_connected(), set_my_id(id), snapshot_remote_players(). Callers
    never touch the RefCells; if storage ever moves to a Mutex or
    OnceCell, only this file changes.

  src/app.rs (~510 lines)
    The App + winit ApplicationHandler + tick + drain_net_inbox +
    do_respawn + render_frame + FrameClock. Uses the bridges
    accessors instead of poking thread_locals directly, so the call
    sites read as a pipeline rather than a chain of `.with(|x|
    x.borrow_mut())`.

  src/lib.rs
    Modules now declared in alphabetical order:
      app, bridges, camera, mesh, net, proto, render,
      shader_source, sim, world.
    `run()` constructs `app::App::default()` instead of the old
    `state::App`.

  src/render/mod.rs
    `use crate::bridges::RemotePlayer` (was `crate::state::`).

Net effect of the four phases combined: state.rs at the start of
alpha-0.0.2 was 2500 lines doing everything; today the same logic
spans nine focused modules totalling ~3000 lines (with full doc
comments). 53 tests pass, native + wasm release build green, server
build green.
2026-05-23 23:27:03 -06:00
Maximus Gorog
549662ddc8 Phase 3: extract render/ module from state.rs
state.rs is now 870 lines (down from 1700+). All GPU code moved to a
dedicated render/ module.

New src/render/:
  mod.rs           Renderer struct + impl with all methods; the only
                   place that owns wgpu device/surface/pipelines. The
                   wasm-only WebGPU probe + compat-error overlay live
                   here as a private wasm_compat sub-module.
  pipelines.rs     Pipeline factory functions: camera_bgl, post_bgl,
                   pipeline_layout, sky_pipeline, terrain_pipeline,
                   outline_pipeline, post_pipeline. Each takes
                   device + shader + format and returns a configured
                   wgpu::RenderPipeline — pure factories, no hidden
                   state.
  scene_target.rs  create_depth_view, create_scene_color_view,
                   create_post_bind_group — fresh-resource builders
                   called from Renderer::new and Renderer::resize.
  uniform.rs       CameraUniform (matches WGSL camera.frame layout),
                   OutlineVertex, ChunkBuffers.

state.rs:
  - drops ~760 lines of pipeline + scene-target plumbing
  - imports Renderer from crate::render
  - keeps App + tick + drain_net_inbox + thread_locals + wasm_api

Tests: 53/53 pass. Native + wasm release build clean.
2026-05-23 23:21:47 -06:00
Maximus Gorog
accbf67bf2 Phase 2: shader decomposition + Rust-shared constants
shader.wgsl restructured:
  - Section headers: Camera → Sky horizon → Atmosphere extras → Terrain
    lighting decomposition → Pipelines.
  - sky_dome() is now the single source of truth for the horizon→zenith
    mix; sky_color() builds on it instead of duplicating the gradient.
  - fs_main decomposed into named helpers:
      ambient_term(n, sun, day)    hemisphere ambient via sky_dome lookup
      direct_sun_term(n, sun)      Lambert × visibility ramp
      leaf_jitter(world_pos)       per-pixel canopy variation
      fog_factor(dist)             0..1 fog ramp
      apply_fog(lit, dist, view)   defers sky_color call until needed
  - Camera.misc renamed to Camera.frame with named accessors
    scene_time() / eye_world() so callsites read intent.
  - DAY_PERIOD / SUN_OFFSET REMOVED from the shader — injected at the
    top by shader_source::wgsl_constants_header(). One source of truth
    in sim::lighting now drives both Rust and WGSL; mob burn and
    visible sun direction can never disagree.

New src/shader_source.rs:
  - wgsl_constants_header()  Rust → WGSL constants prelude
  - terrain_shader_source()  header + shader.wgsl, used at Renderer::new
  - post_shader_source()     pass-through

state.rs CameraUniform:
  - misc → frame to match the renamed WGSL field
  - Renderer uses the assembled shader source instead of include_str! directly

Tests: 53 passing (added 2 shader_source assembly tests). Native build,
wasm release build, server build all green.
2026-05-23 23:15:25 -06:00
Maximus Gorog
989de4f43d Phase 1: sim/lighting + sim/visibility + mesh utilities
New modules:
  src/sim/lighting.rs   - DAY_PERIOD, SUN_OFFSET constants; sun_direction,
                          day_strength, twilight_amount, LightingFrame::at;
                          is_in_direct_sun(world, p, t) via 3D DDA — the
                          mechanical sunlight predicate that future mob
                          burn / plant growth / shade pathfinding will all
                          consume. Mirrors the shader's sun math exactly
                          (Phase 2 will wire the WGSL side to consume the
                          same constants from this module).
  src/sim/visibility.rs - compute_visible_chunks moved out of state.rs;
                          frustum_planes + chunk_in_frustum decomposed.

Moves into mesh.rs:
  emit_oriented_box, name_hash + their tests. These are mesh utilities
  (Vertex output, color hash for remote-player boxes), not GPU shell.

state.rs:
  - drops the moved functions
  - imports compute_visible_chunks / emit_oriented_box / name_hash from
    their new homes
  - 230 lines lighter

Tests: 51 passing (up from 45). New coverage: sun-below-horizon=>night,
open-sky-at-noon-is-lit, occluded-by-overhead-block, ramp shapes match
the WGSL smoothstep, name_hash determinism.
2026-05-23 23:12:01 -06:00
Maximus Gorog
c6f50bcb50 DEPLOY.md: add active-deployment runbook for voxel.mxvs.art
Records the live production state (Linode IP, paths, redeploy command,
firewall + fail2ban + SSH hardening, TLS via Caddy, DNS via Namecheap
Advanced DNS, rollback steps, troubleshooting checklist) so a fresh
session can pick this up without re-deriving any of it.
2026-05-23 22:52:43 -06:00
Maximus Gorog
e4cf5a9bed Refactor: extract functional core into sim/ and net/
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.
2026-05-23 18:55:05 -06:00
Maximus Gorog
f239a939ce Add Docker + Caddy deploy for voxel.mxvs.art
Multi-stage Dockerfile compiles wasm client + axum server in one Rust
builder and copies into a debian:bookworm-slim runtime (non-root uid).
docker-compose.yml binds localhost:8080 by default; docker-compose.prod.yml
replaces ports with a Caddy reverse proxy on host 80/443 that talks to
the voxel container over the internal network. Caddy auto-issues Let's
Encrypt certs.

DEPLOY.md covers the three deployment modes (local-only, VPS with
Cloudflare or Caddy, Cloudflare Tunnel from a workstation).
2026-05-23 18:45:05 -06:00
Maximus Gorog
b52c1927cf Render + UI polish since pre-alpha-0.0.1
- Greedy meshing now bakes per-vertex AO with 4-corner sampling and an
  anisotropic-diagonal split when corner AO disagrees.
- WGSL: extracted sky_dome() for hemisphere ambient sampling so vertical
  faces match the sun-side sky tint at day; ambient_strength mixed by
  day strength instead of a flat constant.
- Step-1 post pipeline: render scene into an offscreen color texture,
  pass-through to the surface. Foundation for FXAA/shafts that will
  follow.
- Input bug: merge_held() now recomputes per tick from sticky keyboard +
  live touch bridge, so releasing the joystick actually stops the
  player (previous OR-into-self bug ate playtests).
- Touch UI hit-zones reordered (menu/hotbar above the joystick z-index);
  hotbar widened to 10 slots with tap-to-select on mobile.
- find_safe_spawn anchors on natural_surface_y so spawn is deterministic
  from noise — towers built at spawn no longer climb the spawn point.
- move_axis is sub-stepped (0.45-block max) so high-velocity falls can't
  teleport the player inside terrain.
2026-05-23 18:44:56 -06:00
Maximus Gorog
3a4ae970b2 pre-alpha 0.0.1 — initial multiplayer voxel sandbox
Web/wasm Rust voxel game with:
- wgpu 23 client (WebGPU when available, WebGL2 fallback)
- Chunked terrain (17x17 chunks, deterministic value-noise generator)
- Greedy meshing with frustum + distance culling
- Sky shader, leaf wind shader, distance fog
- Player physics: substepped AABB collision, gravity, fall damage,
  natural-surface respawn
- Touch UI (MCPE-style joystick + jump/break/place/sprint),
  gamepad polling with axis calibration, mouse+keyboard
- HP / death-screen / respawn flow
- 10-slot hotbar with mouse-wheel + hotkey + tap cycling
- Settings menu (mouse sens, FOV, render distance, input mode toggle)
- Axum multiplayer server: WebSocket protocol, edit log,
  10Hz player broadcasts
- 31 unit tests covering spawn invariants, collision sweeps,
  raycast hit/miss, greedy mesh winding, fall damage, oriented
  box rotation, hotbar block roundtrip, and the input-merge
  regression that latched movement after touch release

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 23:33:47 -06:00