Skip to main content

MapData

Trait MapData 

Source
pub trait MapData: Hash + Component {
    // Required methods
    fn into_chunk_pos(&self, cell: Cell) -> ChunkPos;
    fn max_chunk_size(&self) -> UVec2;
    fn break_data_vecs_down_into_chunk_data<TileData>(
        &self,
        data: &[Vec<TileData>],
        chunk_pos: ChunkPos,
        max_chunk_size: UVec2,
    ) -> Vec<Vec<TileData>>
       where TileData: Clone + Copy + Sized + Default + Send + Sync + 'static;
    fn break_data_vecs_into_chunks<TileData, MapChunk>(
        &self,
        data: &[Vec<TileData>],
        max_chunk_size: UVec2,
        chunk_settings: MapChunk::ChunkSettings,
    ) -> Vec<Vec<Chunk<MapChunk, TileData>>>
       where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static,
             MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default;
    fn break_hashmap_into_chunks<TileData, MapChunk>(
        &self,
        map_layer: impl MapLayer,
        data: &HashMap<Cell, TileData>,
        map_size: UVec2,
        max_chunk_size: UVec2,
        chunk_settings: MapChunk::ChunkSettings,
    ) -> Vec<Vec<Chunk<MapChunk, TileData>>>
       where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static,
             MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default;

    // Provided method
    fn add_entities_to_layer<TileData, MapChunk>(
        &self,
        map_layer: u32,
        chunks: &mut Vec<Vec<Chunk<MapChunk, TileData>>>,
        entities: &HashMap<Cell, Entity>,
    )
       where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static,
             MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default { ... }
}
Expand description

Trait that must be implemented for a map type. It consists of mandatory functions used in building new maps as well as implementing a way to convert a given Cell into a chunk pos

Required Methods§

Source

fn into_chunk_pos(&self, cell: Cell) -> ChunkPos

Converts a Cell (A position on the map) into a ChunkPos (The position of the chunk that that cell is in)

Source

fn max_chunk_size(&self) -> UVec2

The maximum size that a chunk can be

Source

fn break_data_vecs_down_into_chunk_data<TileData>( &self, data: &[Vec<TileData>], chunk_pos: ChunkPos, max_chunk_size: UVec2, ) -> Vec<Vec<TileData>>
where TileData: Clone + Copy + Sized + Default + Send + Sync + 'static,

Function that breaks a Vec<Vec<TileData>> down into a Vec<Vec<TileData>> of the given ChunkPos chunks data

Source

fn break_data_vecs_into_chunks<TileData, MapChunk>( &self, data: &[Vec<TileData>], max_chunk_size: UVec2, chunk_settings: MapChunk::ChunkSettings, ) -> Vec<Vec<Chunk<MapChunk, TileData>>>
where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static, MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default,

Function that breaks a Vec<Vec<TileData>> into Vec<Vec<Chunk<TileData>>>

This function should:

  • Create new chunks
  • Insert the correct data for each chunk
  • Return a Vec<Vec<Chunk<TileData>>> where each chunk is correctly positioned.
    • Correctly positioned meaning chunk 0:0 contains the tiles for cell positions 0:0 -> 0:max chunk size and max chunk size:0 and so forth for each chunk in order
Source

fn break_hashmap_into_chunks<TileData, MapChunk>( &self, map_layer: impl MapLayer, data: &HashMap<Cell, TileData>, map_size: UVec2, max_chunk_size: UVec2, chunk_settings: MapChunk::ChunkSettings, ) -> Vec<Vec<Chunk<MapChunk, TileData>>>
where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static, MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default,

Provided Methods§

Source

fn add_entities_to_layer<TileData, MapChunk>( &self, map_layer: u32, chunks: &mut Vec<Vec<Chunk<MapChunk, TileData>>>, entities: &HashMap<Cell, Entity>, )
where TileData: Hash + Clone + Copy + Sized + Default + Send + Sync + 'static, MapChunk: ChunkLayer<TileData> + Send + Sync + 'static + Default,

Adds the given hashmap of entities to the map

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§