Skip to main content

NavMesh

Struct NavMesh 

Source
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§

Source§

impl NavMesh

Source

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.

Source

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.

Source

pub fn params(&self) -> &NavMeshParams

The mesh parameters.

Source

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.

Source

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.

Source

pub fn tile_at(&self, x: i32, y: i32) -> Option<&TileData>

The tile in grid cell (x, y).

Source

pub fn tiles(&self) -> impl Iterator<Item = (u64, &TileData)>

The tiles with their references, in slot order.

Source

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).

Source

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§

Source§

impl Clone for NavMesh

Source§

fn clone(&self) -> NavMesh

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 NavMesh

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.