Skip to content

Commit

Permalink
move spatial setup to SpatialPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
thombruce committed Oct 10, 2023
1 parent 4434b80 commit d91d88c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/astronomy/orbit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::time::Duration;

use bevy::prelude::*;
use bevy_spatial::{AutomaticUpdate, SpatialStructure};

use crate::resources::{game_time::GameTime, spatial::KDNode, state::GameState};
use crate::resources::{game_time::GameTime, state::GameState};

const ORBITAL_PERIOD_SCALING_FACTOR: f32 = 1.0;

Expand All @@ -30,11 +27,6 @@ impl Default for Orbitable {
pub struct OrbitPlugin;
impl Plugin for OrbitPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(
AutomaticUpdate::<KDNode>::new()
.with_spatial_ds(SpatialStructure::KDTree2)
.with_frequency(Duration::from_millis(1)),
);
app.add_systems(
Update,
(orbitable_update_system, orbital_positioning_system)
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
assets::{AudioAssets, SpriteAssets, UiAssets},
camera::CameraPlugin,
game_time::GameTimePlugin,
spatial::SpatialPlugin,
state::{GameState, StatePlugin},
},
ship::ShipPlugin,
Expand Down Expand Up @@ -61,6 +62,10 @@ fn main() {
PlanetarySystemPlugin,
));

// You can only add 15 plugins to add_plugins
// I need to start refactoring.
app.add_plugins(SpatialPlugin);

#[cfg(debug_assertions)]
app.add_plugins((
RapierDebugRenderPlugin::default(),
Expand Down
14 changes: 14 additions & 0 deletions src/resources/spatial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
use std::time::Duration;

use bevy::prelude::*;
use bevy_spatial::{AutomaticUpdate, SpatialStructure};

#[derive(Component)]
pub struct KDNode;

pub struct SpatialPlugin;
impl Plugin for SpatialPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(
AutomaticUpdate::<KDNode>::new()
.with_spatial_ds(SpatialStructure::KDTree2)
.with_frequency(Duration::from_millis(1)),
);
}
}

0 comments on commit d91d88c

Please sign in to comment.