Commit Graph
203 Commits
Author SHA1 Message Date
popertots b7b7af5560 inventory: linter fixes - saturating_add, SmallVec<4>, new_default, drop PIG_SLOTS 2026-03-21 21:39:52 +00:00
popertots 2f9360c8bc inv update 2026-03-21 21:27:26 +00:00
popertots 40b5d8ce95 Fix forrestry 2026-03-21 19:20:57 +00:00
popertots 1ddcb538df tree felling optimisations 2026-03-21 19:14:14 +00:00
popertots 4fc4843ed7 fix 2026-03-21 19:10:04 +00:00
popertots 03c3e5d6d7 first pass at tree interaction 2026-03-21 18:57:15 +00:00
popertots cabe944f1b use constants better 2026-03-21 17:51:05 +00:00
popertots f96c71b61b docs: update README architecture diagram with magic_numbers locations 2026-03-21 17:31:57 +00:00
popertots 7fe33d4b2d refactor: split magic_numbers into per-module files
Extracted all doc-commented magic numbers into module-local magic_numbers.rs
files, co-located with the module that owns them. No logic changes.

- entities/shared_systems/magic_numbers: pathfinding + dig constants
- world/generation/terrain/magic_numbers: terrain + cave constants
- world/generation/forestry/magic_numbers: tree constants
- world/tiles/magic_numbers: A*, benchmark, memory constants
- entities/item/magic_numbers: item sprite z-offset
- Removed src/magic_numbers.rs (central file deleted)

Constants imported as `crate::{module}::magic_numbers::*` from each
consumer. src/constants.rs retains only structural constants (PIXEL_RATIO,
TILE_SIZE, SEED, pathfinding tier thresholds).
2026-03-21 17:31:39 +00:00
popertots 776d3caefc fix: dig_rng sequential multiply-add mixing
Switch from add-then-XOR pattern to proper sequential multiply-add
avalanche. Each coordinate feeds into the next multiply, preventing
correlation between adjacent tiles when rare drops are introduced.
2026-03-21 17:10:52 +00:00
popertots 2622144cdf fixed typo 2026-03-21 17:09:32 +00:00
popertots 5b563bad67 perf: SmallVec inline storage, TOML drop tables, seeded deterministic RNG
- SmallVec<[DropEntry; 2]> replaces Vec in DropTable: zero heap allocation for
  all current tiles (0 or 1 entries), spills to heap only at 3+
- DropEntry fields packed to u8 (chance_pct, min_count, max_count): ~12 bytes ->
  4 bytes; derives Copy so no extra clones
- Replaced SystemTime pseudo-RNG with dig_rng(pos): PCG-style hash of world SEED
  + tile position. Deterministic per world, same dig = same roll every time
- TOML-driven drop tables: assets/drop_tables.toml (grass=5%/1-2, rock=10%/1,
  dirt/air=none). TOML parsed at startup into DropTableRegistry resource
- OnceLock global map for async terrain generation tasks to access drop tables
  without Bevy resource borrowing
- terrain.rs: DropTableRegistry::global_get("tile") replaces hardcoded drop_table_for
2026-03-21 16:06:41 +00:00
popertots f03651e0cf docs: update README for generic digging, drop tables, revised architecture
- Add generic digging + drop tables to implemented list
- Rabbit digging: now using Digger component, not debug code
- Building and construction: updated to reflect generic system in place
- Architecture: added digging to shared_systems, drop_table to tiles
2026-03-21 15:41:20 +00:00
popertots ce3746366c refactor: extract generic digging system, drop tables, remove debug code
- New src/entities/item/drop_table.rs: DropEntry (chance, min/max count,
  pseudo-RNG roll) + DropTable wrapper. grass=5% coin 1-2, rock=10% coin 1,
  dirt/air=none.
- New src/entities/shared_systems/digging.rs: Digger component + dig_system.
  Any entity with Digger digs the tile below on its interval. Replaces
  rabbit_dig_system/rabbit_fall_debug_system/RabbitDigTimer/RabbitFallDebug.
- New TileMap::dig_floor: remove_floor + insert air. Used by dig_system.
- FloorTileData: added drop_table field. Lost Copy derive (Vec field).
  Updated all 6 terrain.rs call sites with per-tile drop tables.
- Pig: removed PigDropTimer + pig_drop_system. Drops were debug placeholder.
  TODO added for future loot-on-death/butcher system.
- Rabbit: removed all debug components/systems. Now uses Digger::new(5.0).
- main.rs: removed rabbit_dig_system/rabbit_fall_debug_system/pig_drop_system,
  added shared_systems::digging::dig_system.
2026-03-21 15:40:34 +00:00
popertots 1a170ea9a9 docs: update README with collision, tile events, rabbit dig, visibility notes
- Add Stage 2 collision section documenting convoy / head-on / E/S yield / W/N right-of-way
- Add TileChangedEvent + path invalidation section
- Add Rabbit digging to implemented list
- Add visibility raycast note (absent tiles in loaded chunks = air)
- Remove stale warning count from build instructions
2026-03-21 15:23:11 +00:00
popertots 9d2f41faed fix: insert_floor syncs ChunkData, rabbit replaces dug tile with air
- TileMap::insert_floor now syncs ChunkData bits (set_floor_tile) so is_standable
  returns correct values for tiles inserted via insert_floor. Previously the
  HashMap was updated but ChunkData remained stale, causing is_standable to
  return false for valid tiles.
- rabbit_dig_system inserts air tile at the dug position after remove_floor.
  Without this, the HashMap entry is absent and ChunkData bits stay 0 (both
  false), making is_standable return false at that position. The entity then
  falls through multiple levels. Air's can_stand_in=true means the space is
  passable — the entity falls through it and lands on solid ground below.
2026-03-21 15:09:40 +00:00
popertots 2c92bdfe28 fix: remove_floor clears only stand_on_floor, not stand_in_floor
Clearing stand_in_floor when removing a floor tile made the dug position
impassable. An entity falling into the dug slot found (false || false) && true
= false and kept falling. Now only stand_on_floor is cleared — the space
reverts to air (passable), and only the tile above loses its platform.
2026-03-21 14:58:28 +00:00
popertots 89693f968c add debug 2026-03-21 14:50:31 +00:00
popertots ec5287ca86 fix: loaded-chunk guard in calculate_visibility, reset dig timer while airborne
- calculate_visibility: None from floor_tiles.get() now checks tilemap.chunks
  to confirm the neighbour's chunk is loaded before treating it as air.
  Without this, unloaded world borders and pending chunks were incorrectly
  seen as open space, causing underground tiles to render as black.
- rabbit_dig_system: skip and reset timer when entity is not on standable
  ground, preventing rapid-dig cascade as rabbit falls through multiple levels.
2026-03-21 14:25:28 +00:00
popertots 36f068bf0c fix: treat absent tiles as air in visibility, full-column occlusion refresh
- calculate_visibility: None from floor_tiles.get() now breaks touches_air=true.
  Absent tile = open space = air for visibility purposes. Previously, removed
  tiles left their below-neighbours with all-zero visible_range (black).
- rabbit_dig_system: fire TileOcclusionEvent for full Z_BELOW+1 level column
  below the dug tile + 8 XY neighbours each, not just 3x3x3. calculate_visibility
  traces up to Z_TOTAL+Z_BELOW+1 tiles above each tile, so removing one tile
  can expose visibility arbitrarily deep below.
2026-03-21 12:30:56 +00:00
popertots 0ebc48ff40 fix: snap-to-top for above-world spawn, guard rabbit dig at world floor
- Entities spawn at z=35*TILE=560 but Z_ABOVE max is 15*TILE=240. Snap to
  Z_ABOVE*TILE instead of falling one tile per tick through unloaded space.
- Skip rabbit dig when below_pos would be outside ChunkData z-bounds,
  preventing remove_floor assert panic.
2026-03-21 12:16:58 +00:00
popertots 4d702bc8f5 fix: rabbit dig occlusion refresh, bounds guard panic, world floor clamp
- Fire TileOcclusionEvent for 27-tile neighbourhood (3x3x3) so tiles above
  the dug tile recalculate visibility and stop rendering black
- Clamp gravity in movement to world minimum z — rabbits digging the
  floor below them now stop at world floor instead of falling past it
- Assert bounds in remove_floor/remove_fixture before pos_to_index to
  panic with z/coords info instead of silently overflowing
- Hoist ITILE_SIZE, CHUNK_SIZE, Z_BELOW, Z_ABOVE to module-level
  imports in tilemap.rs
2026-03-21 12:09:49 +00:00
popertots 5357a69930 feat: stage 2 collision, TileChangedEvent, path invalidation, rabbit digging
- Stage 2 collision: convoy skip when entities move same direction (dot>0.7),
  E/S yield rule for crossings, W/N right-of-way, head-on unchanged
- TileChangedEvent (Message) + PathfindingDirtyChunks (Resource) in new tile_changed module
- collect_pathfinding_dirty_chunks / invalidate_paths_on_tile_change /
  clear_pathfinding_dirty_chunks in PathfindingPlugin FixedUpdate chain
- TileMap::remove_floor clears HashMap + ChunkData bitsets + tile_ids
- RabbitDigTimer component: rabbits dig floor below every 5s, fires TileChangedEvent
  and TileOcclusionEvent for path invalidation + rendering
2026-03-21 11:56:51 +00:00
popertots d325aa6488 feat: fix log fixture passthrough, improve collision, add move_direction
Fix 1 — insert_fixture now updates ChunkData bitsets:
  Log trunks (can_stand_in=false) now block movement in is_standable.
  Leaf canopy (can_stand_in=true) remains walkable.

Fix 2 — Diagonal-aware collision avoidance:
  Sidestep priority: left+forward, left, right+forward, right.
  If all blocked: push through (excuse me), advance path, apply one-step
  delay (speed-modulated recovery). Does not stack delays.

Fix 3 — Movement direction tracking:
  Ambulatory now has move_direction (Vec2) and step_history ([i16; 4]).
  TileOccupancy tracks per-tile direction hints for Stage 2 collision
  (convoy skip, E/S yield) via direction_at().
  move_direction is smoothed from: 2 historical steps, current confirmed
  step, and 2-step path lookahead.

Ignore: add *.patch and *.diff to .gitignore
2026-03-21 11:07:35 +00:00
popertots f0cb86e73c fix: compare next vs current occupancy counts instead of absolute threshold
Two entities on the same tile (16,-0.0) each saw count=2 and blocked each
other with occupied=true since 2>1. The collision check was treating the
entity's own presence as a blocker.

Now: only trigger avoidance when next_tile has strictly more entities than
current_tile. Handles path[0]=current_pos (count equal → move), two entities
passing through same tile (counts stay equal → move), and genuinely crowded
destinations (next has more → dodge). Also raise crowded threshold to 4+.
2026-03-21 10:35:35 +00:00
popertots 31516f5c58 0 -> 1 2026-03-21 10:31:08 +00:00
popertots dd703f05f3 fix: remove collision_delay to eliminate movement deadlock
collision_delay was causing entities to skip step_recovery ticks, freezing
movement whenever the next tile was occupied. Combined with the ordering fix
(collision_delay placed before step_recovery), entities were stuck at
path_index=0 indefinitely in spawn clusters.

Remove collision_delay entirely — step_recovery already provides the
per-tick pacing, and the natural next-tick retry (via left-step or
normal movement) handles occupied tiles without an artificial delay.

Actual thresholds (grass weight=50): dorfs move after 6 ticks, pigs after
26 ticks, rabbits after 2 ticks. Without collision_delay interference,
movement is now governed purely by step_recovery.
2026-03-21 10:21:44 +00:00
popertots e60d057276 fix: move collision_delay after step_recovery to prevent deadlock
collision_delay was placed before the walk_speed/step_recovery block,
causing step_recovery to never tick when collision_delay was active —
entities stayed permanently pre-empted at path_index=0.

Correct order: step_recovery (must tick every frame) before
collision_delay (only checked when entity is ready to move).
2026-03-21 01:45:36 +00:00
popertots b4804bee5a fix gitignore 2026-03-21 01:37:44 +00:00
popertots 90a6196443 feat: soft entity collision, dead code removal, leaf standability fix
- Add TileOccupancy resource and rebuild_tile_occupancy system to track
  per-tile entity counts for soft collision avoidance
- Add collision_delay to Ambulatory; entities try relative-left step on
  occupied tiles, wait 1 tick, then push through
- Fix leaf canopy standability: leaves are now can_stand_in=true,
  can_stand_on=false (walkable, not standable-on)
- Delete FloorTilePrefab / FixtureTilePrefab / FloorTile / FixtureTile /
  TileState (all fully dead — TileMap + ChunkData are sole truth)
- Delete tile_spawns from TerrainBlob (populated but never consumed)
- Delete leaf ghost entity spawn in forestry (orphaned invisible ECS entity)
- Replace log prefab spawn with inline commands.spawn(Transform, Visibility)
- Add TileMap::remove_fixture for future digging/explosion use
- Skip collision avoidance when current tile has >2 entities (handles spawn
  cluster deadlock)
2026-03-21 01:36:38 +00:00
popertots 1fe4781bab fix: eliminate chunk-boundary doglegs in hierarchical pathfinding
Replace hard-coded chunk-centre waypoints with directional edge waypoints.
When a path segment crosses into the next chunk, directional_chunk_waypoint()
samples standable tiles along the entry edge and picks the one closest to the
straight-line projection from the entity's current position toward the goal.
Falls back to chunk centre if no standable edge tile is found.

This preserves tile-locked DF movement feel while removing the forced dogleg
at every chunk boundary that the chunk-centre approach introduced.
2026-03-20 17:47:35 +00:00
popertots e61a27fdb0 cargo 2026-03-20 17:29:47 +00:00
popertots c9802e6e0f gitignore 2026-03-20 17:28:41 +00:00
popertots 017ddb8047 feat: add distro, kernel version, and display resolution+Hz to system info
Distro parsed from /etc/os-release PRETTY_NAME.
Kernel from uname -r.
Display resolution and refresh rate from xrandr (linux only, N/A elsewhere).
2026-03-20 17:20:29 +00:00
popertots 06bbc9caa8 feat: neofetch-style system info dump at startup
Prints DORF SYSTEM box to stdout before game loop begins:
OS, CPU (model + cores), GPU (WEBGPU_ADAPTER_NAME env var),
RAM total + free (from /proc/meminfo), display vsync mode,
initial chunk radius, world seed.
2026-03-20 17:16:54 +00:00
popertots eac787be3f feat: runtime-configurable VSync via config.toml
[display]
vsync = "mailbox"   # "vsync" | "mailbox" | "uncapped"

VsyncMode enum with custom Deserialize — accepts string values in toml.
apply_vsync_setting system reads GameConfig on every frame, updates
Window.present_mode immediately on change. No restart needed.
2026-03-20 17:10:54 +00:00
popertots 11d4b6a8a0 fix 2026-03-20 15:57:24 +00:00
popertots 21e9dc1f34 perf: double populate budget in release builds
512 chunks/frame in debug, 1024 in release. In release, recolor runs
~2x faster so 1024 still costs ~1ms but clears the dirty queue twice
as fast, closing the p99 gap during rapid z-scrolling.
2026-03-20 15:44:47 +00:00
popertots 2b8e1c32b9 fix: remove .max(0) clamp from z_min — was inflating dirty set to all 20181 keys
Negative world z (below ground) was excluded by the clamp, making the
visible window asymmetrically large. Dirty count now proportional to
actual scroll distance. Frame time dropped from ~13ms to ~8.3ms avg.
2026-03-20 15:31:53 +00:00
popertots 0d73311c68 fix: correct boundary z-marking and tileset_index swap in recolor
Boundary: mark all z-levels where z_diff changed, not just 4 boundary
indices. For multi-step scrolls, every z-level between
min(old,new)-8 and max(old,new) inclusive needs recoloring.
Also fixes last_z_change_dirty_count to use actual new_keys.len().

Recolor: update tileset_index alongside color so sky tile switch at
t>=0.98 actually renders the sky texture, not sky-coloured grass.

Cleanup: removed solid_bits (was unused after recolor fix).
2026-03-20 15:28:17 +00:00
popertots 4c14f79cd2 perf: eliminate HashMap lookups on z-scroll with fast recolor + targeted boundary dirty
Three optimizations for z-scroll performance:

Option 1 — Fast in-place recolor (no HashMap lookups):
- TilemapChunkStates stores solid_bits + underground_bits per chunk
- recolor_chunk_for_depth iterates flat Vec<Option<TileData>> — pure cache-friendly sequential reads
- tile_fade_color computes color from tileset_idx + z_diff without any HashMap access
- vs repopulate_chunk_tiles: 32K Vec reads vs 32K HashMap lookups per frame

Option 2 — Targeted boundary dirty (from 9×chunks to 2×chunks):
- on_camera_z_changed now only marks the 4 boundary z-levels:
  old_entered, old_exited, new_entered, new_exited
- Registry.z_change_keys tracks z-changed keys separately from occlusion dirty_keys
- populate_tilemap_chunk_data uses fast recolor for z_change_keys,
  full repopulate for dirty_keys (occlusion — rare)

Option 3 — Separate budgets:
- z_change_keys processed with MAX_POPULATE_PER_FRAME budget (fast recolor)
- dirty_keys processed with MAX_POPULATE_PER_FRAME budget (full repopulate)
- Both pipelines tracked separately in benchmark

Also:
- populate_chunk_tiles now returns underground_bits for state storage
- compute_solid_bits helper extracts solid tiles from TileData Vec
- spawn_tilemap_chunks computes and stores both bitmasks on spawn
- despawn_tilemap_chunks clears all state for despawned chunks
2026-03-20 15:21:19 +00:00
popertots ac0e8bc1c7 perf: targeted z-scroll dirty marking, per-frame populate budget
on_camera_z_changed: only dirty z-levels whose z_diff changed
(both old and new camera positions, within 0..=8 window).
Previously dirtied all 20k entities on every z-change.

populate_tilemap_chunk_data: process up to MAX_POPULATE_PER_FRAME
(512) keys per frame, sorted by z-distance from current camera.
Spreads z-scroll cost across multiple frames instead of one spike.

TilemapBenchmark: added z-change spike instrumentation
(last_z_change_dirty_ms, last_z_change_dirty_count,
last_z_change_populate_ms, z_change_history_ms).
F9 report now shows z-scroll metrics.

PreviousZIndex resource tracks prior camera z for targeted dirty calc.
2026-03-20 14:50:13 +00:00
popertots b48459fceb fix: distinguish air vs solid non-visible tiles
Air (id=0) not in line of sight participates in depth fade (open space).
Solid terrain not visible is genuinely occluded — render black.
2026-03-20 14:37:48 +00:00
popertots 5c4725b4a0 fix: lerp RGB toward sky colour with full opacity — no alpha fade
- tile_for_depth: alpha always 1.0, lerp RGB from white toward sky RGB
  instead of fading tile out via alpha. Tiles stay opaque.
- Expose LAYER_ALPHA as pub const so it can be tuned at runtime
- LAYER_ALPHA changed from 41/255 to 50/255 for steeper visible fade
- Invisible tiles: explicit solid sky colour, not tile_for_depth(0, 999)
2026-03-20 14:34:07 +00:00
popertots fc47e719d7 fix: cross-fade tiles to sky tile using alpha instead of color tint
Replace df_fade_color (multiplicative tint that preserves texture hue)
with tile_for_depth which cross-fades between real tile and sky tile:

- z_diff <= 0: real tile at full opacity (no fade)
- z_diff in (0, threshold): real tile fades out via alpha
- z_diff past threshold: sky tile (index 0) fades in
- invisible tiles: solid sky colour

Also fix tile_id_to_tileset_index to include sky (id=0) as index 0,
so sky tiles render correctly as the fade target.
2026-03-20 14:27:24 +00:00
popertots 6fbfb10e48 fix: replace HSV df_fade_color with exact stacked blue compositing 2026-03-20 14:17:19 +00:00
popertots f9a74ed432 feat: migrate quilter rendering to Bevy TilemapChunk
Replaces the CPU pixel-baking quilter system (QuiltCache, TerrainSprite,
pixel_buffers) with Bevy's native TilemapChunk GPU-index-lookup API.

Architecture:
- TilemapChunk entities replace TerrainSprite entities per (chunk, z, layer)
- Tileset PNG stacked vertically as texture_2d_array (11 rows: 6 floor + 5 fixture)
- populate_chunk_tiles reads TileMap HashMap directly; no ECS FloorTile entities
- Chunk spawn deferred to apply_terrain_blobs (after TileMap data exists)
- Dirty key system triggers repopulate on occlusion/camera-z changes

Bug fixes:
- populate_chunk_tiles: add chunk_pos offset to world tile lookups (was always (0,0))
- spawn_tilemap_chunks: offset Transform by -TILE_SIZE/2 (tile-centre vs bottom-left)
- spawn_tilemap_chunks: AlphaMode2d::Blend (was Opaque, blocking DF fade)
- update_tilemap_chunk_visibility: actually mutate Visibility (was read-only)
- handle_tile_occlusion_updates: mark dirty keys inline (was double-reading events)
- TilemapChunkSpawner: deduplicate pending queue and guard stale registry

Performance:
- ~115K FloorTile ECS entities eliminated
- GPU memory: O(tile_data) instead of O(CHUNK_TILES² × z_levels × pixel_bytes)
- Z-scroll: only TilemapChunkTileData repopulates (no entity re-spawn)
- Benchmarks via TilemapBenchmark resource (F9 to report)
2026-03-20 14:02:04 +00:00
popertots 0eb2fcfbb3 plan 2026-03-20 11:19:54 +00:00
popertots 9018dabd6b remove tests 2026-03-20 10:52:46 +00:00
popertots 792a8981c1 docs: rewrite README to reflect actual implementation state 2026-03-20 10:33:20 +00:00