diff --git a/engine/world_generation/src/generators/mesh_generator.rs b/engine/world_generation/src/generators/mesh_generator.rs index 2ac4f79..722b291 100644 --- a/engine/world_generation/src/generators/mesh_generator.rs +++ b/engine/world_generation/src/generators/mesh_generator.rs @@ -39,6 +39,7 @@ pub fn generate_chunk_mesh(chunk: &MeshChunkData) -> Mesh { // &mut tex, chunk.textures[idx][0], chunk.textures[idx][1], + chunk.overlay_textures[idx], ); } } @@ -63,10 +64,14 @@ fn create_tile( normals: &mut Vec, texture_index: u32, side_texture_index: u32, + side_overlay_texture_index: Option, ) { let uv_offset = Vec2::splat(0.5); let tex_off = Vec2::new(texture_index as f32, 0.); - let side_tex_off = Vec2::new(side_texture_index as f32, 0.); + let side_tex_off = Vec2::new( + pack_texture_data(side_texture_index, side_overlay_texture_index) as f32, + 0., + ); let idx = verts.len() as u32; for i in 0..6 { @@ -278,6 +283,13 @@ fn create_tile_wall( uvs.push((Vec2::new(1., pos.y - height) / TEX_MULTI) + tex_off); } +fn pack_texture_data(texture: u32, overlay: Option) -> u32 { + if let Some(ovr) = overlay { + return texture + (ovr << 5); + } + return texture + (texture << 5); +} + #[cfg(test)] mod tests { @@ -320,7 +332,17 @@ mod tests { //4 side faces let nbors = [2.0, 2.0, 0.0, 0.0, 0.0, 0.0]; - create_tile(Vec3::Y, &nbors, &mut verts, &mut uvs, &mut indices, &mut normals, 3, 7); + create_tile( + Vec3::Y, + &nbors, + &mut verts, + &mut uvs, + &mut indices, + &mut normals, + 3, + 7, + None, + ); assert!(verts.len() == (6 + 4 * 4), "Number of verts don't match"); assert!(uvs.len() == (6 + 4 * 4), "Number of uvs don't match"); diff --git a/engine/world_generation/src/map/chunk.rs b/engine/world_generation/src/map/chunk.rs index 893a4fb..7a81fdb 100644 --- a/engine/world_generation/src/map/chunk.rs +++ b/engine/world_generation/src/map/chunk.rs @@ -1,11 +1,11 @@ use crate::hex_utils::SHORT_DIAGONAL; use bevy::prelude::*; - #[derive(Clone)] pub struct Chunk { pub heights: [f32; Chunk::AREA], pub textures: [[u32; 2]; Chunk::AREA], + pub overlay_textures: [Option; Chunk::AREA], // pub biome_data: [BiomeData; Chunk::AREA], pub biome_id: [usize; Chunk::AREA], pub chunk_offset: IVec2, @@ -18,6 +18,7 @@ impl Default for Chunk { Self { heights: [0.; Chunk::AREA], textures: [[0; 2]; Chunk::AREA], + overlay_textures: [None; Chunk::AREA], // biome_data: [BiomeData::default(); Chunk::AREA], biome_id: [0; Chunk::AREA], chunk_offset: Default::default(), diff --git a/engine/world_generation/src/map/map.rs b/engine/world_generation/src/map/map.rs index 04c7844..c99c504 100644 --- a/engine/world_generation/src/map/map.rs +++ b/engine/world_generation/src/map/map.rs @@ -2,10 +2,7 @@ use bevy::prelude::*; use crate::hex_utils::*; -use super::{ - chunk::Chunk, - mesh_chunk::MeshChunkData, -}; +use super::{chunk::Chunk, mesh_chunk::MeshChunkData}; #[derive(Resource, Clone)] pub struct Map { @@ -41,6 +38,7 @@ impl Map { sealevel: self.sealevel, heights: chunk.heights.clone(), textures: chunk.textures.clone(), + overlay_textures: chunk.overlay_textures.clone(), distance_to_land: self.get_distance_from_land(chunk.chunk_offset, 4), }; } diff --git a/engine/world_generation/src/map/mesh_chunk.rs b/engine/world_generation/src/map/mesh_chunk.rs index 7b6c7f2..834744e 100644 --- a/engine/world_generation/src/map/mesh_chunk.rs +++ b/engine/world_generation/src/map/mesh_chunk.rs @@ -9,6 +9,7 @@ use super::chunk::Chunk; pub struct MeshChunkData { pub heights: [f32; Chunk::AREA], pub textures: [[u32; 2]; Chunk::AREA], + pub overlay_textures: [Option; Chunk::AREA], pub min_height: f32, pub sealevel: f32, pub distance_to_land: [f32; Chunk::AREA], diff --git a/engine/world_generation/src/tile_manager.rs b/engine/world_generation/src/tile_manager.rs index 41d0a3d..24a442a 100644 --- a/engine/world_generation/src/tile_manager.rs +++ b/engine/world_generation/src/tile_manager.rs @@ -29,6 +29,7 @@ pub struct TileAsset { #[serde(skip)] pub texture: String, pub side_texture_id: u32, + pub side_overlay_id: Option, #[serde(skip)] pub side_texture: String, } diff --git a/game/main/assets b/game/main/assets index 3606ca0..67cf2d4 160000 --- a/game/main/assets +++ b/game/main/assets @@ -1 +1 @@ -Subproject commit 3606ca032461db3f8d0a9573af36ce51d90b6352 +Subproject commit 67cf2d46ce29c9c3eb1be22ffa97a94f11a253eb diff --git a/game/main/src/camera_system/components.rs b/game/main/src/camera_system/components.rs index b6efd8c..1830d0b 100644 --- a/game/main/src/camera_system/components.rs +++ b/game/main/src/camera_system/components.rs @@ -21,7 +21,7 @@ impl Default for PhosCamera { max_height: 420., speed: 100., pan_speed: Vec2::new(0.8, 0.5), - zoom_speed: 20., + zoom_speed: 200., min_angle: (20. as f32).to_radians(), max_angle: 1., } diff --git a/game/main/src/utlis/chunk_utils.rs b/game/main/src/utlis/chunk_utils.rs index 942e81d..9497ec2 100644 --- a/game/main/src/utlis/chunk_utils.rs +++ b/game/main/src/utlis/chunk_utils.rs @@ -47,6 +47,7 @@ pub fn paint_chunk( let tile_handle = mapper.unwrap().sample_tile(height); let tile = tiles.get(tile_handle).unwrap(); chunk.textures[idx] = [tile.texture_id, tile.side_texture_id]; + chunk.overlay_textures[idx] = tile.side_overlay_id; } } }