move block to shared

This commit is contained in:
griffi-gh 2023-02-15 22:07:47 +01:00
parent 0de70ed1b7
commit c865835e8d
13 changed files with 55 additions and 49 deletions

View file

@ -1,5 +1,35 @@
use crate::prefabs::BlockTexture;
pub use kubi_shared::blocks::Block;
use bincode::{Encode, Decode};
use strum::EnumIter;
#[derive(Clone, Copy, Debug, EnumIter)]
#[repr(u8)]
pub enum BlockTexture {
Stone,
Dirt,
GrassTop,
GrassSide,
Sand,
Bedrock,
Wood,
WoodTop,
Leaf,
Torch,
TallGrass,
Snow,
GrassSideSnow,
Cobblestone,
}
#[derive(Encode, Decode, Clone, Copy, Debug, PartialEq, Eq, EnumIter)]
#[repr(u8)]
pub enum Block {
Air,
Stone,
Dirt,
Grass,
Sand,
Cobblestone,
}
pub trait BlockDescriptorSource {
fn descriptor(self) -> BlockDescriptor;
@ -92,6 +122,13 @@ impl CubeTexture {
}
}
#[derive(Clone, Copy, Debug)]
struct CrossTexture {
pub a: BlockTexture,
pub b: BlockTexture,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CollisionType {
None,
@ -101,5 +138,6 @@ pub enum CollisionType {
#[derive(Clone, Copy, Debug)]
pub enum RenderType {
None,
SolidBlock(CubeTexture)
SolidBlock(CubeTexture),
CrossShape,
}

View file

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

View file

@ -1,4 +1,4 @@
use crate::blocks::Block;
use crate::block::Block;
pub const CHUNK_SIZE: usize = 32;
pub type BlockData = Box<[[[Block; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]>;

View file

@ -1,4 +1,4 @@
pub mod blocks;
pub mod block;
pub mod networking;
pub mod worldgen;
pub mod chunk;

View file

@ -2,7 +2,7 @@ use glam::{IVec3, ivec3};
use bracket_noise::prelude::*;
use crate::{
chunk::{BlockData, CHUNK_SIZE},
blocks::Block
block::Block
};
fn mountain_ramp(mut x: f32) -> f32 {

View file

@ -1,7 +1,8 @@
use shipyard::{UniqueViewMut, UniqueView, View, IntoIter, ViewMut, EntitiesViewMut};
use kubi_shared::block::Block;
use crate::{
player::MainPlayer,
world::{raycast::LookingAtBlock, block::Block, queue::{BlockUpdateQueue, BlockUpdateEvent}},
world::{raycast::LookingAtBlock, queue::{BlockUpdateQueue, BlockUpdateEvent}},
input::{Inputs, PrevInputs},
events::{EventComponent, player_actions::PlayerActionEvent},
};

View file

@ -1,8 +1,7 @@
use shipyard::{Component, View, ViewMut, EntitiesViewMut, IntoIter, track};
use glam::{IVec3, Quat, Vec3};
use kubi_shared::block::Block;
use crate::{
world::block::Block,
player::MainPlayer,
transform::Transform
};

View file

@ -1,6 +1,6 @@
use shipyard::{NonSendSync, UniqueView, Unique, AllStoragesView};
use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program};
use strum::EnumIter;
use kubi_shared::block::{Block, BlockTexture};
use crate::rendering::Renderer;
mod texture;
@ -13,24 +13,6 @@ pub trait AssetPaths {
fn file_name(self) -> &'static str;
}
#[derive(Clone, Copy, Debug, EnumIter)]
#[repr(u8)]
pub enum BlockTexture {
Stone,
Dirt,
GrassTop,
GrassSide,
Sand,
Bedrock,
Wood,
WoodTop,
Leaf,
Torch,
TallGrass,
Snow,
GrassSideSnow,
Cobblestone,
}
impl AssetPaths for BlockTexture {
fn file_name(self) -> &'static str {
match self {

View file

@ -110,7 +110,6 @@ pub fn draw_world(
}
}
//this doesn't use culling!
pub fn draw_current_chunk_border(
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
player: View<MainPlayer>,

View file

@ -4,10 +4,9 @@ use glam::IVec3;
use hashbrown::HashMap;
use anyhow::{Result, Context};
pub use kubi_shared::worldgen;
pub use kubi_shared::{worldgen, block::Block};
pub mod chunk;
pub mod block;
pub mod tasks;
pub mod loading;
pub mod mesh;
@ -15,7 +14,6 @@ pub mod neighbors;
pub mod raycast;
pub mod queue;
use block::Block;
use chunk::{Chunk, ChunkMesh, CHUNK_SIZE};
use tasks::ChunkTaskManager;
use queue::BlockUpdateQueue;

View file

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

View file

@ -1,5 +1,5 @@
use glam::{IVec3, ivec3};
use kubi_shared::{blocks::Block, chunk::CHUNK_SIZE};
use kubi_shared::{block::Block, chunk::CHUNK_SIZE};
use shipyard::{UniqueViewMut, Unique};
use super::ChunkStorage;

View file

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