internally use enum instead of u16

This commit is contained in:
zoe 2022-05-08 14:06:42 +02:00
parent 93fa683319
commit 3c5bbd204e
3 changed files with 10 additions and 10 deletions

Binary file not shown.

View file

@ -6,13 +6,13 @@ pub struct World {
xsize: usize,
ysize: usize,
zsize: usize,
tiles: Vec<Vec<Vec<u16>>>,
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
}
impl World {
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16{
//TODO: error handling, or maybe just do that in godot
self.tiles[x][y][z]
self.tiles[x][y][z] as u16
}
pub fn generate(&mut self) -> Vector3Array{
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
@ -21,7 +21,7 @@ impl World {
for y in 0..self.ysize {
for z in 0..self.zsize {
ret.push(Vector3::new(x as f32, y as f32, z as f32));
self.tiles[x][y][z] = tiles::Tiletypes::Dirt as u16;
self.tiles[x][y][z] = tiles::Tiletypes::Dirt;
}
}
}
@ -37,14 +37,14 @@ impl World {
}
}
fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec<Vec<Vec<u16>>> {
let mut zvec: Vec<u16> = Vec::with_capacity(zsize);
zvec.resize(zsize, 0);
fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec<Vec<Vec<tiles::Tiletypes>>> {
let mut zvec: Vec<tiles::Tiletypes> = Vec::with_capacity(zsize);
zvec.resize(zsize, tiles::Tiletypes::Air);
let mut yvec: Vec<Vec<u16>> = Vec::with_capacity(ysize);
let mut yvec: Vec<Vec<tiles::Tiletypes>> = Vec::with_capacity(ysize);
yvec.resize(ysize, zvec.clone());
let mut xvec: Vec<Vec<Vec<u16>>> = Vec::with_capacity(xsize);
let mut xvec: Vec<Vec<Vec<tiles::Tiletypes>>> = Vec::with_capacity(xsize);
xvec.resize(ysize, yvec.clone());
yvec.push(zvec);

View file

@ -1,8 +1,8 @@
use derive_builder::Builder;
use strum::{AsRefStr, EnumDiscriminants, EnumIter, FromRepr};
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone)]
#[repr(u16)]
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy)]
#[repr(u8)]
pub enum Tiletypes {
Air,
Water,