From f7ad96b03d149befbe5a39962264816dea277f7b Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 16 Jan 2023 02:42:50 +0100 Subject: [PATCH] wip, doesnt compile --- src/game.rs | 5 +- src/game/blocks.rs | 126 +++++++++++++++++++++++++++++++++++++++++ src/game/chunk.rs | 3 + src/game/controller.rs | 1 + src/game/items.rs | 9 +++ src/game/world.rs | 3 + 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/game/blocks.rs create mode 100644 src/game/chunk.rs create mode 100644 src/game/items.rs create mode 100644 src/game/world.rs diff --git a/src/game.rs b/src/game.rs index a69fcac..c33e694 100644 --- a/src/game.rs +++ b/src/game.rs @@ -10,13 +10,16 @@ mod display; mod shaders; mod camera; mod controller; +mod world; +mod chunk; +mod blocks; +mod items; use assets::Assets; use display::init_display; use shaders::{Programs, chunk::Vertex as ChunkVertex}; use camera::Camera; use controller::Controls; - struct State { pub camera: Camera, pub controls: Controls, diff --git a/src/game/blocks.rs b/src/game/blocks.rs new file mode 100644 index 0000000..34c662b --- /dev/null +++ b/src/game/blocks.rs @@ -0,0 +1,126 @@ +use crate::game::items::Item; + +#[derive(Clone, Copy, Debug)] +pub enum CollisionType { + Solid, + Liquid, + Ladder, +} + +#[derive(Clone, Copy, Debug)] +pub enum RenderType { + OpaqueBlock, + TranslucentBlock, + TranslucentLiquid, + CrossShape +} + +#[derive(Clone, Copy, Debug)] +pub struct BlockTextures { + pub top: u8, + pub bottom: u8, + pub left: u8, + pub right: u8, + pub back: u8, + pub front: u8, +} +impl BlockTextures { + pub const fn all(tex: u8) -> Self { + Self { + top: tex, + bottom: tex, + left: tex, + right: tex, + back: tex, + front: tex, + } + } + pub const fn top_sides_bottom(top: u8, sides: u8, bottom: u8) -> Self { + Self { + top, + bottom, + left: sides, + right: sides, + back: sides, + front: sides, + } + } +} + +#[derive(Clone, Copy, Debug)] +pub struct BlockDescriptor { + pub name: &'static str, + pub id: &'static str, + pub collision: Option, + pub raycast_collision: bool, + pub render: Option<(RenderType, BlockTextures)>, + pub item: Option, +} +impl BlockDescriptor { + //Not using the Default trait because this function has to be const! + pub const fn default() -> Self { + Self { + name: "default", + id: "default", + collision: Some(CollisionType::Solid), + raycast_collision: true, + render: Some((RenderType::OpaqueBlock, BlockTextures::all(0))), + item: None + } + } +} + +#[derive(Clone, Copy, Debug)] +pub enum Block { + Air, + Stone, + Dirt, + Grass, + Sand, +} +impl Block { + pub const fn get_by_id(id: &str) -> Option { + Some(match id { + "air" => Self::Air, + "stone" => Self::Stone, + _ => { return None }, + }) + } + pub const fn descriptor(self) -> BlockDescriptor { + match self { + Self::Air => BlockDescriptor { + name: "Air", + id: "air", + collision: None, + raycast_collision: false, + render: None, + item: None, + }, + Self::Stone => BlockDescriptor { + name: "Stone", + id: "stone", + collision: Some(CollisionType::Solid), + raycast_collision: true, + render: Some((RenderType::OpaqueBlock, BlockTextures::all(1))), + item: Some(Item::StoneBlock) + }, + Self::Dirt => BlockDescriptor { + name: "Dirt", + id: "dirt", + collision: Some(CollisionType::Solid), + raycast_collision: true, + render: Some((RenderType::OpaqueBlock, BlockTextures::all(2))), + item: Some(Item::DirtBlock) + }, + Self::Grass => BlockDescriptor { + name: "Grass", + id: "grass", + collision: Some(CollisionType::Solid), + raycast_collision: true, + render: Some((RenderType::OpaqueBlock, BlockTextures::top_sides_bottom(0, 3, 2))), + item: Some(Item::DirtBlock) + }, + _ => unimplemented!() + } + } +} diff --git a/src/game/chunk.rs b/src/game/chunk.rs new file mode 100644 index 0000000..b33a9ea --- /dev/null +++ b/src/game/chunk.rs @@ -0,0 +1,3 @@ +pub struct Chunk { + +} diff --git a/src/game/controller.rs b/src/game/controller.rs index 39f345c..7a2a58c 100644 --- a/src/game/controller.rs +++ b/src/game/controller.rs @@ -39,6 +39,7 @@ pub struct Controls { pub sensitivity: f32, } impl Controls { + //TODO locking controls pub fn lock(&mut self) { todo!() } diff --git a/src/game/items.rs b/src/game/items.rs new file mode 100644 index 0000000..0028d1c --- /dev/null +++ b/src/game/items.rs @@ -0,0 +1,9 @@ +//TODO items + +#[derive(Clone, Copy, Debug)] +pub enum Item { + StoneBlock, + DirtBlock, + GrassBlock, + SandBlock, +} diff --git a/src/game/world.rs b/src/game/world.rs new file mode 100644 index 0000000..cc73959 --- /dev/null +++ b/src/game/world.rs @@ -0,0 +1,3 @@ +pub struct World { + chunks: Vec<()> +}