test
This commit is contained in:
@@ -39,6 +39,7 @@ pub fn generate_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
|||||||
// &mut tex,
|
// &mut tex,
|
||||||
chunk.textures[idx][0],
|
chunk.textures[idx][0],
|
||||||
chunk.textures[idx][1],
|
chunk.textures[idx][1],
|
||||||
|
chunk.overlay_textures[idx],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,10 +64,14 @@ fn create_tile(
|
|||||||
normals: &mut Vec<Vec3>,
|
normals: &mut Vec<Vec3>,
|
||||||
texture_index: u32,
|
texture_index: u32,
|
||||||
side_texture_index: u32,
|
side_texture_index: u32,
|
||||||
|
side_overlay_texture_index: Option<u32>,
|
||||||
) {
|
) {
|
||||||
let uv_offset = Vec2::splat(0.5);
|
let uv_offset = Vec2::splat(0.5);
|
||||||
let tex_off = Vec2::new(texture_index as f32, 0.);
|
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;
|
let idx = verts.len() as u32;
|
||||||
for i in 0..6 {
|
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);
|
uvs.push((Vec2::new(1., pos.y - height) / TEX_MULTI) + tex_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pack_texture_data(texture: u32, overlay: Option<u32>) -> u32 {
|
||||||
|
if let Some(ovr) = overlay {
|
||||||
|
return texture + (ovr << 5);
|
||||||
|
}
|
||||||
|
return texture + (texture << 5);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@@ -320,7 +332,17 @@ mod tests {
|
|||||||
//4 side faces
|
//4 side faces
|
||||||
let nbors = [2.0, 2.0, 0.0, 0.0, 0.0, 0.0];
|
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!(verts.len() == (6 + 4 * 4), "Number of verts don't match");
|
||||||
assert!(uvs.len() == (6 + 4 * 4), "Number of uvs don't match");
|
assert!(uvs.len() == (6 + 4 * 4), "Number of uvs don't match");
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::hex_utils::SHORT_DIAGONAL;
|
use crate::hex_utils::SHORT_DIAGONAL;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Chunk {
|
pub struct Chunk {
|
||||||
pub heights: [f32; Chunk::AREA],
|
pub heights: [f32; Chunk::AREA],
|
||||||
pub textures: [[u32; 2]; Chunk::AREA],
|
pub textures: [[u32; 2]; Chunk::AREA],
|
||||||
|
pub overlay_textures: [Option<u32>; Chunk::AREA],
|
||||||
// pub biome_data: [BiomeData; Chunk::AREA],
|
// pub biome_data: [BiomeData; Chunk::AREA],
|
||||||
pub biome_id: [usize; Chunk::AREA],
|
pub biome_id: [usize; Chunk::AREA],
|
||||||
pub chunk_offset: IVec2,
|
pub chunk_offset: IVec2,
|
||||||
@@ -18,6 +18,7 @@ impl Default for Chunk {
|
|||||||
Self {
|
Self {
|
||||||
heights: [0.; Chunk::AREA],
|
heights: [0.; Chunk::AREA],
|
||||||
textures: [[0; 2]; Chunk::AREA],
|
textures: [[0; 2]; Chunk::AREA],
|
||||||
|
overlay_textures: [None; Chunk::AREA],
|
||||||
// biome_data: [BiomeData::default(); Chunk::AREA],
|
// biome_data: [BiomeData::default(); Chunk::AREA],
|
||||||
biome_id: [0; Chunk::AREA],
|
biome_id: [0; Chunk::AREA],
|
||||||
chunk_offset: Default::default(),
|
chunk_offset: Default::default(),
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
use crate::hex_utils::*;
|
use crate::hex_utils::*;
|
||||||
|
|
||||||
use super::{
|
use super::{chunk::Chunk, mesh_chunk::MeshChunkData};
|
||||||
chunk::Chunk,
|
|
||||||
mesh_chunk::MeshChunkData,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct Map {
|
pub struct Map {
|
||||||
@@ -41,6 +38,7 @@ impl Map {
|
|||||||
sealevel: self.sealevel,
|
sealevel: self.sealevel,
|
||||||
heights: chunk.heights.clone(),
|
heights: chunk.heights.clone(),
|
||||||
textures: chunk.textures.clone(),
|
textures: chunk.textures.clone(),
|
||||||
|
overlay_textures: chunk.overlay_textures.clone(),
|
||||||
distance_to_land: self.get_distance_from_land(chunk.chunk_offset, 4),
|
distance_to_land: self.get_distance_from_land(chunk.chunk_offset, 4),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use super::chunk::Chunk;
|
|||||||
pub struct MeshChunkData {
|
pub struct MeshChunkData {
|
||||||
pub heights: [f32; Chunk::AREA],
|
pub heights: [f32; Chunk::AREA],
|
||||||
pub textures: [[u32; 2]; Chunk::AREA],
|
pub textures: [[u32; 2]; Chunk::AREA],
|
||||||
|
pub overlay_textures: [Option<u32>; Chunk::AREA],
|
||||||
pub min_height: f32,
|
pub min_height: f32,
|
||||||
pub sealevel: f32,
|
pub sealevel: f32,
|
||||||
pub distance_to_land: [f32; Chunk::AREA],
|
pub distance_to_land: [f32; Chunk::AREA],
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub struct TileAsset {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub texture: String,
|
pub texture: String,
|
||||||
pub side_texture_id: u32,
|
pub side_texture_id: u32,
|
||||||
|
pub side_overlay_id: Option<u32>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub side_texture: String,
|
pub side_texture: String,
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule game/main/assets updated: 3606ca0324...67cf2d46ce
@@ -21,7 +21,7 @@ impl Default for PhosCamera {
|
|||||||
max_height: 420.,
|
max_height: 420.,
|
||||||
speed: 100.,
|
speed: 100.,
|
||||||
pan_speed: Vec2::new(0.8, 0.5),
|
pan_speed: Vec2::new(0.8, 0.5),
|
||||||
zoom_speed: 20.,
|
zoom_speed: 200.,
|
||||||
min_angle: (20. as f32).to_radians(),
|
min_angle: (20. as f32).to_radians(),
|
||||||
max_angle: 1.,
|
max_angle: 1.,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ pub fn paint_chunk(
|
|||||||
let tile_handle = mapper.unwrap().sample_tile(height);
|
let tile_handle = mapper.unwrap().sample_tile(height);
|
||||||
let tile = tiles.get(tile_handle).unwrap();
|
let tile = tiles.get(tile_handle).unwrap();
|
||||||
chunk.textures[idx] = [tile.texture_id, tile.side_texture_id];
|
chunk.textures[idx] = [tile.texture_id, tile.side_texture_id];
|
||||||
|
chunk.overlay_textures[idx] = tile.side_overlay_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user