Expand description

License: MIT Crates.io docs

An implementation of Adam Millazo’s FOV algorithm

To use it you must implement the [VisiblityMap] trait on your map type. Then you can call fov::compute with your map which will populate visible tiles based on the map’s opaque tiles.

Example

use adam_fov_rs::{VisibilityMap, fov};
use glam::IVec2;

struct Map {
    visible: Vec<Vec<bool>>,
    opaque: Vec<Vec<bool>>,
    size: IVec2,
}

impl VisibilityMap for Map {
    fn is_opaque(&self, p: IVec2) -> bool { self.opaque[p.x as usize][p.y as usize] }
    fn is_in_bounds(&self, p: IVec2) -> bool { p.cmpge(IVec2::ZERO).all() && p.cmplt(self.size).all() }
    fn set_visible(&mut self, p: IVec2) { self.visible[p.x as usize][p.y as usize] = true; }
    fn dist(&self, a: IVec2, b: IVec2) -> f32 { a.as_vec2().distance(b.as_vec2()) }
}

fn calc_fov(map: &mut Map, p: IVec2) {
    fov::compute(p, 5, map);
}

Modules

Module containing the compute function.

Traits

A trait used by the fov algorithm to calculate the resulting fov.