Add tile graphic

This commit is contained in:
crumblingstatue 2023-04-01 21:01:14 +02:00
parent d78726eb5b
commit fbc7e35f9e
11 changed files with 812 additions and 20 deletions

View file

@ -1,4 +1,5 @@
use fnv::FnvHashMap;
use rand::{thread_rng, Rng};
type ChunkPosScalar = i16;
@ -12,6 +13,14 @@ pub struct World {
chunks: FnvHashMap<ChunkPos, Chunk>,
}
impl Default for World {
fn default() -> Self {
Self {
chunks: Default::default(),
}
}
}
const CHUNK_EXTENT: u16 = 256;
const CHUNK_N_BLOCKS: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
@ -21,8 +30,20 @@ pub struct Chunk {
blocks: ChunkBlocks,
}
impl Chunk {
pub fn new_rand() -> Self {
let mut rng = thread_rng();
let mut blocks = [Block { id: 0 }; CHUNK_N_BLOCKS];
for b in &mut blocks {
b.id = rng.gen();
}
Self { blocks }
}
}
type BlockId = u16;
#[derive(Clone, Copy)]
pub struct Block {
id: BlockId,
}