Skip to main content

FlowFieldGrid

Struct FlowFieldGrid 

Source
pub struct FlowFieldGrid { /* private fields */ }
Expand description

Integration and flow-vector grid enabling O(1) steering lookup for thousands of crowd units.

Implementations§

Source§

impl FlowFieldGrid

Integration and flow-vector construction and O(1) lookup for FlowFieldGrid.

Source

pub fn new(width: usize, height: usize, cell_size: f32, origin: Vec2) -> Self

Creates a walkable FlowFieldGrid with uniform cost 1 per cell.

§Arguments
  • usize - Number of columns.
  • usize - Number of rows.
  • f32 - World-space cell width and height (clamped to >= 1e-4).
  • Vec2 - World-space origin (min_x, min_y) of cell (0, 0).
§Returns
  • Self - Initialized flow field grid.
Source

pub fn set_cost(&mut self, coord: GridCoord, cost: u8)

Sets the traversal cost of coord (0 clamped to 1, 255 marks impassable).

§Arguments
  • GridCoord - Cell coordinate to modify.
  • u8 - Cost byte (1..=254 walkable, 255 wall).
Source

pub fn set_blocked(&mut self, coord: GridCoord, blocked: bool)

Marks coord as impassable (blocked == true) or normal cost 1 (blocked == false).

§Arguments
  • GridCoord - Cell coordinate to update.
  • bool - Whether the cell is a solid obstacle.
Source

pub fn build_for_goals(&mut self, goals: &[GridCoord])

Computes Dijkstra integration distances and smooth downhill flow vectors toward goals.

§Arguments
  • &[GridCoord] - One or more goal cell coordinates.
Source

pub fn direction_at_cell(&self, coord: GridCoord) -> Vec2

Returns the unit flow direction at integer cell coord in O(1) time.

§Arguments
  • GridCoord - Cell coordinate.
§Returns
  • Vec2 - Unit flow direction, or (0, 0) at goals, walls, or out of bounds.
Source

pub fn integration_at(&self, coord: GridCoord) -> u32

Returns the integration distance at coord (u32::MAX if unreachable or out of bounds).

§Arguments
  • GridCoord - Cell coordinate.
§Returns
  • u32 - Integration distance to the nearest goal.
Source

pub fn world_to_cell(&self, world_pos: Vec2) -> Option<GridCoord>

Converts a world position to its enclosing GridCoord if within bounds.

§Arguments
  • Vec2 - World-space 2D position.
§Returns
  • Option<GridCoord> - Containing cell coordinate if inside grid extents.
Source

pub fn cell_center(&self, coord: GridCoord) -> Vec2

Converts a GridCoord into the world-space center of that cell.

§Arguments
  • GridCoord - Cell coordinate.
§Returns
  • Vec2 - World-space center of the cell.
Source

pub fn sample_direction(&self, world_pos: Vec2) -> Vec2

Samples the flow direction at continuous world position world_pos in O(1) time.

§Arguments
  • Vec2 - World-space agent position.
§Returns
  • Vec2 - Unit steering direction toward the nearest goal.
Source§

impl FlowFieldGrid

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_width(&self) -> usize

Source

pub fn get_mut_width(&mut self) -> &mut usize

Source

pub fn set_width(&mut self, val: usize) -> &mut Self

Source

pub fn get_height(&self) -> usize

Source

pub fn get_mut_height(&mut self) -> &mut usize

Source

pub fn set_height(&mut self, val: usize) -> &mut Self

Source

pub fn get_cell_size(&self) -> f32

Source

pub fn get_mut_cell_size(&mut self) -> &mut f32

Source

pub fn set_cell_size(&mut self, val: f32) -> &mut Self

Source

pub fn get_origin(&self) -> Vec2

Source

pub fn get_mut_origin(&mut self) -> &mut Vec2

Source

pub fn set_origin(&mut self, val: Vec2) -> &mut Self

Source

pub fn get_costs(&self) -> &Vec<u8> ⓘ

Source

pub fn get_mut_costs(&mut self) -> &mut Vec<u8> ⓘ

Source

pub fn set_costs(&mut self, val: Vec<u8>) -> &mut Self

Source

pub fn get_integration(&self) -> &Vec<u32>

Source

pub fn get_mut_integration(&mut self) -> &mut Vec<u32>

Source

pub fn set_integration(&mut self, val: Vec<u32>) -> &mut Self

Source

pub fn get_flow_vectors(&self) -> &Vec<Vec2>

Source

pub fn get_mut_flow_vectors(&mut self) -> &mut Vec<Vec2>

Source

pub fn set_flow_vectors(&mut self, val: Vec<Vec2>) -> &mut Self

Trait Implementations§

Source§

impl Clone for FlowFieldGrid

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlowFieldGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.