Skip to content

Commit

Permalink
Allow configuration of schedule in which particles update
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrea-c committed Aug 15, 2024
1 parent 101f87b commit 9f6981a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
#[cfg(target_arch = "wasm32")]
app.insert_resource(Msaa::Off);

app.add_plugins(ParticleSystemPlugin)
app.add_plugins(ParticleSystemPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, adjust_time_scale)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/pbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {

// The particle system plugin must be added **after** any changes
// to the MSAA setting.
app.add_plugins(ParticleSystemPlugin)
app.add_plugins(ParticleSystemPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, (adjust_time_scale, rotate_point_light));
#[cfg(feature = "physics_avian")]
Expand Down
2 changes: 1 addition & 1 deletion examples/sparks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

// The particle system plugin must be added **after** any changes
// to the MSAA setting.
app.add_plugins(ParticleSystemPlugin)
app.add_plugins(ParticleSystemPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, adjust_time_scale);

Expand Down
2 changes: 1 addition & 1 deletion examples/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {

// The particle system plugin must be added **after** any changes
// to the MSAA setting.
app.add_plugins(ParticleSystemPlugin)
app.add_plugins(ParticleSystemPlugin::default())
.init_resource::<DebugInfo>()
.add_systems(Startup, setup)
.add_systems(
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_test_collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {

// The particle system plugin must be added **after** any changes
// to the MSAA setting.
app.add_plugins(ParticleSystemPlugin)
app.add_plugins(ParticleSystemPlugin::default())
.init_resource::<DebugInfo>()
.add_systems(Startup, setup)
.add_systems(
Expand Down
28 changes: 19 additions & 9 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@ use super::{
},
render,
};
use bevy::{asset::load_internal_asset, prelude::*, transform::TransformSystem};
use bevy::{
asset::load_internal_asset,
ecs::{intern::Interned, schedule::ScheduleLabel},
prelude::*,
};

#[cfg(feature = "physics_avian")]
use super::core::sync_parent_velocity;

pub const PARTICLE_SHADER_HANDLE: Handle<Shader> =
Handle::weak_from_u128(272481238906797053434642785120685433641);

pub struct ParticleSystemPlugin;
pub struct ParticleSystemPlugin {
update_schedule: Interned<dyn ScheduleLabel>,
}

impl Default for ParticleSystemPlugin {
fn default() -> Self {
Self {
update_schedule: Update.intern(),
}
}
}

impl Plugin for ParticleSystemPlugin {
fn build(&self, app: &mut App) {
Expand All @@ -31,22 +45,18 @@ impl Plugin for ParticleSystemPlugin {
.add_plugins(render::CustomMaterialPlugin)
.add_systems(Startup, setup_default_mesh)
.add_systems(
Update,
self.update_schedule,
(
apply_deferred,
(create_spawner_data, propagate_particle_spawner_modifier),
apply_deferred,
sync_spawner_data,
#[cfg(feature = "physics_avian")]
sync_parent_velocity,
spawn_particles,
update_particles,
)
.chain(),
)
.add_systems(
PostUpdate,
(spawn_particles, update_particles)
.chain()
.after(TransformSystem::TransformPropagate),
);
}
}

0 comments on commit 9f6981a

Please sign in to comment.