Commit Graph
17 Commits
Author SHA1 Message Date
Emil a16645d2d8 feat: procedurally scalable UI — font_scale auto-computed from screen size
- UiLayer.font_scale: dynamically computed as (ui_height / 200).clamp(2, 6)
  Larger screens get bigger UI text automatically
- draw_text: renders each font pixel as font_scale×font_scale block
  (was 1×1, now 2×2 to 6×6 depending on screen size)
- text_width: now instance method, returns scaled width
- draw_health_bar: bar width scales with font_scale
- draw_character_panel: panel dimensions and row spacing scale
- draw_hud: bar height, row spacing, bar width scale
- draw_inventory_overlay: slot sizes scale with font_scale
- draw_messages: line spacing scales with font_height
- draw_death_screen: centered text uses scaled text_width
- All 185 tests + 14 scenarios pass
- Benchmark: 61.9 FPS (was 82.7 — 25% regression from more set_alpha calls)
2026-06-22 13:23:48 +03:00
Emil f35f56b970 perf: CA optimization — 18 FPS → 83 FPS (4.6× speedup) with ×5 world scale
- Cache active_chunks(): one allocation instead of 5 per tick
- heat_transfer/gas_step/pressure_step: direct chunk array access
  (chunk.temps[idx], chunk.gas_*[idx], chunk.pressure[idx]) instead of
  grid.get_temp()/set_temp() (eliminates 5 chunk-lookups per cell)
- In-place updated_this_tick reset via get_chunk_mut (no Cell copy, no mark_dirty)
- light_step: gather sources first (one pass), skip if no sources,
  reduced radius (lava 25→12, fire 15→6), frequency 10→20 ticks
- gas_step: skip chunks with no gas (gas_density all 0)
- pressure_step: skip chunks with all atmospheric (128), add mark_dirty
- pre_dirty: HashMap instead of Vec (O(1) lookup vs O(n) linear search)
- Cross-chunk heat transfer: edge_temps pre-loaded before mutable borrow
- Spread chunk save I/O: 1 chunk/tick instead of all every 60 ticks
- All 185 tests + 14 scenarios pass
- Benchmark: 82.7 FPS avg, p99 86ms (was 18 FPS, p99 442ms)
2026-06-22 08:55:40 +03:00
Emil 24b6d0320f feat: multi-layer world — temperature, gas, pressure, light as parallel per-chunk arrays
- Removed temp from Cell (13→9 bytes), added temps/pressure/gas_type/gas_density/light arrays to Chunk
- Layer access via grid.get_temp()/set_temp()/get_gas()/set_gas()/get_pressure()/set_pressure()/get_light()/set_light()
- cells_swap swaps all layers, set_material sets default_temp
- heat_transfer refactored to direct array access on temps[] (no Cell copy)
- CA rules refactored: cell.temp → grid.get_temp()/set_temp()
- gas_step: gas flow (rise, spread), fire produces CO2+smoke, steam condenses to water, acid+organic→poison gas
- pressure_step: pressure equalization for connected non-solid cells
- light_step: world-space persistent lighting, updated every 10 ticks, ray-cast line-of-sight
- Gas damage: poison gas damages entities, CO2 suffocates, applied before ca.step()
- Multi-section chunk serialization (VWM1 magic + cells + temps + gas + pressure + light)
- Old 12-byte chunk format auto-detected for backward compat
- AI spectrum: new gas + pressure spectrums, light spectrum uses world-space fallback
- Protocol: gas/pressure spectrum commands
- pre_dirty mechanism: layer steps process pre-clear dirty rects for cross-cell diffusion
- 14 new multilayer tests, all 185 tests + 14 scenarios pass
- Benchmark: 85.9 FPS (graphics surface, was 128 pre-layers — 33% regression from 4 new layer steps)
2026-06-21 23:38:33 +03:00
Emil a5436897ed wip: current project state 2026-06-21 22:27:20 +03:00
Emil 88892db493 fix: bigger UI panels with more spacing between text lines
Character panel:
- Width 44 -> 52, height 44 -> 62
- Text rows spaced 8 apart (was 6) — no more squished text
- HP/XP bars 38 wide (was 32)
- Stats with double space between pairs
- Inventory section at bottom with more room

HUD bar:
- Height 18 -> 28
- Rows at y_top+2, +12, +22 (was +1, +7, +13)

Inventory overlay:
- Slots 12x10 (was 8x6), gap 3 (was 2)
- Panel auto-sizes larger
- Click hitboxes in main.rs updated to match

Fixed depth_shown_in_hud test for new HUD height.

All 171 tests + 14 scenarios pass.
2026-06-21 19:03:14 +03:00
Emil 357db17c2f feat: GPU optimization — lighting, viewport CA, benchmark mode, 531 FPS
- Resolution: 8x8 world cells, 2x2 UI cells (UI_SCALE=4)
- GPU lighting: vertex-shader computed, light source list buffer (max 64)
  instead of O(N×R²) grid scan, O(N×S) per cell
- Viewport-aware CA: iterate only active chunks, not all 250×250
- Flat array entity/item/shadow maps instead of HashMaps
- Flat 128-entry ASCII atlas array instead of HashMap lookup
- Partial grid upload: viewport + 30-cell margin only
- Pre-allocated viewport arrays in renderer structs (zero alloc/frame)
- Skip CPU lighting for GPU modes (pass None)
- Benchmark mode: --mode benchmark with per-subsystem timing
- GpuLightSource struct, light_count in push constants
- gather_sources_in_range() for viewport-scoped source gathering

Benchmark (600 ticks, release):
  Graphics: 531 FPS (was 386, +38%), render 1013us (was 1699us, -40%)
  ASCII:    402 FPS (was 313, +28%), render 1502us (was 2346us, -36%)

All 171 tests + 14 scenarios pass.
2026-06-21 16:09:45 +03:00
Emil 2078e3f11e feat: slime enemies — jump AI, contact damage, combat system
New entity: Slime (EntityKind::Slime)
- 19 parts: blobby body (3x5) + 2 glowing eyes
- Green translucent colors, brighter center
- HP: 25, spawns every 45 ticks (max 2 alive)

Slime AI (update_slime_ai):
- Jumps toward player every 60 ticks when within 40 cells
- Jump power scales with proximity (closer = stronger)
- Pauses horizontally between jumps (50/50 hop-stop cycle)
- Uses set_horizontal_vel + set_vertical_vel (vector movement)

Combat system (update_combat):
- AABB overlap check between player and all alive enemies
- Goblin: 8 damage per 20 ticks on contact
- Slime: 5 damage per 20 ticks on contact
- Knockback: player pushed away from enemy on hit
- Player.take_damage() called, death possible from enemies

World gen: try_spawn_slime() spawns at surface, 18 cells from player
Renderers: slime rendered as 's' in ascii/terminal, green blob in graphics

6 new tests (122 total, 0 failures)
2026-06-21 10:42:16 +03:00
Emil e287b0d22a feat: larger detailed entities — 47 parts, hats, belts, ears
Entities are now ~3x larger and more detailed:

Player (47 parts, was 15):
  - Hat: 3 top + 2 brim (dark purple)
  - Head: 3x2 face (lavender skin)
  - Belt: golden accent across torso
  - Shirt: 3x2 torso + arms out to 3 cells each side
  - Hands: 4 cells (2 per arm, pale lavender)
  - Pants: 3 wide hips + 5 wide legs + split
  - Boots: 3 cells + 2 foot tips (dark purple)
  - half_w=4, half_h=6 (was 2.5x3.5)

Goblin (41 parts):
  - Pointed ears (2 cells)
  - Ragged shirt (green, darker shade)
  - Bare feet (green skin, no boots)
  - Loincloth (dark green)

Auto-constraints: all parts connected to all others (n^2)
  - Simplified from manual constraint lists
  - Works for any template shape
  - Ragdoll will look natural — all parts hold together

macro_rules! p! for compact part definitions
117 tests, 0 failures
2026-06-21 10:34:28 +03:00
Emil 61bf21bda0 feat: BodyTemplate system — data-driven entity editor for AI
BodyTemplate: JSON-serializable entity body definition.
- parts: Vec<BodyPart> with x, y, color, label
- constraints: Vec<(usize, usize)> connecting parts
- half_w/half_h/radius: collider and physics params

Built-in templates:
- humanoid_player: purple wizard (15 parts)
- humanoid_goblin: green (15 parts)
- boulder: 4x4 rock (16 parts)

API for AI agents:
- BodyTemplate::to_json() / from_json() — serialize/deserialize
- BodyTemplate::preview_ascii() — text preview of silhouette
- BodyTemplate::apply_to(&mut entity, cx, cy) — build entity from template
- template_for_kind(EntityKind) — get template by entity type
- Custom templates: create any shape (snake, dragon, boss) from code or JSON

Entity::build_humanoid() now delegates to template_for_kind().apply_to()
— single source of truth for body layout.

7 new tests for template system (116 total, 0 failures)
2026-06-21 10:27:37 +03:00
Emil 6504a619f6 feat: profile-view humanoid entities, purple player in clothes
Redesigned entity as side-profile silhouette (Noita-style):

     O          head (skin tone)
     |
    -|-         shoulders with arms out
     |
    -|-         arms lower
     |
    /|\         hips, legs split
    /|    boot boot boot

15 bodies (was 23), narrower profile shape:
  - head: 2 cells (skin)
  - torso: 3 cells (shirt/clothing color)
  - arms: 4 cells (hands, 2 per side)
  - hips: 1 cell (pants)
  - legs: 3 cells (pants)
  - boots: 3 cells

Player color scheme (purple wizard):
  - skin: pale lavender (220,200,240)
  - shirt: purple (140,80,200)
  - pants: dark purple (90,50,150)
  - boots: dark (60,35,100)
  - hands: pale lavender (210,185,235)

Goblin: green skin, dark green rags
Corpse: desaturated grey-brown

109 tests, 0 failures
2026-06-21 10:20:09 +03:00
Emil 5cd1a5e197 feat: Noita-style humanoid entities with per-part colors
Redesigned entity from solid 5x5 block to humanoid silhouette:

Shape (23 bodies, was 27):
     H H H        (head, 3 wide)
     H H H
   A T T T A      (shoulders + arms, 5 wide)
   A T T T A
     T T T        (torso, 3 wide)
     L   R        (legs, split with gap)
     L   R

Per-part colors (Noita-inspired):
- Player: head=bright yellow, torso=golden, arms=amber, legs=dark gold
- Goblin: head=bright green, torso=green, arms=olive, legs=dark green
- Corpse: desaturated browns

SubBody now has color: [u8; 4] field, set by build_humanoid.
All renderers (terminal, ascii, graphics) use b.color directly.
Fire effect: flickering orange overlay on burning entities.

half_w adjusted from 3.5 to 3.0, half_h from 2.5 to 3.5
(taller shape, narrower than old block).

109 tests, 0 failures
2026-06-21 10:13:22 +03:00
Emil 68fe0b87dd refactor: code cleanup — dead code, warnings, duplication
Dead code removed (21 methods, 4 fields, 3 constants):
- Cell: MaterialId::ALL, MaterialId::from_u8 (unsafe transmute)
- Grid: get_mut, clear, fill_rect, swap, dump_region, next buffer field
- Entity: move_center, EntityManager::iter_mut
- Player: move_dir field, entity_mut
- VerletSolver: step, SubBody::add_vel, SubBody::apply_force
- CellularAutomaton: tick_count
- InputHandler: release_all, poll, Action::None
- WindowInput: clear
- GameSession: perform_action_and_step, is_recording, grid_mut
- ReplayPlayer: from_recording
- Material: empty()
- VulkanRenderer: tick_count field
- MaterialBrush: name()

Warnings fixed:
- Remove unused MaterialRegistry imports from renderers
- Remove unused reg variables in terminal/vulkan/graphics
- Remove unused water_surface in game.rs
- Remove unused p/y_death in tests
- Remove unused qf_slice in graphics.rs

Duplication eliminated:
- main.rs: run_ascii_mode + run_graphics_mode → generic run_gpu_mode<R: GpuRenderer>
  ~140 lines of duplicated event loop code removed
- GpuRenderer trait unifies VulkanRenderer and GraphicsRenderer API

Unsafe code fixed:
- rand_u8: static mut + unsafe → AtomicU8 + fetch_add (thread-safe)

Module cleanup:
- world/mod.rs: removed all unused re-exports
- physics/mod.rs: removed all unused re-exports
- entity/mod.rs: removed unused Entity/EntityId re-exports

Result: ~6500 → ~5964 lines, 0 non-deprecation warnings, 109 tests pass
2026-06-21 01:36:25 +03:00
Emil 61b5d551ae test: 109 Rust tests + 14 JSON scenarios, polish physics
Tests added:
- physics_materials.rs: 15 tests (fire, smoke, steam, grass, dirt, bone, wood, stone, lava temp)
- physics_interactions.rs: 12 tests (lava+water, fire spread, acid interactions, sand+water)
- player_controls.rs: 12 tests (move L/R, jump, double jump, rapid input, wait, continuous)
- collision_robust.rs: 10 tests (walls, ceiling, sliding, corridor, slope, dirt wall, unstick)
- ragdoll_death.rs: 7 tests (death transition, ragdoll fall, progressive damage, corpse)
- determinism.rs: 8 tests (same seed, replay exact, replay partial, recording, 100-tick)
- edge_cases.rs: 19 tests (boundary, stress 20 goblins, fill/clear/paint, gravity, camera)
- 6 new JSON scenarios (fire chain, lava pool, sand bury, entity fall, steam, acid wall)

Fixes:
- AABB resolve_aabb_y: add vertical overlap check (was pushing player down when jumping)
- AABB resolve_aabb_x: velocity-aware resolution (player was stuck against walls)
- check_on_ground: use fractional position check (was always true)
- jump_force 1.5 (was 0.8) for 27-body entity
- Gravity read from self.verlet (was from clone, SetGravity didn't work)
- u8 overflow in lava color (saturating_add)

109 Rust tests, 14 JSON scenarios, 0 warnings, 0 failures
2026-06-20 22:42:29 +03:00
Emil a66b4ac0cb fix: AABB capsule collider for rigid entities, sliding on surfaces
- Replace per-body collision with single AABB collider for rigid entities
- Entity has half_w/half_h defining the collider box
- Separate axis resolution: X first (min-penetration push), then Y
  (velocity-direction push to handle floor/ceiling correctly)
- Sliding: when hitting a wall, only X velocity is zeroed, Y continues
- check_on_ground uses AABB bottom edge, not individual bodies
- Fix: X resolution uses minimum penetration (was velocity-based,
  which pushed player through walls when velocity was zero)
- Default scene: added water pool, lava pool, wood structure, sand dune,
  acid pool, stone wall obstacle
- 28/28 tests passing
2026-06-20 21:56:13 +03:00
Emil e96744b958 feat: rigid living entities, ragdoll corpses, fix WASD movement
- Entity: rigid body mode for alive entities (single object, no wobble)
  - Center position + velocity, bodies positioned from rest offsets
  - Collision: all 16 bodies checked, push applied to center
  - Movement: velocity applied to center, all bodies move together
- Entity: ragdoll mode for corpses (loose Verlet constraints)
  - kill() switches rigid->ragdoll, gives each body inherited velocity
  - Constraints go slack (stiffness=0), bodies fall independently
- Player: move_left/right now applies velocity to entity center (was: head only)
- Physics: lava heat conductivity 0.05 (was 0.5), initial temp 1500 (was 1200)
  Lava cooling threshold 400 (was 800), heat transfer rate 0.1 (was 0.5)
  Lava stays hot long enough for entities to take damage
- Tests: 28/28 passing, updated for new lava and rigid body behavior
2026-06-20 21:39:26 +03:00
Emil 9fe7137e45 feat: bigger characters (16 sub-bodies), wider terminal viewport
- Entity: 16 sub-bodies (was 7), radius 0.7 (was 0.4), full humanoid
  shape: head, shoulders, torso, arms, hips, legs, feet
- Terminal: viewport up to 250x80 (was 120x50), uses full terminal size
- Camera: uses renderer viewport dimensions instead of hardcoded values
- Physics: constraint correction clamped to 0.5 cells max, 8 substeps
  (was 4), gravity 0.04 (was 0.08), collision pass after each constraint
  iteration to prevent tunneling with larger bodies
- Player: move_speed 0.3, jump_force 1.2 for bigger body
- Spawn: 6 cells above surface (was 4) for taller body
2026-06-20 21:27:11 +03:00
Emil 7f4b1dde5e feat: AI integration - pipe protocol, test framework, replay system
AI Session API (src/ai/session.rs):
- GameSession wraps Game with seeded determinism
- init/init_empty, step(n), perform_action, get_state
- get_cell, get_region, get_entities, get_player, count_material

JSON Pipe Protocol (src/ai/protocol.rs):
- --mode pipe: stdin/stdout JSON line protocol
- Commands: init, step, action, get_state, get_view, get_cell,
  get_region, get_entities, get_player, count_material, find_material,
  record_start/stop, replay_save, run_scenario, quit

Test Framework:
- 27 Rust integration tests (tests/*.rs) covering sand, water, lava,
  acid, fire physics + entity movement, damage, ragdoll
- 8 JSON scenarios (scenarios/*.json) runnable via --mode test
- Scenario assertions: cell_is, cell_is_not, no_material_in_region,
  material_count_in_region, entity_alive/dead, player_on_ground, etc.

Replay System (src/ai/replay.rs):
- Record all actions + seed for deterministic playback
- ReplayPlayer::play() and play_until_tick() for debugging
- --mode replay --replay-file PATH

Other changes:
- src/lib.rs: library target for integration tests
- Collision: post-constraint collision pass to reduce tunneling
- serde + serde_json dependencies
- All enums use rename_all = snake_case for JSON compatibility
2026-06-20 18:53:21 +03:00