pub struct NavMesh { /* private fields */ }Expand description
A tiled Detour navigation mesh (dtNavMesh) with 64-bit polygon references: salt 16 bits, tile
28 bits, polygon 20 bits (spec 8.1).
Tiles live in slots. All slots start with salt 1 and slot 0 is allocated first; removing a tile bumps the salt of its slot and puts the slot at the head of the free list. There is one layer (0) per grid cell.
Implementations§
Sourcepub fn new(params: NavMeshParams) -> Result<Self>
pub fn new(params: NavMeshParams) -> Result<Self>
Creates an empty mesh (dtNavMesh::init): every slot has salt 1 and slot 0 is allocated
first.
§Errors
Returns an error when max_tiles is not positive or exceeds what the 28-bit tile field of a
polygon reference can address.
Sourcepub fn from_set(set: &NavMeshSet) -> Result<Self>
pub fn from_set(set: &NavMeshSet) -> Result<Self>
Builds a mesh from a set file: the tiles are added in file order, each into the slot and with the salt of its stored reference. Stored links are ignored and recomputed (spec 2.3).
§Errors
Returns an error for invalid parameters or a tile that NavMesh::set_tile’s checks
reject: wrong magic or version, an inconsistent header, indices out of range, an occupied
grid cell, or a slot that is out of range or already used.
Sourcepub fn params(&self) -> &NavMeshParams
pub fn params(&self) -> &NavMeshParams
The mesh parameters.
Sourcepub fn set_tile(&mut self, data: TileData) -> Result<u64>
pub fn set_tile(&mut self, data: TileData) -> Result<u64>
Adds a tile, replacing the one in the same grid cell (spec 8.2). A replacement keeps its slot and gets the salt plus one. Returns the reference of the tile.
§Errors
Returns an error, leaving the mesh unchanged, when the tile is rejected (see
NavMesh::from_set) or no slot is free.
Sourcepub fn remove_tile_at(&mut self, x: i32, y: i32) -> bool
pub fn remove_tile_at(&mut self, x: i32, y: i32) -> bool
Removes the tile in grid cell (x, y) and unlinks its neighbours. Returns whether there
was one.
Sourcepub fn tiles(&self) -> impl Iterator<Item = (u64, &TileData)>
pub fn tiles(&self) -> impl Iterator<Item = (u64, &TileData)>
The tiles with their references, in slot order.
Sourcepub fn to_set(&self, tiles_x: i32, tiles_z: i32) -> NavMeshSet
pub fn to_set(&self, tiles_x: i32, tiles_z: i32) -> NavMeshSet
The mesh as a set file for a tiles_x by tiles_z grid: the tiles in slot order with
their references and record padding (kept from from_set, 0 for tiles added with set_tile).
Sourcepub fn into_set(self, tiles_x: i32, tiles_z: i32) -> NavMeshSet
pub fn into_set(self, tiles_x: i32, tiles_z: i32) -> NavMeshSet
Like NavMesh::to_set, but consumes the mesh and moves the tiles instead of cloning them,
so the final save of a large run does not double the peak memory.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more