save tile texture id into map
This commit is contained in:
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::tile_mapper::TileMapperAsset;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
|
||||
#[derive(Serialize, Deserialize, Debug, TypePath, Asset, Clone)]
|
||||
pub struct BiomePainterAsset {
|
||||
#[serde(skip)]
|
||||
pub biomes: Vec<Handle<TileMapperAsset>>,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use bevy::math::IVec2;
|
||||
use bevy::prelude::{FloatExt, Vec2};
|
||||
use bevy::utils::default;
|
||||
use noise::{NoiseFn, SuperSimplex};
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
||||
@@ -50,6 +51,7 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
|
||||
moisture: moisture,
|
||||
temperature: temp,
|
||||
chunk_offset: IVec2::new(chunk_x as i32, chunk_z as i32),
|
||||
..default()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -70,11 +70,24 @@ pub mod prelude {
|
||||
|
||||
pub struct Chunk {
|
||||
pub heights: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub textures: [[u32; 2]; Chunk::SIZE * Chunk::SIZE],
|
||||
pub moisture: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub temperature: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub chunk_offset: IVec2,
|
||||
}
|
||||
|
||||
impl Default for Chunk {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
heights: [0.; Chunk::SIZE * Chunk::SIZE],
|
||||
textures: [[0;2]; Chunk::SIZE * Chunk::SIZE],
|
||||
moisture: [0.; Chunk::SIZE * Chunk::SIZE],
|
||||
temperature: [0.; Chunk::SIZE * Chunk::SIZE],
|
||||
chunk_offset: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Chunk {
|
||||
pub const SIZE: usize = 64;
|
||||
pub const WORLD_WIDTH: f32 = Chunk::SIZE as f32 * SHORT_DIAGONAL;
|
||||
|
||||
@@ -13,13 +13,7 @@ use bevy::{
|
||||
},
|
||||
};
|
||||
|
||||
pub fn generate_chunk_mesh(
|
||||
chunk: &Chunk,
|
||||
map: &Map,
|
||||
painter: &BiomePainterAsset,
|
||||
tiles: &Res<Assets<TileAsset>>,
|
||||
mappers: &Res<Assets<TileMapperAsset>>,
|
||||
) -> Mesh {
|
||||
pub fn generate_chunk_mesh(chunk: &Chunk, map: &Map) -> Mesh {
|
||||
#[cfg(feature = "tracing")]
|
||||
let span = info_span!("generate_chunk_mesh").entered();
|
||||
|
||||
@@ -31,17 +25,13 @@ pub fn generate_chunk_mesh(
|
||||
|
||||
for z in 0..Chunk::SIZE {
|
||||
for x in 0..Chunk::SIZE {
|
||||
let height = chunk.heights[x + z * Chunk::SIZE];
|
||||
let moisture = chunk.moisture[x + z * Chunk::SIZE];
|
||||
let temperature = chunk.temperature[x + z * Chunk::SIZE];
|
||||
let idx = x + z * Chunk::SIZE;
|
||||
let height = chunk.heights[idx];
|
||||
let off_pos = Vec3::new(x as f32, height, z as f32);
|
||||
let tile_pos = offset3d_to_world(off_pos);
|
||||
let coord =
|
||||
HexCoord::from_offset(IVec2::new(x as i32, z as i32) + (chunk.chunk_offset * Chunk::SIZE as i32));
|
||||
let n = map.get_neighbors(&coord);
|
||||
let biome = mappers.get(painter.sample_biome(moisture, temperature));
|
||||
let tile_handle = biome.unwrap().sample_tile(height);
|
||||
let tile = tiles.get(tile_handle).unwrap();
|
||||
|
||||
create_tile(
|
||||
tile_pos,
|
||||
@@ -51,8 +41,8 @@ pub fn generate_chunk_mesh(
|
||||
&mut indices,
|
||||
&mut normals,
|
||||
// &mut tex,
|
||||
tile.texture_id,
|
||||
tile.side_texture_id,
|
||||
chunk.textures[idx][0],
|
||||
chunk.textures[idx][1],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ impl TileManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
|
||||
#[derive(Serialize, Deserialize, Debug, TypePath, Asset, Clone)]
|
||||
pub struct TileAsset {
|
||||
#[serde(skip)]
|
||||
pub id: usize,
|
||||
|
||||
Reference in New Issue
Block a user