Skip to main content

TileLayer

Struct TileLayer 

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

A layer of tiles: a grid of square cells in the world, each empty or showing a Tile of the layer’s TileSet.

Cell (0, 0) has its top-left corner at the origin; x grows to the right and y down, as in a TileGrid of the collision crate. The renderer draws a layer in chunks of TileLayer::CHUNK cells a side, those that the view shows, and packs a chunk’s tiles again only after one of them changes.

Implementations§

Source§

impl TileLayer

Source

pub const CHUNK: u32 = 32

The side of a chunk, in cells.

Source

pub fn new(tileset: TileSet, size: UVec2, tile_size: f32, origin: Vec2) -> Self

A layer of size cells, columns by rows, all empty, of tile_size world units a side, with its top-left corner at origin. A layer with no columns or no rows draws nothing.

Cells are placed in f32, exactly up to 2^24 cells a side.

§Panics

If tile_size is not a finite number above 0, or the layer has more cells than memory can count.

Source

pub fn tileset(&self) -> TileSet

The tile set.

Source

pub fn size(&self) -> UVec2

The number of cells: columns by rows.

Source

pub fn tile_size(&self) -> f32

The side of a cell, in world units.

Source

pub fn origin(&self) -> Vec2

The top-left corner of cell (0, 0).

Source

pub fn chunks(&self) -> UVec2

The number of chunks: columns by rows. The last of a row or column may be cut short by the layer’s edge.

Source

pub fn get(&self, cell: IVec2) -> Option<Tile>

The tile of cell: None if it is empty, or outside the layer.

Source

pub fn set(&mut self, cell: IVec2, tile: Option<Tile>)

Shows tile in cell, or empties it with None. The chunk that holds the cell is packed again before it is next drawn, if this changed it.

§Panics

If cell is outside the layer.

Source

pub fn pack_chunk(&self, chunk: UVec2, out: &mut Vec<f32>) -> u32

Appends the instances of the tiles of chunk chunk (its column and row of chunks) to out, row by row, skipping empty cells: TILE_INSTANCE_FLOATS floats each, as the renderer uploads them. Returns how many there are; none for a chunk outside the layer.

The renderer does this for each chunk the view shows that changed since it last did. It is public so that it can be measured.

Trait Implementations§

Source§

impl Clone for TileLayer

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 TileLayer

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.