adam_fov_rs

Crates.ioadam_fov_rs
lib.rsadam_fov_rs
version
sourcesrc
created_at2021-12-26 03:26:47.119838+00
updated_at2025-02-28 07:31:40.207244+00
descriptionA rust implementation of Adam Milazzo's FOV algorithm http://www.adammil.net/blog/v125_Roguelike_Vision_Algorithms.html#mine
homepagehttps://github.com/sarkahn/adam_fov_rs
repositoryhttps://github.com/sarkahn/adam_fov_rs
max_upload_size
id503174
Cargo.toml error:TOML parse error at line 21, column 1 | 21 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
sark (sarkahn)

documentation

README

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

Commit count: 10

cargo fmt