From 0cf98496ed982601f7a9b73ac0254136a9e4fc9c Mon Sep 17 00:00:00 2001 From: Elias Stepanik <40958815+eliasstepanik@users.noreply.github.com> Date: Fri, 13 Jun 2025 02:53:19 +0200 Subject: [PATCH 1/6] Add mesh buffer pooling --- .../plugins/environment/environment_plugin.rs | 45 +++++++------ .../environment/systems/voxels/meshing.rs | 63 ++++++++++++------- .../systems/voxels/render_chunks.rs | 50 ++++++++------- .../environment/systems/voxels/structure.rs | 62 ++++++++++++------ 4 files changed, 137 insertions(+), 83 deletions(-) diff --git a/client/src/plugins/environment/environment_plugin.rs b/client/src/plugins/environment/environment_plugin.rs index c28841c..be6e039 100644 --- a/client/src/plugins/environment/environment_plugin.rs +++ b/client/src/plugins/environment/environment_plugin.rs @@ -1,28 +1,34 @@ +use crate::plugins::environment::systems::voxels::debug::{draw_grid, visualize_octree_system}; +use crate::plugins::environment::systems::voxels::lod::update_chunk_lods; +use crate::plugins::environment::systems::voxels::queue_systems; +use crate::plugins::environment::systems::voxels::queue_systems::{ + enqueue_visible_chunks, process_chunk_queue, +}; +use crate::plugins::environment::systems::voxels::render_chunks::rebuild_dirty_chunks; +use crate::plugins::environment::systems::voxels::structure::{ + ChunkBudget, ChunkCullingCfg, ChunkQueue, MeshBufferPool, PrevCameraChunk, SparseVoxelOctree, + SpawnedChunks, +}; use bevy::app::{App, Plugin, PreStartup, PreUpdate, Startup}; use bevy::prelude::*; -use crate::plugins::environment::systems::voxels::debug::{draw_grid, visualize_octree_system}; -use crate::plugins::environment::systems::voxels::queue_systems; -use crate::plugins::environment::systems::voxels::queue_systems::{enqueue_visible_chunks, process_chunk_queue}; -use crate::plugins::environment::systems::voxels::render_chunks::rebuild_dirty_chunks; -use crate::plugins::environment::systems::voxels::lod::update_chunk_lods; -use crate::plugins::environment::systems::voxels::structure::{ChunkBudget, ChunkCullingCfg, ChunkQueue, SparseVoxelOctree, SpawnedChunks, PrevCameraChunk}; pub struct EnvironmentPlugin; impl Plugin for EnvironmentPlugin { fn build(&self, app: &mut App) { - app.add_systems( Startup, ( crate::plugins::environment::systems::camera_system::setup, - crate::plugins::environment::systems::environment_system::setup.after(crate::plugins::environment::systems::camera_system::setup), - crate::plugins::environment::systems::voxel_system::setup - + crate::plugins::environment::systems::environment_system::setup + .after(crate::plugins::environment::systems::camera_system::setup), + crate::plugins::environment::systems::voxel_system::setup, ), ); let view_distance_chunks = 100; - app.insert_resource(ChunkCullingCfg { view_distance_chunks }); + app.insert_resource(ChunkCullingCfg { + view_distance_chunks, + }); app.insert_resource(ChunkBudget { per_frame: 20 }); app.init_resource::(); app.add_systems(Update, log_mesh_count); @@ -32,6 +38,7 @@ impl Plugin for EnvironmentPlugin { // ------------------------------------------------------------------------ .init_resource::() .init_resource::() + .init_resource::() // ------------------------------------------------------------------------ // frame update // ------------------------------------------------------------------------ @@ -42,8 +49,7 @@ impl Plugin for EnvironmentPlugin { enqueue_visible_chunks, process_chunk_queue.after(enqueue_visible_chunks), update_chunk_lods.after(process_chunk_queue), - rebuild_dirty_chunks .after(process_chunk_queue), // 4. (re)mesh dirty chunks - + rebuild_dirty_chunks.after(process_chunk_queue), // 4. (re)mesh dirty chunks /* ---------- optional debug drawing ------- */ visualize_octree_system .run_if(should_visualize_octree) @@ -52,9 +58,8 @@ impl Plugin for EnvironmentPlugin { .run_if(should_draw_grid) .after(visualize_octree_system), ) - .chain(), // make the whole tuple execute in this exact order + .chain(), // make the whole tuple execute in this exact order ); - } } @@ -65,11 +70,15 @@ fn log_mesh_count(meshes: Res>, time: Res