Tracing and Performance improvements

tracing
chunk rebuild testing
speed up world gen by moving collider creation to thread pool
This commit is contained in:
2024-05-07 23:26:13 -04:00
parent 58a9f62dca
commit 4e9a35adc6
11 changed files with 206 additions and 46 deletions

View File

@@ -13,3 +13,6 @@ serde_json = "1.0.115"
asset_loader = {path = "../asset_loader"}
rayon = "1.10.0"
bevy-inspector-egui = "0.24.0"
[features]
tracing = ["bevy/trace_tracy"]

View File

@@ -1,10 +1,13 @@
use bevy::prelude::*;
use crate::{hex_utils::*, prelude::*};
#[cfg(feature = "tracing")]
use bevy::log::*;
use bevy::prelude::*;
const CHUNK_TOTAL: usize = Chunk::SIZE * Chunk::SIZE;
pub fn generate_chunk_collider(chunk: &Chunk, map: &Map) -> (Vec<Vec3>, Vec<[u32; 3]>) {
#[cfg(feature = "tracing")]
let span = info_span!("generate_chunk_collider").entered();
let vertex_count: usize = CHUNK_TOTAL * 6;
let mut verts = Vec::with_capacity(vertex_count);
let mut indices = Vec::with_capacity(vertex_count);
@@ -28,12 +31,6 @@ fn create_tile_collider(pos: Vec3, verts: &mut Vec<Vec3>, indices: &mut Vec<[u32
let p = pos + HEX_CORNERS[i];
verts.push(p);
}
// for i in 0..3 {
// let off = i * 2;
// indices.push([off + idx, ((off + 1) % 6) + idx, ((off + 2) % 6) + idx]);
// }
// indices.push([idx, idx + 2, idx + 4]);
//Top Surfave
indices.push([idx, idx + 1, idx + 5]);

View File

@@ -120,6 +120,12 @@ impl HexCoord {
return true;
}
pub fn is_on_chunk_edge(&self) -> bool {
let offset = self.to_offset().rem_euclid(IVec2::splat(Chunk::SIZE as i32));
let e = (Chunk::SIZE - 1) as i32;
return offset.x == 0 || offset.y == 0 || offset.x == e || offset.y == e;
}
pub fn to_chunk_pos(&self) -> IVec2 {
let off = self.to_offset();

View File

@@ -144,6 +144,10 @@ pub mod prelude {
pub fn get_world_size(&self) -> Vec2 {
return Vec2::new(self.get_world_width(), self.get_world_height());
}
pub fn set_height(&mut self, pos: &HexCoord, height: f32) {
self.chunks[pos.to_chunk_index(self.width)].heights[pos.to_chunk_local_index()] = height;
}
}
pub const ATTRIBUTE_PACKED_VERTEX_DATA: MeshVertexAttribute =
MeshVertexAttribute::new("PackedVertexData", 988540817, VertexFormat::Uint32);

View File

@@ -3,6 +3,8 @@ use crate::hex_utils::HexCoord;
use crate::tile_manager::TileAsset;
use crate::tile_mapper::TileMapperAsset;
use crate::{hex_utils::offset3d_to_world, prelude::*};
#[cfg(feature = "tracing")]
use bevy::log::*;
use bevy::{
prelude::*,
render::{
@@ -18,6 +20,9 @@ pub fn generate_chunk_mesh(
tiles: &Res<Assets<TileAsset>>,
mappers: &Res<Assets<TileMapperAsset>>,
) -> Mesh {
#[cfg(feature = "tracing")]
let span = info_span!("generate_chunk_mesh").entered();
let vertex_count: usize = Chunk::SIZE * Chunk::SIZE * 6;
let mut verts = Vec::with_capacity(vertex_count);
let mut uvs = Vec::with_capacity(vertex_count);