From d29a3e793f7d8c68f023dbce7f795829cd450b92 Mon Sep 17 00:00:00 2001 From: popertots Date: Thu, 19 Mar 2026 19:16:27 +0000 Subject: [PATCH] docs: add session summary and 48h diff for handoff --- SESSION_SUMMARY.md | 134 ++++++++++++++++++++++++++++++++++++++++ diff_last_48h.patch.txt | 65 +++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 SESSION_SUMMARY.md create mode 100644 diff_last_48h.patch.txt diff --git a/SESSION_SUMMARY.md b/SESSION_SUMMARY.md new file mode 100644 index 0000000..e4d5690 --- /dev/null +++ b/SESSION_SUMMARY.md @@ -0,0 +1,134 @@ +# Session Summary: Data-Oriented Chunks Optimization + +## Date: 2026-03-19 + +## Completed Work + +### Phase 1-3 Optimization (Implemented over multiple sessions) +1. **Bit-Packed Standability** - ChunkData with bitsets for O(1) pathfinding +2. **Reactive Connectivity** - Dirty flag system for O(d) connectivity updates +3. **Async Terrain Baking** - AsyncComputeTaskPool for terrain generation + +### Recent Session Changes + +1. **External Tile Registry** (`tiles.toml`) + - Hot-reloadable tile definitions without recompiling + - TileRegistry singleton for async-safe access + - Configurable weights, IDs, standability flags + +2. **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 + +3. **Bug Fixes** + - Fixed infinite spawner with `Local` state guards + - Fixed `world_to_chunk` to use `CHUNK_SIZE_TILE` (128) not `CHUNK_SIZE` (8) + - Fixed spawn coordinate grid alignment + - Fixed standability logic (reverted to original) + +4. **Standability Logic (Working Version)** + ```rust + 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: +1. Path validation failing and paths being constantly regenerated +2. Weight system causing cost calculation issues +3. Movement speed modifier causing step recovery inconsistencies +4. 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_cost` now takes `tile_weight` parameter +- Movement speed now varies by tile weight +- `get_tile_weight()` retrieves weight from tilemap + +### Relevant Code Locations +- `src/entities/shared_systems/pathfinding.rs` + - `calculate_movement_cost()` lines ~600 + - `get_tile_weight()` lines ~440 + - Movement system lines ~482 +- `src/world/tiles/tilemap.rs` + - `get_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 +1. **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()`) + +2. **Understand the weight system** + - How does `tile_weight` affect `calculate_movement_cost()`? + - Does varying movement costs cause zigzag paths? + +3. **Check movement speed modifier** + - `threshold = walk_speed * (tile_weight / 50.0)` + - Could this cause inconsistent stepping? + +4. **Compare with git history** + - Run `git log --oneline -10` to see recent commits + - `git diff HEAD~1` to see last commit changes + - Find when zigzag started by checking commits + +5. **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 logic +- `src/entities/shared_components/ambulatory.rs` - Movement state +- `src/world/tiles/tilemap.rs` - Tile lookups +- `tiles.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 diff --git a/diff_last_48h.patch.txt b/diff_last_48h.patch.txt new file mode 100644 index 0000000..613180d --- /dev/null +++ b/diff_last_48h.patch.txt @@ -0,0 +1,65 @@ +# Last 48h Git Diff + +## Commit: 9535d65 (HEAD) +### Message: feat: data-oriented chunks optimization with tile registry + +Files changed (14 files, +423 -84): + +``` +tiles.toml | +186 (NEW) +src/config.rs | +50 +src/entities/shared_systems/pathfinding.rs | +45 -4 +src/entities/shared_components/ambulatory.rs | +10 -10 +src/entities/livestock/pig.rs | +10 -2 +src/entities/livestock/rabbit.rs | +8 +src/entities/sentient/dorf.rs | +8 +src/game.rs | +12 +src/main.rs | +16 -16 +src/world/generation/terrain.rs | +123 -3 +src/world/mod.rs | +12 +src/world/tiles/chunk_data.rs | +21 +src/world/tiles/prefabs.rs | +85 -19 +src/world/tiles/tilemap.rs | +14 +``` + +### Key Changes: + +#### 1. External Tile Registry (tiles.toml) +- New `tiles.toml` for hot-reloadable tile definitions +- Floor tiles: air, grass, dirt, rock, bedrock with weight/standability +- Fixture tiles: walls, log, leaves +- IDs, weights, can_stand_in, can_stand_on all configurable + +#### 2. Config.rs additions +- `TileRegistry` struct with `OnceLock` global singleton +- `FloorTileDef` and `FixtureTileDef` structs +- Loads from `tiles.toml` at first access +- `global()` method for async-safe access + +#### 3. Pathfinding.rs changes +- `calculate_movement_cost(move_dir, tile_weight)` - now takes weight param +- `get_tile_weight(tilemap, pos)` - retrieves weight from tile +- Movement speed modifier: `threshold = walk_speed * (tile_weight / 50)` +- `SpawnDelay` resource for delayed spawning + +#### 4. Chunk data improvements +- `ChunkData::is_standable()` bit-packed standability checks +- `get_astar_weight()` method for pathfinding cost + +#### 5. world_to_chunk fix +- Changed from `CHUNK_SIZE` (8) to `CHUNK_SIZE_TILE` (128) + +#### 6. Entity spawning fixes +- `Local` state guards prevent infinite spawning +- Grid-aligned spawn coordinates +- Delayed spawning with `SpawnDelay` resource + +--- + +## Commit: 50788af +### Message: feat(optimization): implement data-oriented chunk architecture + +Previous optimization phases: +- ChunkData with bit-packed standability +- Dirty chunk tracking for O(d) connectivity +- Async terrain generation