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
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use ahash::AHashMap;
|
||||
use ahash::AHashSet;
|
||||
use bevy::tasks::{AsyncComputeTaskPool, Task};
|
||||
use bevy::prelude::*;
|
||||
use rayon::prelude::*;
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustc_hash::FxHashSet as HashSet;
|
||||
use std::{cell::RefCell, collections::BinaryHeap, sync::Arc, time::Instant};
|
||||
use std::{cell::RefCell, collections::BinaryHeap, time::Instant};
|
||||
|
||||
// Thread-local storage for collecting metrics during parallel execution
|
||||
thread_local! {
|
||||
@@ -326,27 +326,24 @@ fn is_standable_tile(tilemap: &TileMap, pos: IVec3) -> bool {
|
||||
let mut can_i_stand_in_fixture: bool = false;
|
||||
let mut can_i_stand_on_fixture_bellow: bool = false;
|
||||
|
||||
// Check if current position has a blocking floor tile
|
||||
if let Some(current_floor_tile) = tilemap.floor_tiles.get(&pos) {
|
||||
can_i_stand_in_tile = current_floor_tile.1;
|
||||
can_i_stand_in_tile = current_floor_tile.can_stand_in();
|
||||
}
|
||||
// Check if current position has a solid fixture tile (e.g., log)
|
||||
if let Some(current_fixture_tile) = tilemap.fixture_tiles.get(&pos) {
|
||||
can_i_stand_in_fixture = current_fixture_tile.1;
|
||||
can_i_stand_in_fixture = current_fixture_tile.can_stand_in();
|
||||
}
|
||||
|
||||
// Check if there's solid ground below (fixture or floor)
|
||||
let pos_below = pos - IVec3::new(0, 0, ITILE_SIZE);
|
||||
|
||||
if let Some(below_floor_tile) = tilemap.floor_tiles.get(&pos_below) {
|
||||
can_i_stand_on_tile_bellow = below_floor_tile.2;
|
||||
can_i_stand_on_tile_bellow = below_floor_tile.can_stand_on();
|
||||
}
|
||||
|
||||
if let Some(below_fixture_tile) = tilemap.fixture_tiles.get(&pos_below) {
|
||||
can_i_stand_on_fixture_bellow = below_fixture_tile.2;
|
||||
can_i_stand_on_fixture_bellow = below_fixture_tile.can_stand_on();
|
||||
}
|
||||
return (can_i_stand_in_tile || can_i_stand_in_fixture)
|
||||
&& (can_i_stand_on_tile_bellow || can_i_stand_on_fixture_bellow);
|
||||
(can_i_stand_in_tile || can_i_stand_in_fixture)
|
||||
&& (can_i_stand_on_tile_bellow || can_i_stand_on_fixture_bellow)
|
||||
}
|
||||
|
||||
/// Original calculate_path - kept for reference, not currently used.
|
||||
|
||||
Reference in New Issue
Block a user