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::meshing_gpu::{ GpuMeshingWorker, queue_gpu_meshing, }; use bevy_app_compute::prelude::{AppComputePlugin, AppComputeWorkerPlugin}; use crate::plugins::environment::systems::voxels::queue_systems::process_chunk_queue; use crate::plugins::environment::systems::voxels::visibility_gpu::{ enqueue_visible_chunks_gpu, GpuVisibilityWorker, }; 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, Startup}; use bevy::prelude::*; 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, ), ); app.add_plugins(AppComputePlugin); app.add_plugins(AppComputeWorkerPlugin::::default()); app.add_plugins(AppComputeWorkerPlugin::::default()); let view_distance_chunks = 100; app.insert_resource(ChunkCullingCfg { view_distance_chunks, }); app.insert_resource(ChunkBudget { per_frame: 20 }); app.init_resource::(); app.add_systems(Update, log_mesh_count); app // ------------------------------------------------------------------------ // resources // ------------------------------------------------------------------------ .init_resource::() .init_resource::() .init_resource::() // ------------------------------------------------------------------------ // frame update // ------------------------------------------------------------------------ .add_systems( Update, ( /* ---------- culling & streaming ---------- */ enqueue_visible_chunks_gpu, process_chunk_queue.after(enqueue_visible_chunks_gpu), update_chunk_lods.after(process_chunk_queue), rebuild_dirty_chunks.after(process_chunk_queue), // 4. (re)mesh dirty chunks queue_gpu_meshing.after(rebuild_dirty_chunks), /* ---------- optional debug drawing ------- */ visualize_octree_system .run_if(should_visualize_octree) .after(rebuild_dirty_chunks), draw_grid .run_if(should_draw_grid) .after(visualize_octree_system), ) .chain(), // make the whole tuple execute in this exact order ); } } fn log_mesh_count(meshes: Res>, time: Res