updated asset loader
prep for adding biomes
This commit is contained in:
@@ -33,7 +33,9 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
|
||||
}
|
||||
}
|
||||
return Chunk {
|
||||
points: result,
|
||||
heights: result,
|
||||
moisture: result.clone(),
|
||||
tempurature: result.clone(),
|
||||
chunk_offset: IVec2::new(chunk_x as i32, chunk_z as i32),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -128,15 +128,15 @@ impl HexCoord {
|
||||
return IVec2::new(self.hex.x + (self.hex.y / 2), self.hex.y);
|
||||
}
|
||||
|
||||
pub fn to_index(&self, width: usize) -> i32 {
|
||||
return (self.hex.x + self.hex.y * width as i32) + (self.hex.y / 2);
|
||||
pub fn to_index(&self, width: usize) -> usize {
|
||||
return ((self.hex.x + self.hex.y * width as i32) + (self.hex.y / 2)) as usize;
|
||||
}
|
||||
pub fn to_chunk_index(&self, width: usize) -> i32 {
|
||||
pub fn to_chunk_index(&self, width: usize) -> usize {
|
||||
let pos = self.to_chunk_pos();
|
||||
return pos.x + pos.y * width as i32;
|
||||
return (pos.x + pos.y * width as i32) as usize;
|
||||
}
|
||||
|
||||
pub fn to_chunk_local_index(&self) -> i32 {
|
||||
pub fn to_chunk_local_index(&self) -> usize {
|
||||
return self.to_chunk().to_index(Chunk::SIZE);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
pub struct Chunk {
|
||||
pub points: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub heights: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub moisture: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub tempurature: [f32; Chunk::SIZE * Chunk::SIZE],
|
||||
pub chunk_offset: IVec2,
|
||||
}
|
||||
|
||||
@@ -59,12 +61,27 @@ pub mod prelude {
|
||||
continue;
|
||||
}
|
||||
let c_idx = n_tile.to_chunk_index(self.width);
|
||||
let chunk = &self.chunks[c_idx as usize];
|
||||
let chunk = &self.chunks[c_idx];
|
||||
let local = n_tile.to_chunk_local_index();
|
||||
results[i] = Some(chunk.points[local as usize]);
|
||||
results[i] = Some(chunk.heights[local]);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
pub fn get_height(&self, pos: &HexCoord) -> f32 {
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.heights[pos.to_chunk_local_index()];
|
||||
}
|
||||
|
||||
pub fn get_moisture(&self, pos: &HexCoord) -> f32 {
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.moisture[pos.to_chunk_local_index()];
|
||||
}
|
||||
|
||||
pub fn get_tempurature(&self, pos: &HexCoord) -> f32 {
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.tempurature[pos.to_chunk_local_index()];
|
||||
}
|
||||
}
|
||||
|
||||
pub const ATTRIBUTE_TEXTURE_INDEX: MeshVertexAttribute =
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn generate_chunk_mesh(chunk: &Chunk, map: &Map) -> Mesh {
|
||||
|
||||
for z in 0..Chunk::SIZE {
|
||||
for x in 0..Chunk::SIZE {
|
||||
let height = chunk.points[x + z * Chunk::SIZE];
|
||||
let height = chunk.heights[x + z * Chunk::SIZE];
|
||||
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(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use asset_loader::create_asset_loader;
|
||||
use bevy::{
|
||||
asset::{Asset, AssetLoader, AsyncReadExt},
|
||||
asset::{Asset, Handle},
|
||||
ecs::system::Resource,
|
||||
reflect::TypePath,
|
||||
};
|
||||
@@ -29,12 +29,12 @@ pub struct TileAsset {
|
||||
#[serde(skip)]
|
||||
pub id: usize,
|
||||
pub name: String,
|
||||
#[serde(skip)]
|
||||
pub texture_id: u32,
|
||||
#[serde(skip)]
|
||||
pub texture: String,
|
||||
pub side_texture_id: u32,
|
||||
#[serde(skip)]
|
||||
pub side_texture_id: u32,
|
||||
pub side_texture: String,
|
||||
}
|
||||
|
||||
create_asset_loader!(TileAssetPlugin, TileAssetLoader, TileAsset, &["tile.json"]);
|
||||
create_asset_loader!(TileAssetPlugin, TileAssetLoader, TileAsset, &["tile.json"],);
|
||||
|
||||
Reference in New Issue
Block a user