separate blocks into common

This commit is contained in:
griffi-gh 2023-01-30 02:45:35 +01:00
parent 6d41a5717b
commit 80be3673a2
7 changed files with 21 additions and 28 deletions

View file

@ -1,3 +1,3 @@
fn main() { fn main() {
println!("Hello, world!");
} }

View file

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
strum = { version = "0.24", features = ["derive"] }

11
kubi-shared/src/blocks.rs Normal file
View file

@ -0,0 +1,11 @@
use strum::EnumIter;
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)]
#[repr(u8)]
pub enum Block {
Air,
Stone,
Dirt,
Grass,
Sand,
}

View file

@ -1,14 +1 @@
pub fn add(left: usize, right: usize) -> usize { pub mod blocks;
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View file

@ -1,17 +1,12 @@
use strum::EnumIter; use strum::EnumIter;
use crate::prefabs::BlockTexture; use crate::prefabs::BlockTexture;
pub use kubi_shared::blocks::Block;
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)] pub trait BlockDescriptorSource {
#[repr(u8)] fn descriptor(self) -> BlockDescriptor;
pub enum Block {
Air,
Stone,
Dirt,
Grass,
Sand,
} }
impl Block { impl BlockDescriptorSource for Block {
pub const fn descriptor(self) -> BlockDescriptor { fn descriptor(self) -> BlockDescriptor {
match self { match self {
Self::Air => BlockDescriptor { Self::Air => BlockDescriptor {
name: "air", name: "air",

View file

@ -1,7 +1,7 @@
use strum::{EnumIter, IntoEnumIterator}; use strum::{EnumIter, IntoEnumIterator};
use glam::{Vec3A, vec3a, IVec3, ivec3}; use glam::{Vec3A, vec3a, IVec3, ivec3};
use std::mem::discriminant; use std::mem::discriminant;
use super::{chunk::CHUNK_SIZE, block::{Block, RenderType}}; use super::{chunk::CHUNK_SIZE, block::{Block, RenderType, BlockDescriptorSource}};
use crate::rendering::world::ChunkVertex; use crate::rendering::world::ChunkVertex;
pub mod data; pub mod data;

View file

@ -1,7 +1,6 @@
use glam::{Vec3, IVec3}; use glam::{Vec3, IVec3};
use shipyard::{View, Component, ViewMut, IntoIter, UniqueView}; use shipyard::{View, Component, ViewMut, IntoIter, UniqueView};
use crate::transform::Transform; use crate::{transform::Transform, world::block::BlockDescriptorSource};
use super::{ChunkStorage, block::Block}; use super::{ChunkStorage, block::Block};
const RAYCAST_STEP: f32 = 0.25; const RAYCAST_STEP: f32 = 0.25;