fix issues with refactor

This commit is contained in:
griffi-gh 2023-01-18 01:24:47 +01:00
parent 365ab73643
commit ae488d090e
5 changed files with 40 additions and 25 deletions

View file

@ -78,3 +78,19 @@ impl Textures {
}
}
}
#[derive(Clone, Copy, Debug)]
#[repr(u8)]
pub enum BlockTexture {
Stone = 0,
Dirt = 1,
GrassTop = 2,
GrassSide = 3,
Sand = 4,
Bedrock = 5,
Tree = 6,
TreeTop = 7,
Leaf = 8,
Torch = 9,
TallGrass = 10,
}

View file

@ -1,5 +1,9 @@
use strum::{EnumIter, IntoEnumIterator};
use crate::game::items::Item;
use crate::game::{
items::Item,
assets::textures::BlockTexture,
};
#[derive(Clone, Copy, Debug)]
pub enum CollisionType {
@ -18,15 +22,15 @@ pub enum RenderType {
#[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,
pub top: BlockTexture,
pub bottom: BlockTexture,
pub left: BlockTexture,
pub right: BlockTexture,
pub back: BlockTexture,
pub front: BlockTexture,
}
impl BlockTextures {
pub const fn all(tex: u8) -> Self {
pub const fn all(tex: BlockTexture) -> Self {
Self {
top: tex,
bottom: tex,
@ -36,7 +40,7 @@ impl BlockTextures {
front: tex,
}
}
pub const fn top_sides_bottom(top: u8, sides: u8, bottom: u8) -> Self {
pub const fn top_sides_bottom(top: BlockTexture, sides: BlockTexture, bottom: BlockTexture) -> Self {
Self {
top,
bottom,
@ -65,7 +69,7 @@ impl BlockDescriptor {
id: "default",
collision: Some(CollisionType::Solid),
raycast_collision: true,
render: Some((RenderType::OpaqueBlock, BlockTextures::all(0))),
render: Some((RenderType::OpaqueBlock, BlockTextures::all(BlockTexture::Stone))),
item: None
}
}
@ -105,7 +109,7 @@ impl Block {
id: "stone",
collision: Some(CollisionType::Solid),
raycast_collision: true,
render: Some((RenderType::OpaqueBlock, BlockTextures::all(1))),
render: Some((RenderType::OpaqueBlock, BlockTextures::all(BlockTexture::Stone))),
item: Some(Item::StoneBlock)
},
Self::Dirt => BlockDescriptor {
@ -113,7 +117,7 @@ impl Block {
id: "dirt",
collision: Some(CollisionType::Solid),
raycast_collision: true,
render: Some((RenderType::OpaqueBlock, BlockTextures::all(2))),
render: Some((RenderType::OpaqueBlock, BlockTextures::all(BlockTexture::Dirt))),
item: Some(Item::DirtBlock)
},
Self::Grass => BlockDescriptor {
@ -121,7 +125,7 @@ impl Block {
id: "grass",
collision: Some(CollisionType::Solid),
raycast_collision: true,
render: Some((RenderType::OpaqueBlock, BlockTextures::top_sides_bottom(0, 3, 2))),
render: Some((RenderType::OpaqueBlock, BlockTextures::top_sides_bottom(BlockTexture::GrassTop, BlockTexture::GrassSide, BlockTexture::Dirt))),
item: Some(Item::DirtBlock)
},
Self::Sand => BlockDescriptor {
@ -129,7 +133,7 @@ impl Block {
id: "sand",
collision: Some(CollisionType::Solid),
raycast_collision: true,
render: Some((RenderType::OpaqueBlock, BlockTextures::all(4))), //this is not a sand tex
render: Some((RenderType::OpaqueBlock, BlockTextures::all(BlockTexture::Sand))), //this is not a sand tex
item: Some(Item::StoneBlock)
}
}

View file

@ -7,12 +7,13 @@ in uint tex_index;
out vec2 v_uv;
out vec3 v_normal;
flat out uint v_tex_index;
uniform vec3 position_offset;
uniform vec2 position_offset;
uniform mat4 perspective;
uniform mat4 view;
void main() {
v_normal = normal;
v_tex_index = tex_index;
gl_Position = perspective * view * vec4(position, 1.0) * vec4(position_offset, 1.0);
v_uv = uv;
gl_Position = perspective * view * (vec4(position, 1.0) + vec4(position_offset.x, 0., position_offset.y, 0.));
}

View file

@ -86,13 +86,7 @@ impl World {
&mesh.index_buffer,
&programs.chunk,
&uniform! {
model: [
[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
//[0., 0., 0., 1.0_f32]
[(position.x * CHUNK_SIZE as i32) as f32, 0., (position.y * CHUNK_SIZE as i32) as f32, 1.0_f32]
],
position_offset: (position.as_vec2() * CHUNK_SIZE as f32).to_array(),
view: view,
perspective: perspective,
tex: Sampler(&assets.textures.blocks, sampler)

View file

@ -120,7 +120,7 @@ pub fn generate_mesh(position: IVec2, chunk_data: ChunkData, neighbors: [ChunkDa
};
if show {
let texures = descriptor.render.unwrap().1;
let texture_index = match face {
let block_texture = match face {
CubeFace::Top => texures.top,
CubeFace::Front => texures.front,
CubeFace::Left => texures.left,
@ -128,7 +128,7 @@ pub fn generate_mesh(position: IVec2, chunk_data: ChunkData, neighbors: [ChunkDa
CubeFace::Back => texures.back,
CubeFace::Bottom => texures.bottom,
};
builer.add_face(face, coord, texture_index);
builer.add_face(face, coord, block_texture as u8);
}
}
}