Commit Graph
18 Commits
Author SHA1 Message Date
Emil d889e24cf6 feat: store color directly in Cell (reality layer)
Each cell now stores its own fg/bg color inline, instead of looking
up from MaterialRegistry every frame.

Cell struct:
- fg: [u8; 3] — foreground color (for rendering)
- bg: [u8; 3] — background color (for rendering)
- temp: f32 — temperature (already there)
- material: MaterialId — for physics property lookup
- variant: u8 — visual/behavioral variant
- updated_this_tick: bool — CA flag

Colors are copied from MaterialRegistry at Cell::new() time.
This allows per-cell color variation in the future (water depth
shading, lava gradient, damaged materials, etc.) without registry
changes.

MaterialRegistry still stores physics properties (density, solid,
liquid, flammable, etc.) — looked up only during CA/physics steps,
not during rendering.

Renderers (terminal, ascii, graphics) updated to use cell.fg/cell.bg
directly — no more registry lookup in render path.

Cell size: ~16 bytes (was ~12). 250x250 grid = 1MB (was 750KB).
126 tests, 0 failures
2026-06-21 01:21:38 +03:00
Emil 2eb9de6502 fix: use window inner_size() for resize on Wayland
Wayland surface always reports current_extent as 0xFFFFFFFF (undefined),
meaning the swapchain size is determined by the application, not the
surface. Previous code returned early when this happened, so resize
never worked — cells stretched to fill the window.

Fix: when current_extent is 0xFFFFFFFF, use winit's window.inner_size()
to get the actual pixel dimensions. This works on both X11 and Wayland.

Both renderers (ascii + graphics) updated.
109 tests, 0 failures
2026-06-21 01:17:32 +03:00
Emil 57a88fd41e feat: adaptive viewport — window resize expands camera, no stretching
Both renderers (ascii + graphics) now support dynamic window resize:

- check_resize() called at start of every render() frame
- Compares surface capabilities with current swapchain extent
- If changed: recreates swapchain, image views, framebuffers, command buffers
- Recalculates grid_w/grid_h from new extent / cell_size (16x16)
- Reallocates instance buffer if grid cell count changed
- Old swapchain properly destroyed after new one created
- Handles window minimize (skip if extent = 0)
- physical_device field added back to both renderers (needed for surface caps query)

main.rs: vw/vh queried every frame from renderer.grid_w()/grid_h()
instead of cached once at startup. Camera center uses dynamic dimensions.

Result: resize window → more/fewer cells visible, cells stay 16x16 pixels.
109 tests, 0 failures
2026-06-21 01:13:34 +03:00
Emil 3235957a26 feat: square cells (16x16), slope stepping collision
Square cells:
- CHAR_W and CHAR_H both 16 (was 8x16, non-square)
- Window size updated to 160*16 x 50*16 = 2560x800
- Applies to both ascii and graphics renderers

Slope stepping collision:
- Before resolving X, check if new position overlaps solid
- If overlap, try stepping up 1 cell — if clear, snap up (walk up slope)
- If can't step up, resolve X normally (wall block)
- aabb_overlaps_solid() helper for fast overlap check
- Player can now walk up 1-cell-high steps and slopes

109 tests, 0 failures
2026-06-21 01:06:37 +03:00
Emil 45d2767719 fix: clean up dead code warnings in vulkan.rs
Remove unused fields from VulkanRenderer: pixel_w, pixel_h,
physical_device, queue_family, swapchain_format. Mark unused
device param in create_swapchain as _device.

Only winit deprecation warnings remain (create_window, run).
2026-06-21 01:02:20 +03:00
Emil 019ae8f090 feat: three render modes — terminal, ascii, graphics
Three render modes:
- --mode terminal: pure ANSI ASCII in terminal
- --mode ascii: Vulkan window with ASCII characters (glyph atlas)
- --mode graphics: Vulkan window with colored cells (no glyphs, each
  material = unique base color, no lighting yet)

Graphics renderer:
- Same Vulkan pipeline as ASCII but without glyph atlas
- Simpler shaders: graphics.vert/frag just output instance color
- No descriptor set, no texture sampling
- Each cell = colored quad, material color fills entire cell
- Entities rendered as colored shapes (player=yellow, goblin=green)

Default mode changed to --mode ascii
109 tests, 0 failures
2026-06-21 00:59:19 +03:00
Emil 020914ab99 refactor: --mode window is now Vulkan, remove softbuffer fallback
- --mode window = Vulkan renderer (was softbuffer CPU)
- --mode vulkan removed (merged into --mode window)
- softbuffer dependency removed
- log dependency removed (unused)
- Old window.rs (softbuffer CPU renderer) deleted
- Fallback: if Vulkan init fails, falls back to --mode terminal
- 109 tests, 0 failures
2026-06-21 00:53:20 +03:00
Emil fdc1f416c7 fix: platform-agnostic Vulkan instance extensions
Use ash_window::enumerate_required_extensions() instead of hardcoded
VK_KHR_xlib_surface / VK_KHR_wayland_surface. This automatically
selects the correct surface extension per platform:
- Linux X11: VK_KHR_xlib_surface
- Linux Wayland: VK_KHR_wayland_surface
- Windows: VK_KHR_win32_surface
- macOS: VK_EXT_metal_surface (via MoltenVK)

No platform-specific code in the renderer — fully cross-platform.

109 tests, 0 failures
2026-06-21 00:43:26 +03:00
Emil 139b60b8af fix: flip Y in vertex shader, dynamic viewport/scissor, clean debug
- Fix: Y coordinate was inverted (1.0 - 2.0*y → 2.0*y - 1.0)
  Vulkan clip space Y is already down-up, no need to flip
- Fix: dynamic viewport/scissor with viewport_count(1) + scissor_count(1)
  Required by validation layer even with dynamic state
- Clean: removed debug eprintlns, restored default clear color
- Shaders recompiled to SPIR-V
2026-06-21 00:41:34 +03:00
Emil 6e9e90fb34 feat: Vulkan renderer with instanced rendering (Phase 4)
VulkanRenderer using ash 0.38 + winit:
- Instance with KHR_surface + xlib + wayland extensions
- Physical device selection (first GPU with graphics+present)
- Swapchain (FIFO present mode, B8G8R8A8_UNORM)
- Render pass with color attachment
- Graphics pipeline with instanced rendering:
  - Vertex buffer: unit quad (4 verts, 6 indices)
  - Instance buffer: 8000 CellInstance structs (32 bytes each)
  - 2 vertex bindings: per-vertex (quad pos) + per-instance (grid pos,
    atlas UV, fg/bg colors)
  - Push constants: screen size + cell size
- Glyph atlas: R8_UNORM texture, uploaded via staging buffer
  - fontdue rasterizes DejaVu Sans Mono at startup
  - Linear filtering sampler
- Descriptor set: combined image sampler for atlas
- 2 frames in flight with semaphores + fences
- Persistent mapped instance buffer (zero-copy per frame)

Shaders (pre-compiled SPIR-V):
- cell.vert: positions quad from instance data, maps to clip space
- cell.frag: samples atlas alpha, blends fg/bg

--mode vulkan: tries Vulkan, falls back to softbuffer window mode
109 tests, 0 failures
2026-06-21 00:34:01 +03:00
Emil 390eca9cda fix: winit + softbuffer for layout-agnostic input and better FPS
Replaced minifb with winit + softbuffer:

Input (layout-agnostic):
- winit uses PhysicalKey<KeyCode> which maps to physical key positions
- KeyCode::KeyA = physical A key, regardless of keyboard layout
- Works on Russian, Arabic, any layout — no key mapping needed
- HashSet<KeyCode> tracks pressed/released state
- Proper Press/Release events from OS, no timeout hacks

FPS improvements:
- Glyph atlas pre-built at startup (alpha bitmap, zero per-frame alloc)
- render_to_buffer: skip empty cells entirely (no draw call)
- blend_fast: bitshift instead of division for alpha blending
- Buffer fill via .fill() instead of nested loop
- copy_from_slice for pixel transfer to softbuffer (memcpy speed)
- ControlFlow::Poll for maximum frame rate

109 tests, 0 failures
2026-06-21 00:11:12 +03:00
Emil 65752b4cfe fix: window input uses get_keys() for held state, glyph atlas for FPS
Input fix: get_keys_pressed(No) only fires on initial press, not held.
Switched to get_keys() which returns all currently-down keys every frame.
Jump still edge-triggered via jump_was_down flag.

Performance fix: pre-build glyph atlas at startup (all ASCII chars
rasterized once into 128x256 alpha bitmap). No per-frame cloning.
draw_cell reads atlas alpha + blends fg/bg inline. Zero allocations
in render loop.

109 tests, 0 warnings
2026-06-21 00:01:28 +03:00
Emil 19bd883645 feat: window mode with minifb — direct keyboard polling, no terminal
New --mode window (now default):
- minifb creates a real OS window (no terminal needed)
- fontdue rasterizes DejaVu Sans Mono glyphs to pixel buffer
- ASCII characters rendered as colored pixels — same aesthetic
- Keyboard polled via get_pressed_keys() every frame:
  - Instant response, no terminal delay
  - Proper multi-key support (W+A strafing works)
  - No Release event hacks needed
  - No key repeat timeout hacks
  - Instant stop when key released

Controls: WASD/arrows, 1-9/0 paint, X erase, HJKL camera, Q/Esc quit
--mode terminal still available as fallback

109 tests, 0 warnings, 0 failures
2026-06-20 23:58:05 +03:00
Emil 6d98c09ece fix: request keyboard enhancement flags for proper Release events
Root cause of both issues: terminals don't send Release events by
default. When pressing W while holding A, terminal stops repeating A
(but doesn't send Release), so A times out and strafing breaks.
On key release, 400ms timeout means 400ms of extra movement.

Fix: PushKeyboardEnhancementFlags(REPORT_EVENT_TYPES) in terminal init.
This asks the terminal to send proper Press/Release/Repeat events for
ALL keys, not just special ones.

With Release events:
- Key release is instant (no 400ms timeout delay)
- Pressing W doesn't cancel A's held state (terminal sends Release
  only when A is actually released)
- A/D strafing works while W is held

Fallback: if terminal doesn't support enhancement flags (old xterm),
got_release flag stays false and 150ms timeout is used. Once any
Release event is received, all keys switch to Release-based mode
(infinite timeout, rely on actual Release events).

109 tests, 0 warnings, 0 failures
2026-06-20 23:48:03 +03:00
Emil 8b1f5d4768 fix: u8 overflow in lava color calculation (saturating_add) 2026-06-20 22:14:26 +03:00
Emil a731d5cbb7 feat: 5x5 entity (27 bodies), terminal viewport up to 250x120
- Entity: 5x5 grid body + 2-cell arm = 27 sub-bodies, radius 0.5
- Terminal: default 200x60, max 250x120 (was 250x80)
- 31 constraints (full grid + arm)
- Spawn height adjusted for 5-tall body
2026-06-20 21:43:50 +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 68f6292c4d feat: Verbatim MVP - terminal renderer, cellular automaton, Verlet physics
- World: 250x250 grid with 14 materials (sand, water, lava, stone, wood, etc.)
- Physics: cellular automaton for materials + Verlet solver for entities
- Entity: multi-cell humanoid (7 sub-bodies with distance constraints)
- Render: terminal renderer with ANSI colors and diff-based updates
- Game loop: fixed 60Hz timestep with accumulator pattern
- Input: WASD movement, number keys for material painting
2026-06-20 18:21:26 +03:00