100 Commits
Author SHA1 Message Date
popertots 61992da90f docs: update investigation handoff with current state and fixes 2026-04-06 00:25:10 +01:00
popertots 1d78c211ad fix: cargo standability and clear old task target
- Make is_standable return true for cargo tiles (logs, rocks can be stood on)
- Clear ambulatory.target when assigning new task to prevent old targets persisting

These fixes address the 'Lost Signal' bug where dorfs would freeze:
1. Cargo tiles were incorrectly flagged as non-standable, blocking pathfinding
2. Old Idle task targets persisted when new jobs assigned, causing dorfs to path to wrong locations
2026-04-06 00:23:09 +01:00
popertots 9eecd3e49d pathfinding 2026-04-06 00:22:17 +01:00
popertots cfed0c4d26 Handoff 2026-04-06 00:21:59 +01:00
popertots ec1ec6b7d4 Fix bug: prevent multiple job assignments to same dorf in one frame
- Add assigned_this_frame HashSet to track dorfs receiving jobs
- Filter out already-assigned dorfs from subsequent job assignments
- Add debug logging for spawn position (z-level)
- Add debug logging for is_standable failures
- Add debug logging for falling/snapping movement behavior

This fixes the critical bug where one dorf could be assigned multiple
jobs in the same frame, causing earlier assignments to be lost due to
queue.clear(). Each dorf now receives at most one job per frame.
2026-04-05 18:09:37 +01:00
popertots c9d74ef49b Update z-level context: not underground, perlin terrain, check working pathfinding 2026-04-04 12:29:03 +01:00
popertots f054bf25f1 Add session continuation prompt for next agent 2026-04-04 12:21:52 +01:00
popertots 8e3e8b8b8c Fix: Set ambulatory.target for HaulCargo when approach pre-computed
When job_pathfinding pre-computes the approach tile for HaulCargo,
the executor was skipping target assignment because:
1. approach.is_none() was false (approach already set)
2. ambulatory.target.is_none() was true (no target set)
3. No else branch to set the target

Added else-if branch to set target when approach is set but target isn't.
This fixes dorfs freezing in MovingToCargo state with target=None.
2026-04-04 12:16:23 +01:00
popertots 022e21d484 Fix: Don't clear ambulatory.target during job assignment
The target oscillation was caused by job_pathfinding_system
clearing ambulatory.target = None on assignment, then the executor
setting it to approach, then job_pathfinding clearing it again
the next frame.

By not clearing ambulatory.target, the executor sets it once
and it persists until the task completes.
2026-04-04 12:02:15 +01:00
popertots 7cf1b83427 Fix: Allow dorfs running Idle task to be job candidates
The bug: We excluded ALL Active state dorfs, but Idle tasks get
immediately promoted from Pending to Active by task_executor_system.
So by the time job_pathfinding runs, all dorfs are Active with Idle.

The fix: Check if dorf is 'busy' = Active AND non-Idle task.
Dorfs with Idle tasks (even in Active state) can be interrupted
for real jobs.
2026-04-04 11:53:29 +01:00
popertots 196ff9cec4 Fix job pathfinding: allow idle dorfs to be candidates + add debug logging
KEY FIX: Changed candidate filter to allow dorfs with Idle tasks:
- Before: Only dorfs with empty queues were candidates
- After: Dorfs with empty queue OR Idle task are candidates
- This fixes deadlock where all dorfs had Idle tasks and were excluded

Debug logging added:
- job_pathfinding.rs: Log job processing, candidate counts, path results
- queue_debug.rs: Show job state (Unclaimed/Calculating/Claimed/Suspended), retry count, and dorf idle status

The bug was that job_pathfinding_system filtered out ALL dorfs because:
1. job_assignment_system gave Idle tasks to dorfs with empty queues
2. task_executor_system promoted them to Active
3. job_pathfinding_system then excluded Active dorfs AND non-empty queues
2026-04-04 11:50:10 +01:00
popertots 053fe415bf Implement async job pathfinding system
- Add calculate_traversal_distance() - full A* that returns actual distance
- Add batch_calculate_traversals() for efficient batch processing
- Add Calculating state to JobState enum for dorf locking
- Add approach_target and retry_count to job Entry
- Add helper methods: is_dorf_locked, get_locked_dorfs, get_scope_for_job
- Add job_assignment config section with max_dorfs_per_job
- Create job_pathfinding.rs with main pathfinding system:
  - Throttled to MAX_JOBS_PER_TICK (5) per frame
  - Expanding scope: 5 -> 20 -> 200 dorfs based on retry count
  - Uses full pathfinding, not provisional
  - Pre-computes approach_target for assigned dorfs
- Simplify job_assignment.rs to only handle idle fallback
- Update has_fell_tree to check state (Unclaimed, Calculating, Claimed)
2026-03-29 13:13:53 +01:00
popertots 3c74a68d4d Refactor job queue: add JobState enum, improve pathfinding fallback
- Add JobState enum (Unclaimed, Claimed, Complete) replacing boolean claimed flag
- Increase provisional node limit from 256 to 4096
- Add iter_unclaimed() and claim_job_at() methods to JobQueue
- Update job_assignment to filter idle dorfs, match by distance
- Add unclaim_jobs_for_entity() for handling dorf death/failure
- Add JobId collision detection in debug builds
- Fix demo system to check Pending state for chopping dorfs
- Throttle queue_debug to every 120 ticks
- Add surface position deduplication for terrain chunks
2026-03-29 13:02:05 +01:00
popertots 79e0efa409 Fix job queueing system: add JobId tracking for failed job reassignment
- Add JobId (rolling u16 counter) to track jobs through their lifecycle
- Add job_id field to all Task variants (Idle, GoTo, ChopTree, HaulCargo, DropHauled)
- Add unclaim_job() method to requeue failed jobs for reassignment
- Change task failure paths to use unclaim_job() instead of complete_job_by_id()
  - This allows failed jobs to be picked up by another dorf instead of being stuck
- Add to_job_kind() and get_job_id() helper methods to Task
- Fix pathfinding is_standable_tile debug logging spam
- Fix chunk bounds check in ChunkData::is_standable (was checking wrong z range)
2026-03-27 20:28:58 +00:00
popertots bd1b45e4d7 attempt 3 2026-03-27 10:29:33 +00:00
popertots 1f5dfe5182 Task fix attempt 2026-03-23 19:31:30 +00:00
popertots 3632836016 fix 2026-03-22 22:30:15 +00:00
popertots bf81f42ced fix 2026-03-22 22:10:00 +00:00
popertots 57764fbcbb fix 2026-03-22 22:05:08 +00:00
popertots c448ef4bff fix 2026-03-22 22:01:11 +00:00
popertots 760f6602cf fix 2026-03-22 16:51:20 +00:00
popertots ffb0e79cf3 fix 2026-03-22 16:45:46 +00:00
popertots 738f595f67 debug 2026-03-22 16:38:54 +00:00
popertots e7a43457a3 fix 2026-03-22 16:05:38 +00:00
popertots bceec18a7a log sprite 2026-03-22 16:05:33 +00:00
popertots c46e23af06 fix 2026-03-22 15:23:44 +00:00
popertots 3b9b2d9c88 fix 2026-03-22 15:07:05 +00:00
popertots 5a830f46f9 demo part 2 2026-03-22 14:57:59 +00:00
popertots 54eabe85e2 fix 2026-03-22 14:34:59 +00:00
popertots 57e377c093 fix 2026-03-22 13:01:10 +00:00
popertots 2eaf0196a5 demo 1 2026-03-22 12:56:52 +00:00
popertots 360ffc7526 value tweaks 2026-03-22 12:06:33 +00:00
popertots 26a861e1a5 value tweaks 2026-03-22 12:00:17 +00:00
popertots cb5b18008d fix 2026-03-22 11:50:53 +00:00
popertots 2f456f80b8 Gaussian idle 2026-03-22 11:29:50 +00:00
popertots b2dc0cb864 fix 2026-03-22 11:02:36 +00:00
popertots 749913a028 fix? 2026-03-22 01:58:34 +00:00
popertots adc236dc3d fix 2026-03-22 01:52:20 +00:00
popertots 9afcb0f612 more debug 2026-03-22 01:32:22 +00:00
popertots 64a69d6a40 Debug 2026-03-22 01:24:08 +00:00
popertots deb3f741b0 rng fix 2026-03-22 01:00:42 +00:00
popertots 71653350d8 fix 2026-03-22 00:52:06 +00:00
popertots cafe376841 Plugin cleanup 2026-03-22 00:43:03 +00:00
popertots d61baaf1ba Task Infrastructure — Task Enum, Queue, Events, Executor 2026-03-22 00:35:22 +00:00
popertots 458068fb87 run_if 2026-03-22 00:03:57 +00:00
popertots ff149117ca remove Digger from dorf 2026-03-21 23:56:03 +00:00
popertots 029e4162d8 fixes 2026-03-21 23:48:49 +00:00
popertots c776b91a44 haulage system WIP 2026-03-21 23:39:58 +00:00
popertots dcdfb375f0 Fix 2026-03-21 21:51:29 +00:00
popertots f52c8ab18c inventory: early return before HashSet alloc, restore doc comments 2026-03-21 21:44:06 +00:00
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