| Crates.io | adam_fov_rs |
| lib.rs | adam_fov_rs |
| version | 0.4.0 |
| created_at | 2021-12-26 03:26:47.119838+00 |
| updated_at | 2025-02-28 07:31:40.207244+00 |
| description | A rust implementation of Adam Milazzo's FOV algorithm http://www.adammil.net/blog/v125_Roguelike_Vision_Algorithms.html#mine |
| homepage | https://github.com/sarkahn/adam_fov_rs |
| repository | https://github.com/sarkahn/adam_fov_rs |
| max_upload_size | |
| id | 503174 |
| size | 244,330 |
An implementation of Adam Millazo's FOV algorithm
This crate provides a single function, compute_fov which can be used to compute a field of view into a 2d grid from existing map data. compute_fov uses function callbacks to read map data and define visible tiles for the caller.
use adam_fov_rs::*;
#[derive(Clone)]
enum Tile {
Floor,
Wall,
}
let width = 50;
let height = 50;
let index = |p: IVec2| p.y as usize * width + p.x as usize;
let mut game_map = vec![Tile::Floor; width * height];
// Add a vision blocker
game_map[index(IVec2::new(15, 16))] = Tile::Wall;
let mut vision = vec![false; width * height];
let is_opaque = |p| matches!(game_map[index(p)], Tile::Wall);
let mark_visible = |p| {
let i = index(p);
vision[i] = true;
};
compute_fov([15, 15], 5, [width, height], is_opaque, mark_visible);
let is_visible = |p| vision[index(p)];
assert!(!is_visible(IVec2::new(15, 17)));
assert!(is_visible(IVec2::new(17, 15)));

Taken from the "terminal" example