Dead code removed (21 methods, 4 fields, 3 constants): - Cell: MaterialId::ALL, MaterialId::from_u8 (unsafe transmute) - Grid: get_mut, clear, fill_rect, swap, dump_region, next buffer field - Entity: move_center, EntityManager::iter_mut - Player: move_dir field, entity_mut - VerletSolver: step, SubBody::add_vel, SubBody::apply_force - CellularAutomaton: tick_count - InputHandler: release_all, poll, Action::None - WindowInput: clear - GameSession: perform_action_and_step, is_recording, grid_mut - ReplayPlayer: from_recording - Material: empty() - VulkanRenderer: tick_count field - MaterialBrush: name() Warnings fixed: - Remove unused MaterialRegistry imports from renderers - Remove unused reg variables in terminal/vulkan/graphics - Remove unused water_surface in game.rs - Remove unused p/y_death in tests - Remove unused qf_slice in graphics.rs Duplication eliminated: - main.rs: run_ascii_mode + run_graphics_mode → generic run_gpu_mode<R: GpuRenderer> ~140 lines of duplicated event loop code removed - GpuRenderer trait unifies VulkanRenderer and GraphicsRenderer API Unsafe code fixed: - rand_u8: static mut + unsafe → AtomicU8 + fetch_add (thread-safe) Module cleanup: - world/mod.rs: removed all unused re-exports - physics/mod.rs: removed all unused re-exports - entity/mod.rs: removed unused Entity/EntityId re-exports Result: ~6500 → ~5964 lines, 0 non-deprecation warnings, 109 tests pass
73 lines
1.8 KiB
Rust
73 lines
1.8 KiB
Rust
use crate::world::cell::{Cell, MaterialId};
|
|
|
|
pub const WORLD_W: usize = 250;
|
|
pub const WORLD_H: usize = 250;
|
|
|
|
pub struct Grid {
|
|
pub cells: Vec<Cell>,
|
|
pub width: usize,
|
|
pub height: usize,
|
|
}
|
|
|
|
impl Grid {
|
|
pub fn new() -> Self {
|
|
let size = WORLD_W * WORLD_H;
|
|
Self {
|
|
cells: vec![Cell::empty(); size],
|
|
width: WORLD_W,
|
|
height: WORLD_H,
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn idx(&self, x: i32, y: i32) -> usize {
|
|
(y as usize) * self.width + (x as usize)
|
|
}
|
|
|
|
#[inline]
|
|
pub fn in_bounds(&self, x: i32, y: i32) -> bool {
|
|
x >= 0 && x < self.width as i32 && y >= 0 && y < self.height as i32
|
|
}
|
|
|
|
#[inline]
|
|
pub fn get(&self, x: i32, y: i32) -> Cell {
|
|
if !self.in_bounds(x, y) {
|
|
return Cell::new(MaterialId::Stone);
|
|
}
|
|
self.cells[self.idx(x, y)]
|
|
}
|
|
|
|
#[inline]
|
|
pub fn set(&mut self, x: i32, y: i32, cell: Cell) {
|
|
if self.in_bounds(x, y) {
|
|
let i = (y as usize) * self.width + (x as usize);
|
|
self.cells[i] = cell;
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn set_material(&mut self, x: i32, y: i32, mat: MaterialId) {
|
|
if self.in_bounds(x, y) {
|
|
let i = (y as usize) * self.width + (x as usize);
|
|
self.cells[i] = Cell::new(mat);
|
|
}
|
|
}
|
|
|
|
pub fn fill_border(&mut self, mat: MaterialId) {
|
|
for x in 0..self.width {
|
|
self.set_material(x as i32, 0, mat);
|
|
self.set_material(x as i32, (self.height - 1) as i32, mat);
|
|
}
|
|
for y in 0..self.height {
|
|
self.set_material(0, y as i32, mat);
|
|
self.set_material((self.width - 1) as i32, y as i32, mat);
|
|
}
|
|
}
|
|
|
|
pub fn reset_tick_flags(&mut self) {
|
|
for c in &mut self.cells {
|
|
c.updated_this_tick = false;
|
|
}
|
|
}
|
|
}
|