Commit Graph
184 Commits
Author SHA1 Message Date
popertots c902cff908 feat: async pathfinding with provisional paths and bit-grid snapshots
- Add StandableBitGrid: O(1) bit-packed snapshot (~6KB per 50k tiles vs HashMap overhead)
- Implement two-tier pathfinding: sync for short paths (<64 tiles), provisional+async for long paths
- calculate_provisional_path: capped A* returning path to best heuristic node
- calculate_async_path: A* using bit-grid (Send+Sync, no thread_local)
- prepare_paths system: dispatches provisional paths immediately, spawns async for full paths
- poll_async_paths + splice_completed_async_paths: seamless path transition when async completes
- Entities start walking immediately on provisional path while full path computes in background

Architecture:
  FixedUpdate: prepare_paths → update_wandering_targets → movement
  PostUpdate: poll_async_paths → splice_completed_async_paths

Priority: DF-like pathing (immediate movement) > performance > memory
2026-03-18 16:35:39 +00:00
popertots 79a386afa6 chore: add benchmark verification script and current benchmark data 2026-03-18 16:15:19 +00:00
popertots 0550191c7a Fix update_wandering_targets target validation logic
- Restored original target selection logic that validates is_standable_tile
- Fixed target position z-level checking (check floor tile then standable)
- Re-added check for completed paths (path_index >= path.len)
- This was the cause of 50,297 failed paths - entities targeting invalid positions
2026-03-18 15:45:25 +00:00
popertots 367ab26d5e Fix performance regressions: remove TIER0, consolidate scratchpads, remove Arc trap
Key fixes based on benchmark analysis:
1. Remove TIER0 Vec-based pathfinding - O(N) linear scan was slower than FxHashMap for typical path lengths
2. Consolidate scratchpads into single AStarScratchpad struct - eliminates nested RefCell borrow overhead
3. Remove Arc wrapper from TileMap - eliminated Copy-on-Write trap causing 63ms stutters
4. Replace AHashMap with FxHashMap - FxHash is faster for small integer keys like IVec3
5. Simplify tier logic - single pathfinding function with scratchpad reuse

Benchmark analysis showed:
- Original: 1.95 µs/node, P99 1.1ms, Max 5ms
- TIER0/TIER1 regression: 2.89 µs/node (+48%), P99 5ms (+348%)
- Root causes: Vec linear scan in TIER0, nested RefCell borrows, Arc::make_mut CoW

This should restore and improve performance by using simple FxHashMap scratchpad for all paths.
2026-03-18 15:30:48 +00:00
popertots 466a20700a Wrap TileMap HashMaps in Arc for async pathfinding access
- Add Arc<AHashMap> wrapper around floor_tiles, fixture_tiles, item_tiles
- Copy-on-write semantics: Arc::make_mut clones only if other Arcs exist
- Add insert_floor, insert_fixture, insert_item, remove_item methods
- Add get_floor_mut, get_fixture_mut for visibility updates
- Update all mutation sites to use new TileMap methods
- Enables cheap Arc::clone for async pathfinding workers
- Single-threaded pathfinding: no clone, direct access
- Multi-threaded pathfinding: clone Arc, read without locks
2026-03-18 14:56:57 +00:00
popertots 8478b385bc Optimize TileMap: replace HashMap with AHashMap, pack tile data
- Replace std HashMap (SipHash) with ahash::AHashMap for fast non-crypto hashing
- Pack tile data from tuples to structs: FloorTileData (~35 bytes) and FixtureTileData (~18 bytes)
- FloorTileData: pack 3 bools into single flags byte, use u8 for id/weight
- FixtureTileData: pack 2 bools into single flags byte
- Update all accessors: is_standable_tile, visibility, terrain generation, forestry
- Preparation for async pathfinding (Arc wrapping to come in follow-up)

Memory reduction: ~54% for floor tiles (76→35 bytes), ~62% for fixtures (48→18 bytes)
Hash performance: AHashMap uses fxhash, faster than SipHash for game data
2026-03-18 14:52:46 +00:00
popertots 81b70a661c Implement tiered pathfinding with thread-local scratchpads
- TIER0 (<10 tiles): Vec-based linear search, zero hash overhead
- TIER1 (10-30 tiles): FxHashMap scratchpad with memory reuse
- TIER2 (30-100 tiles): AHashMap scratchpad for better collision resistance
- TIER3 (>100 tiles): Chunk waypoint decomposition
- Added benchmarking infrastructure with F8 report trigger
- Added async infrastructure: PendingPath, CompletedPaths resources
- Lowered MAX_NODES to 5000 to prevent runaway searches

Benchmarks show P50 improved 13%, max improved 53%
2026-03-18 14:37:15 +00:00
popertots 49972b9b64 better config for benchmarks 2026-03-18 11:21:40 +00:00
popertots aeef78eca2 Fix tiled patching 2026-03-18 09:22:47 +00:00
popertots b0b0ca0390 optimize visibility calcs 2026-02-28 11:27:50 +00:00
popertots b1de9f95c2 quilted chunk optimisations 2026-02-28 00:07:07 +00:00
popertots 4ef68c4e04 migratetion to 0.18.0 2026-02-16 00:02:00 +00:00
popertots a9040a4c9e optimize item removal 2026-02-15 19:18:52 +00:00
popertots 886d162963 dropped item rotation 2026-02-15 18:56:38 +00:00
popertots 975ac20876 minor 2025-09-14 19:04:34 +01:00
popertots 4c4c985be3 item flashing 2025-09-14 18:48:50 +01:00
popertots 8a5884c6d5 example item 2025-09-12 18:04:03 +01:00
popertots ee7ac39ad5 refactor file locations for readability 2025-09-11 18:23:53 +01:00
popertots e58f6804bf File cleanup 2025-09-10 20:03:29 +01:00
popertots cbc8011f33 Art 2025-09-10 18:11:01 +01:00
popertots feed403495 Update bevy version, implement bevy_rand 2025-09-07 20:05:00 +01:00
popertots 7e52d6e1bd fix zoom, rework chunkmap events 2025-05-29 16:22:02 +01:00
Stephen Adamson 0def6af6e8 fix scroll 2025-05-28 11:03:57 +01:00
popertots e8d3f1bafb prep bench 2025-05-27 23:28:25 +01:00
popertots 950f02c2e1 rework pathfinding, game entity fog rendering, and tilemap usage 2025-05-27 23:10:54 +01:00
popertots d2dd70caa0 add trees 2025-05-23 17:09:58 +01:00
popertots ac033de136 rework occlusion events 2025-05-23 14:01:28 +01:00
popertots a245f35332 Refactor visibility system to use component-based approach
- Introduce VisibleGameEntity component for entities needing visibility logic
- Move Z-index based visibility calculations to dedicated system
- Update both citizens and logs to use new visibility system
- Remove duplicated visibility logic from citizen movement system
- Add compute_visibility_of_game_entities system to Update phase

This improves modularity by separating visibility concerns from movement systems.
2025-05-22 13:06:27 +01:00
popertots a83f71addd Fix pathing 2025-05-12 21:49:10 +01:00
popertots e2ccd0cead Log (wip), parallelisation 2025-05-11 22:58:25 +01:00
popertots 31e6eb29b2 camera zooming 2025-05-09 18:13:28 +01:00
popertots e3ea662668 fake fog, better parallelisation 2025-05-07 20:13:29 +01:00
popertots 6f4de57f1b average composite on terrain sprites 2025-05-06 22:31:31 +01:00
popertots 6f82b904fe fix terrain ordering 2025-05-06 14:24:29 +01:00
popertots 49095cc47f terrain quilting scaling fix 2025-05-05 23:09:28 +01:00
popertots 5726a68efb Terrain quilting 2025-05-05 00:09:12 +01:00
popertots c061ecc082 fix terrain z scrolling 2025-05-04 01:08:58 +01:00
popertots 9df3f7ecaf manhattan to octile 2025-05-03 20:27:44 +01:00
popertots b5a3fd1714 clippy 2025-05-02 20:58:18 +01:00
popertots 18756b2366 fix unloadng of temp terrain 2025-05-02 20:53:04 +01:00
popertots b7261ae847 bevy 0.16 migration 2025-05-02 19:27:23 +01:00
popertots 9f264f230e revert to non-benchmark 2025-05-02 18:20:32 +01:00
StephenAdamson 4ba6fecc27 batch sprite 1 2025-02-08 00:23:49 +00:00
StephenAdamson 4089851734 benchmark 2025-02-06 21:32:30 +00:00
StephenAdamson 6161c21e22 Singular tiles resource 2025-02-01 01:07:39 +00:00
StephenAdamson 501c66a1b0 better dorf z 2025-01-25 16:54:27 +00:00
popertots 7143a9dded working path finding, non working targeting 2025-01-24 17:20:45 +00:00
popertots ca3fcc00ff path 2 2025-01-21 23:39:00 +00:00
StephenAdamson bb3905e6b9 minor 2025-01-21 21:02:40 +00:00
popertots 53b95f452f Fixed targeting for citizen movement 2025-01-19 22:13:24 +00:00