add feature flag for toggling the generic ring asteroids

This commit is contained in:
yuni 2024-06-08 04:14:51 +02:00
parent e56f931951
commit 974bf9cb8d

View file

@ -19,6 +19,7 @@ use bevy_xpbd_3d::prelude::*;
use fastrand; use fastrand;
use std::collections::HashMap; use std::collections::HashMap;
const ENABLE_ASTEROIDS: bool = true;
const ASTEROID_UPDATE_INTERVAL: f32 = 0.1; // seconds const ASTEROID_UPDATE_INTERVAL: f32 = 0.1; // seconds
const ASTEROID_SIZE_FACTOR: f32 = 10.0; const ASTEROID_SIZE_FACTOR: f32 = 10.0;
const RING_THICKNESS: f64 = 8.0e6; const RING_THICKNESS: f64 = 8.0e6;
@ -36,19 +37,21 @@ pub struct WorldPlugin;
impl Plugin for WorldPlugin { impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, setup); app.add_systems(Startup, setup);
app.add_systems(PostUpdate, handle_despawn);
app.add_systems(Update, spawn_despawn_asteroids);
app.add_systems(Update, handle_respawn.run_if(on_event::<RespawnEvent>())); app.add_systems(Update, handle_respawn.run_if(on_event::<RespawnEvent>()));
app.add_plugins(PhysicsPlugins::default()); app.add_plugins(PhysicsPlugins::default());
//app.add_plugins(PhysicsDebugPlugin::default()); //app.add_plugins(PhysicsDebugPlugin::default());
app.insert_resource(Gravity(DVec3::splat(0.0))); app.insert_resource(Gravity(DVec3::splat(0.0)));
app.insert_resource(ActiveAsteroids(HashMap::new()));
app.add_event::<RespawnEvent>();
if ENABLE_ASTEROIDS {
app.insert_resource(AsteroidUpdateTimer(Timer::from_seconds( app.insert_resource(AsteroidUpdateTimer(Timer::from_seconds(
ASTEROID_UPDATE_INTERVAL, ASTEROID_UPDATE_INTERVAL,
TimerMode::Repeating, TimerMode::Repeating,
))); )));
app.insert_resource(ActiveAsteroids(HashMap::new())); app.add_systems(Update, spawn_despawn_asteroids);
app.add_systems(PostUpdate, handle_despawn_asteroids);
app.add_event::<DespawnAsteroidEvent>(); app.add_event::<DespawnAsteroidEvent>();
app.add_event::<RespawnEvent>(); }
} }
} }
@ -344,7 +347,7 @@ fn spawn_despawn_asteroids(
} }
} }
fn handle_despawn( fn handle_despawn_asteroids(
mut commands: Commands, mut commands: Commands,
mut er_despawn: EventReader<DespawnAsteroidEvent>, mut er_despawn: EventReader<DespawnAsteroidEvent>,
mut db: ResMut<ActiveAsteroids>, mut db: ResMut<ActiveAsteroids>,