#rogue-like #2d #fov #field-of-view #2d-grid #width-height

adam_fov_rs

A rust implementation of Adam Milazzo's FOV algorithm http://www.adammil.net/blog/v125_Roguelike_Vision_Algorithms.html#mine

7 unstable releases (3 breaking)

0.4.0 Feb 28, 2025
0.3.0 Feb 22, 2025
0.2.0 Sep 23, 2022
0.1.4 May 25, 2022
0.1.1 Dec 26, 2021

#648 in Game dev

Download history 1/week @ 2024-11-13 1/week @ 2024-11-20 128/week @ 2025-02-19 170/week @ 2025-02-26

298 downloads per month

MIT license

145KB
328 lines

License: MIT Crates.io docs

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.

Example

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

Dependencies

~4.5MB
~131K SLoC