4.8 KiB
Session Summary: Data-Oriented Chunks Optimization
Date: 2026-03-19
Completed Work
Phase 1-3 Optimization (Implemented over multiple sessions)
- Bit-Packed Standability - ChunkData with bitsets for O(1) pathfinding
- Reactive Connectivity - Dirty flag system for O(d) connectivity updates
- Async Terrain Baking - AsyncComputeTaskPool for terrain generation
Recent Session Changes
-
External Tile Registry (
tiles.toml)- Hot-reloadable tile definitions without recompiling
- TileRegistry singleton for async-safe access
- Configurable weights, IDs, standability flags
-
Pathfinding Weight System
- Lower weight = preferred path (rock=50 best, bedrock=150 worst)
- Movement speed affected by tile weight
calculate_movement_cost(move_dir, tile_weight)signature change
-
Bug Fixes
- Fixed infinite spawner with
Local<bool>state guards - Fixed
world_to_chunkto useCHUNK_SIZE_TILE(128) notCHUNK_SIZE(8) - Fixed spawn coordinate grid alignment
- Fixed standability logic (reverted to original)
- Fixed infinite spawner with
-
Standability Logic (Working Version)
fn is_standable_slow(&self, pos: IVec3) -> bool { let can_stand_in_floor = self.floor_tiles.get(&pos) .map(|t| t.can_stand_in()).unwrap_or(false); let can_stand_in_fixture = self.fixture_tiles.get(&pos) .map(|t| t.can_stand_in()).unwrap_or(false); let pos_below = IVec3::new(pos.x, pos.y, pos.z - ITILE_SIZE); let can_stand_on_floor = self.floor_tiles.get(&pos_below) .map(|t| t.can_stand_on()).unwrap_or(false); let can_stand_on_fixture = self.fixture_tiles.get(&pos_below) .map(|t| t.can_stand_on()).unwrap_or(false); (can_stand_in_floor || can_stand_in_fixture) && (can_stand_on_floor || can_stand_on_fixture) }
Current Bug: Zigzag Pathfinding
Symptom
Entities no longer walk in straight lines to their targets. Movement shows erratic zigzag behavior instead of direct paths.
Working Hypothesis
The zigzag behavior likely stems from:
- Path validation failing and paths being constantly regenerated
- Weight system causing cost calculation issues
- Movement speed modifier causing step recovery inconsistencies
- The tile weight being applied incorrectly in movement
What Was Working Before Recent Changes
- Straight-line pathfinding
- Entities would walk directly to targets
What Changed That Might Cause Zigzag
calculate_movement_costnow takestile_weightparameter- Movement speed now varies by tile weight
get_tile_weight()retrieves weight from tilemap
Relevant Code Locations
src/entities/shared_systems/pathfinding.rscalculate_movement_cost()lines ~600get_tile_weight()lines ~440- Movement system lines ~482
src/world/tiles/tilemap.rsget_astar_weight()method
tiles.toml- Weight values: rock=50, grass=100, bedrock=150
Next Agent Prompt
Starting From Zero Context
You are investigating a zigzag pathfinding bug in a Bevy game engine project called "Dorf".
Project Overview
- Voxel-style game with procedural terrain generation
- Pathfinding system with A* implementation
- Tile-based world with gravity for entities
- Coordinates: TILE_SIZE=16, ITILE_SIZE=16
The Bug
After recent commits, entities exhibit zigzag movement instead of walking in straight lines to their targets.
Investigation Steps
-
Read the pathfinding system (
src/entities/shared_systems/pathfinding.rs)- Focus on
movement()function (line ~482) - Focus on
calculate_movement_cost()(line ~600) - Focus on path validation (
validate_next_steps())
- Focus on
-
Understand the weight system
- How does
tile_weightaffectcalculate_movement_cost()? - Does varying movement costs cause zigzag paths?
- How does
-
Check movement speed modifier
threshold = walk_speed * (tile_weight / 50.0)- Could this cause inconsistent stepping?
-
Compare with git history
- Run
git log --oneline -10to see recent commits git diff HEAD~1to see last commit changes- Find when zigzag started by checking commits
- Run
-
Hypothesize and test
- Disable weight system temporarily
- Compare path cost calculations
- Verify path validation is working
Key Files
src/entities/shared_systems/pathfinding.rs- Main pathfinding logicsrc/entities/shared_components/ambulatory.rs- Movement statesrc/world/tiles/tilemap.rs- Tile lookupstiles.toml- Tile weight definitions
Expected Behavior
Entities should walk in straight lines from start to goal when no obstacles.
Actual Behavior
Entities zigzag/wander instead of walking straight.
Success Criteria
- Entities walk in straight lines to targets
- Path costs are consistent
- No erratic movement behavior