From e6b1e964fa493bcb31a6b3809ecbc0746e4448d1 Mon Sep 17 00:00:00 2001 From: devil-ira Date: Tue, 14 Mar 2023 17:20:45 +0100 Subject: [PATCH 01/10] Schedule-First --- bevy_rapier2d/Cargo.toml | 4 +- bevy_rapier2d/examples/boxes2.rs | 3 +- bevy_rapier2d/examples/contact_filter2.rs | 3 +- .../examples/custom_system_setup2.rs | 70 +++++++------------ bevy_rapier2d/examples/debug_despawn2.rs | 4 +- bevy_rapier2d/examples/despawn2.rs | 6 +- bevy_rapier2d/examples/events2.rs | 5 +- bevy_rapier2d/examples/joints2.rs | 3 +- bevy_rapier2d/examples/joints_despawn2.rs | 5 +- bevy_rapier2d/examples/locked_rotations2.rs | 3 +- bevy_rapier2d/examples/multiple_colliders2.rs | 3 +- bevy_rapier2d/examples/player_movement2.rs | 4 +- bevy_rapier3d/Cargo.toml | 4 +- bevy_rapier3d/examples/boxes3.rs | 3 +- bevy_rapier3d/examples/contact_filter3.rs | 3 +- .../examples/custom_system_setup3.rs | 60 ++++++---------- bevy_rapier3d/examples/despawn3.rs | 5 +- bevy_rapier3d/examples/events3.rs | 5 +- bevy_rapier3d/examples/joints3.rs | 3 +- bevy_rapier3d/examples/joints_despawn3.rs | 5 +- bevy_rapier3d/examples/locked_rotations3.rs | 3 +- bevy_rapier3d/examples/multiple_colliders3.rs | 3 +- bevy_rapier3d/examples/ray_casting3.rs | 5 +- bevy_rapier3d/examples/static_trimesh3.rs | 5 +- src/plugin/plugin.rs | 45 +++++------- src/plugin/systems.rs | 10 +-- src/render/lines/mod.rs | 14 ++-- src/render/mod.rs | 6 +- 28 files changed, 113 insertions(+), 179 deletions(-) diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 1937871e..41bc67a9 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -37,7 +37,7 @@ async-collider = [ ] [dependencies] -bevy = { version = "0.10", default-features = false, features = ["bevy_asset", "bevy_scene"] } +bevy = { version = "0.11.0-dev", path = "../../bevy", default-features = false, features = ["bevy_asset", "bevy_scene"] } nalgebra = { version = "0.32.2", features = [ "convert-glam023" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet rapier2d = "0.17.0" @@ -47,7 +47,7 @@ log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} [dev-dependencies] -bevy = { version = "0.10", default-features = false, features = ["x11"]} +bevy = { version = "0.11.0-dev", path = "../../bevy", default-features = false, features = ["x11"]} oorandom = "11" approx = "0.5.1" glam = { version = "0.23", features = [ "approx" ] } diff --git a/bevy_rapier2d/examples/boxes2.rs b/bevy_rapier2d/examples/boxes2.rs index 2ea9a1d0..cfb04e66 100644 --- a/bevy_rapier2d/examples/boxes2.rs +++ b/bevy_rapier2d/examples/boxes2.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier2d/examples/contact_filter2.rs b/bevy_rapier2d/examples/contact_filter2.rs index 37dc0d08..dcddb426 100644 --- a/bevy_rapier2d/examples/contact_filter2.rs +++ b/bevy_rapier2d/examples/contact_filter2.rs @@ -40,8 +40,7 @@ fn main() { 100.0, )) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier2d/examples/custom_system_setup2.rs b/bevy_rapier2d/examples/custom_system_setup2.rs index 49a6f92c..b55c9c5c 100644 --- a/bevy_rapier2d/examples/custom_system_setup2.rs +++ b/bevy_rapier2d/examples/custom_system_setup2.rs @@ -1,9 +1,6 @@ -use bevy::{core::FrameCount, ecs::schedule::ScheduleLabel, prelude::*}; +use bevy::{core::FrameCount, prelude::*, transform::TransformSystem}; use bevy_rapier2d::prelude::*; -#[derive(ScheduleLabel, Hash, Debug, PartialEq, Eq, Clone)] -struct SpecialSchedule; - fn main() { let mut app = App::new(); @@ -14,56 +11,43 @@ fn main() { ))) .add_plugins(DefaultPlugins) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system( - (|world: &mut World| { - world.run_schedule(SpecialSchedule); - }) - .in_base_set(CoreSet::PostUpdate), - ); - - // Do the setup however we want, maybe in its very own schedule - let mut schedule = Schedule::new(); + .add_systems(Startup, (setup_graphics, setup_physics)); - schedule.configure_sets( + app.configure_sets( + PostUpdate, ( PhysicsSet::SyncBackend, PhysicsSet::SyncBackendFlush, PhysicsSet::StepSimulation, PhysicsSet::Writeback, ) - .chain(), + .chain() + .before(TransformSystem::TransformPropagate), ); - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackend) - .in_base_set(PhysicsSet::SyncBackend), - ); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackendFlush) - .in_base_set(PhysicsSet::SyncBackendFlush), - ); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::StepSimulation) - .in_base_set(PhysicsSet::StepSimulation), - ); - schedule.add_system(despawn_one_box.in_base_set(PhysicsSet::StepSimulation)); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::Writeback) - .in_base_set(PhysicsSet::Writeback), + app.add_systems( + PostUpdate, + ( + RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackend) + .in_set(PhysicsSet::SyncBackend), + RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackendFlush) + .in_set(PhysicsSet::SyncBackendFlush), + ( + RapierPhysicsPlugin::::get_systems(PhysicsSet::StepSimulation), + despawn_one_box, + ) + .in_set(PhysicsSet::StepSimulation), + RapierPhysicsPlugin::::get_systems(PhysicsSet::Writeback) + .in_set(PhysicsSet::Writeback), + ), ); - app.add_schedule(SpecialSchedule, schedule) - .add_plugin( - RapierPhysicsPlugin::::default() - .with_physics_scale(100.) - .with_default_system_setup(false), - ) - .run(); + app.add_plugin( + RapierPhysicsPlugin::::default() + .with_physics_scale(100.) + .with_default_system_setup(false), + ) + .run(); } fn despawn_one_box( diff --git a/bevy_rapier2d/examples/debug_despawn2.rs b/bevy_rapier2d/examples/debug_despawn2.rs index 92cdd924..990c9ba0 100644 --- a/bevy_rapier2d/examples/debug_despawn2.rs +++ b/bevy_rapier2d/examples/debug_despawn2.rs @@ -10,8 +10,8 @@ fn main() { .init_resource::() .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))) .add_plugins(DefaultPlugins) - .add_startup_system(setup_game) - .add_system(cube_sleep_detection) + .add_systems(Startup, setup_game) + .add_systems(Update, cube_sleep_detection) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) .run(); diff --git a/bevy_rapier2d/examples/despawn2.rs b/bevy_rapier2d/examples/despawn2.rs index 8a2db871..5c6f49f1 100644 --- a/bevy_rapier2d/examples/despawn2.rs +++ b/bevy_rapier2d/examples/despawn2.rs @@ -23,10 +23,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(despawn) - .add_system(resize) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, (despawn, resize)) .run(); } diff --git a/bevy_rapier2d/examples/events2.rs b/bevy_rapier2d/examples/events2.rs index 15b416a5..ec26806a 100644 --- a/bevy_rapier2d/examples/events2.rs +++ b/bevy_rapier2d/examples/events2.rs @@ -11,9 +11,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(display_events.in_base_set(CoreSet::PostUpdate)) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(PostUpdate, display_events) .run(); } diff --git a/bevy_rapier2d/examples/joints2.rs b/bevy_rapier2d/examples/joints2.rs index f4688f68..89dca927 100644 --- a/bevy_rapier2d/examples/joints2.rs +++ b/bevy_rapier2d/examples/joints2.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier2d/examples/joints_despawn2.rs b/bevy_rapier2d/examples/joints_despawn2.rs index a3599a01..496520c0 100644 --- a/bevy_rapier2d/examples/joints_despawn2.rs +++ b/bevy_rapier2d/examples/joints_despawn2.rs @@ -17,9 +17,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(despawn) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, despawn) .run(); } diff --git a/bevy_rapier2d/examples/locked_rotations2.rs b/bevy_rapier2d/examples/locked_rotations2.rs index 43aa7045..e7e55306 100644 --- a/bevy_rapier2d/examples/locked_rotations2.rs +++ b/bevy_rapier2d/examples/locked_rotations2.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier2d/examples/multiple_colliders2.rs b/bevy_rapier2d/examples/multiple_colliders2.rs index 6e473fab..295459fc 100644 --- a/bevy_rapier2d/examples/multiple_colliders2.rs +++ b/bevy_rapier2d/examples/multiple_colliders2.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier2d/examples/player_movement2.rs b/bevy_rapier2d/examples/player_movement2.rs index bf273bd7..be03d254 100644 --- a/bevy_rapier2d/examples/player_movement2.rs +++ b/bevy_rapier2d/examples/player_movement2.rs @@ -11,8 +11,8 @@ fn main() { }), ..default() })) - .add_startup_system(spawn_player) - .add_system(player_movement) + .add_systems(Startup, spawn_player) + .add_systems(Update, player_movement) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(100.0)) .add_plugin(RapierDebugRenderPlugin::default()) .run(); diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index c311b768..cba68f75 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -38,7 +38,7 @@ headless = [ ] async-collider = [ ] [dependencies] -bevy = { version = "0.10", default-features = false, features = ["bevy_asset", "bevy_scene"] } +bevy = { version = "0.11.0-dev", path = "../../bevy", default-features = false, features = ["bevy_asset", "bevy_scene"] } nalgebra = { version = "0.32.2", features = [ "convert-glam023" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet rapier3d = "0.17.0" @@ -48,7 +48,7 @@ log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} [dev-dependencies] -bevy = { version = "0.10", default-features = false, features = ["x11"]} +bevy = { version = "0.11.0-dev", path = "../../bevy", default-features = false, features = ["x11"]} approx = "0.5.1" glam = { version = "0.23", features = [ "approx" ] } diff --git a/bevy_rapier3d/examples/boxes3.rs b/bevy_rapier3d/examples/boxes3.rs index 075110b7..8df67b4f 100644 --- a/bevy_rapier3d/examples/boxes3.rs +++ b/bevy_rapier3d/examples/boxes3.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier3d/examples/contact_filter3.rs b/bevy_rapier3d/examples/contact_filter3.rs index 7a5ebfaa..cf2f1f4d 100644 --- a/bevy_rapier3d/examples/contact_filter3.rs +++ b/bevy_rapier3d/examples/contact_filter3.rs @@ -38,8 +38,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier3d/examples/custom_system_setup3.rs b/bevy_rapier3d/examples/custom_system_setup3.rs index 3911afed..b9bad403 100644 --- a/bevy_rapier3d/examples/custom_system_setup3.rs +++ b/bevy_rapier3d/examples/custom_system_setup3.rs @@ -1,9 +1,6 @@ -use bevy::{core::FrameCount, ecs::schedule::ScheduleLabel, prelude::*}; +use bevy::{core::FrameCount, prelude::*, transform::TransformSystem}; use bevy_rapier3d::prelude::*; -#[derive(ScheduleLabel, Hash, Debug, PartialEq, Eq, Clone)] -struct SpecialSchedule; - fn main() { let mut app = App::new(); @@ -14,51 +11,38 @@ fn main() { ))) .add_plugins(DefaultPlugins) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system( - (|world: &mut World| { - world.run_schedule(SpecialSchedule); - }) - .in_base_set(CoreSet::PostUpdate), - ); - - // Do the setup however we want, maybe in its very own schedule - let mut schedule = Schedule::new(); + .add_systems(Startup, (setup_graphics, setup_physics)); - schedule.configure_sets( + app.configure_sets( + PostUpdate, ( PhysicsSet::SyncBackend, PhysicsSet::SyncBackendFlush, PhysicsSet::StepSimulation, PhysicsSet::Writeback, ) - .chain(), - ); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackend) - .in_base_set(PhysicsSet::SyncBackend), + .chain() + .before(TransformSystem::TransformPropagate), ); - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackendFlush) - .in_base_set(PhysicsSet::SyncBackendFlush), - ); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::StepSimulation) - .in_base_set(PhysicsSet::StepSimulation), - ); - schedule.add_system(despawn_one_box.in_base_set(PhysicsSet::StepSimulation)); - - schedule.add_systems( - RapierPhysicsPlugin::::get_systems(PhysicsSet::Writeback) - .in_base_set(PhysicsSet::Writeback), + app.add_systems( + PostUpdate, + ( + RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackend) + .in_set(PhysicsSet::SyncBackend), + RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackendFlush) + .in_set(PhysicsSet::SyncBackendFlush), + ( + RapierPhysicsPlugin::::get_systems(PhysicsSet::StepSimulation), + despawn_one_box, + ) + .in_set(PhysicsSet::StepSimulation), + RapierPhysicsPlugin::::get_systems(PhysicsSet::Writeback) + .in_set(PhysicsSet::Writeback), + ), ); - app.add_schedule(SpecialSchedule, schedule) - .add_plugin(RapierPhysicsPlugin::::default().with_default_system_setup(false)) + app.add_plugin(RapierPhysicsPlugin::::default().with_default_system_setup(false)) .run(); } diff --git a/bevy_rapier3d/examples/despawn3.rs b/bevy_rapier3d/examples/despawn3.rs index ae78a7ad..81815940 100644 --- a/bevy_rapier3d/examples/despawn3.rs +++ b/bevy_rapier3d/examples/despawn3.rs @@ -17,9 +17,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(despawn) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, despawn) .run(); } diff --git a/bevy_rapier3d/examples/events3.rs b/bevy_rapier3d/examples/events3.rs index 15d65f57..0a94a360 100644 --- a/bevy_rapier3d/examples/events3.rs +++ b/bevy_rapier3d/examples/events3.rs @@ -11,9 +11,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(display_events.in_base_set(CoreSet::PostUpdate)) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(PostUpdate, display_events) .run(); } diff --git a/bevy_rapier3d/examples/joints3.rs b/bevy_rapier3d/examples/joints3.rs index d0327a01..ec229868 100644 --- a/bevy_rapier3d/examples/joints3.rs +++ b/bevy_rapier3d/examples/joints3.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier3d/examples/joints_despawn3.rs b/bevy_rapier3d/examples/joints_despawn3.rs index a04cc3b6..3b5257b0 100644 --- a/bevy_rapier3d/examples/joints_despawn3.rs +++ b/bevy_rapier3d/examples/joints_despawn3.rs @@ -17,9 +17,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(despawn) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, despawn) .run(); } diff --git a/bevy_rapier3d/examples/locked_rotations3.rs b/bevy_rapier3d/examples/locked_rotations3.rs index c5ce9e73..6170526d 100644 --- a/bevy_rapier3d/examples/locked_rotations3.rs +++ b/bevy_rapier3d/examples/locked_rotations3.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier3d/examples/multiple_colliders3.rs b/bevy_rapier3d/examples/multiple_colliders3.rs index 6d13f3ba..e9522969 100644 --- a/bevy_rapier3d/examples/multiple_colliders3.rs +++ b/bevy_rapier3d/examples/multiple_colliders3.rs @@ -11,8 +11,7 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .run(); } diff --git a/bevy_rapier3d/examples/ray_casting3.rs b/bevy_rapier3d/examples/ray_casting3.rs index 5ecc5cce..6ecba415 100644 --- a/bevy_rapier3d/examples/ray_casting3.rs +++ b/bevy_rapier3d/examples/ray_casting3.rs @@ -12,9 +12,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) - .add_system(cast_ray) + .add_systems(Startup, (setup_graphics, setup_physics)) + .add_systems(Update, cast_ray) .run(); } diff --git a/bevy_rapier3d/examples/static_trimesh3.rs b/bevy_rapier3d/examples/static_trimesh3.rs index 4b926bfd..51743d3f 100644 --- a/bevy_rapier3d/examples/static_trimesh3.rs +++ b/bevy_rapier3d/examples/static_trimesh3.rs @@ -13,10 +13,9 @@ fn main() { .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system(setup_graphics) - .add_startup_system(setup_physics) + .add_systems(Startup, (setup_graphics, setup_physics)) .insert_resource(BallState::default()) - .add_system(ball_spawner) + .add_systems(Update, ball_spawner) .run(); } diff --git a/src/plugin/plugin.rs b/src/plugin/plugin.rs index b9ce828d..336bd02e 100644 --- a/src/plugin/plugin.rs +++ b/src/plugin/plugin.rs @@ -3,7 +3,7 @@ use crate::plugin::configuration::SimulationToRenderTime; use crate::plugin::{systems, RapierConfiguration, RapierContext}; use crate::prelude::*; use bevy::ecs::{event::Events, schedule::SystemConfigs, system::SystemParamItem}; -use bevy::prelude::*; +use bevy::{prelude::*, transform::TransformSystem}; use std::marker::PhantomData; /// No specific user-data is associated to the hooks. @@ -60,22 +60,17 @@ where /// [`with_system_setup(false)`](Self::with_system_setup). /// See [`PhysicsSet`] for a description of these systems. pub fn get_systems(set: PhysicsSet) -> SystemConfigs { - // A set for `propagate_transforms` to mark it as ambiguous with `sync_simple_transforms`. - // Used instead of the `SystemTypeSet` as that would not allow multiple instances of the system. - #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] - struct PropagateTransformsSet; - match set { PhysicsSet::SyncBackend => ( // Run the character controller before the manual transform propagation. systems::update_character_controls, // Run Bevy transform propagation additionally to sync [`GlobalTransform`] - bevy::transform::systems::sync_simple_transforms - .in_set(RapierTransformPropagateSet) - .after(systems::update_character_controls), - bevy::transform::systems::propagate_transforms + ( + bevy::transform::systems::sync_simple_transforms, + bevy::transform::systems::propagate_transforms, + ) + .chain() .after(systems::update_character_controls) - .in_set(PropagateTransformsSet) .in_set(RapierTransformPropagateSet), systems::init_async_colliders.after(RapierTransformPropagateSet), systems::apply_scale.after(systems::init_async_colliders), @@ -132,8 +127,7 @@ impl Default for RapierPhysicsPlugin() - .add_system(update_colliding_entities); + .add_systems(Update, update_colliding_entities); let entity1 = app.world.spawn(CollidingEntities::default()).id(); let entity2 = app.world.spawn(CollidingEntities::default()).id(); @@ -1508,7 +1508,7 @@ mod tests { fn async_collider_initializes() { let mut app = App::new(); app.add_plugin(HeadlessRenderPlugin) - .add_system(init_async_colliders); + .add_systems(Update, init_async_colliders); let mut meshes = app.world.resource_mut::>(); let cube = meshes.add(Cube::default().into()); @@ -1534,8 +1534,10 @@ mod tests { use bevy::scene::scene_spawner_system; let mut app = App::new(); - app.add_plugin(HeadlessRenderPlugin) - .add_system(init_async_scene_colliders.after(scene_spawner_system)); + app.add_plugin(HeadlessRenderPlugin).add_systems( + Update, + init_async_scene_colliders.after(scene_spawner_system), + ); let mut meshes = app.world.resource_mut::>(); let cube_handle = meshes.add(Cube::default().into()); diff --git a/src/render/lines/mod.rs b/src/render/lines/mod.rs index da92e749..d583fd44 100644 --- a/src/render/lines/mod.rs +++ b/src/render/lines/mod.rs @@ -24,7 +24,7 @@ use bevy::{ render_resource::PrimitiveTopology, render_resource::Shader, view::NoFrustumCulling, - Extract, + Extract, Render, }, }; use std::sync::{Arc, RwLock}; @@ -117,11 +117,7 @@ impl Plugin for DebugLinesPlugin { let lines_config = DebugLinesConfig::always_on_top(self.always_on_top); app.init_resource::() .add_startup_system(setup) - .add_system( - update - .in_base_set(CoreSet::PostUpdate) - .in_set(DrawLinesLabel), - ) + .add_systems(PostUpdate, update.in_set(DrawLinesLabel)) .insert_resource(lines_config.clone()); #[cfg(feature = "debug-render-3d")] @@ -129,18 +125,18 @@ impl Plugin for DebugLinesPlugin { .add_render_command::() .init_resource::() .init_resource::>() - .add_system(dim3::queue.in_set(RenderSet::Queue)); + .add_systems(Render, dim3::queue.in_set(RenderSet::Queue)); #[cfg(feature = "debug-render-2d")] app.sub_app_mut(RenderApp) .add_render_command::() .init_resource::() .init_resource::>() - .add_system(dim2::queue.in_set(RenderSet::Queue)); + .add_systems(Render, dim2::queue.in_set(RenderSet::Queue)); app.sub_app_mut(RenderApp) .insert_resource(lines_config) - .add_system(extract.in_schedule(ExtractSchedule)); + .add_systems(ExtractSchedule, extract); #[cfg(feature = "debug-render-3d")] info!("Loaded 3d debug lines plugin."); diff --git a/src/render/mod.rs b/src/render/mod.rs index b7151ea9..2a069595 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -103,11 +103,7 @@ impl Plugin for RapierDebugRenderPlugin { pipeline: DebugRenderPipeline::new(self.style, self.mode), always_on_top: self.always_on_top, }) - .add_system( - debug_render_scene - .in_base_set(CoreSet::PostUpdate) - .before(DrawLinesLabel), - ); + .add_systems(PostUpdate, debug_render_scene.before(DrawLinesLabel)); } } From 4d4aafe08683843f8b2b475c3cba593bb8676bb4 Mon Sep 17 00:00:00 2001 From: devil-ira Date: Mon, 27 Mar 2023 17:37:57 +0200 Subject: [PATCH 02/10] Use Bevy's built in line-rendering --- bevy_rapier2d/Cargo.toml | 4 +- bevy_rapier3d/Cargo.toml | 4 +- src/render/lines/debuglines.wgsl | 50 ---- src/render/lines/mod.rs | 397 ------------------------------- src/render/lines/render_dim.rs | 345 --------------------------- src/render/mod.rs | 43 ++-- 6 files changed, 18 insertions(+), 825 deletions(-) delete mode 100644 src/render/lines/debuglines.wgsl delete mode 100644 src/render/lines/mod.rs delete mode 100644 src/render/lines/render_dim.rs diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 41bc67a9..94d6c3d2 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -20,8 +20,8 @@ required-features = [ "dim2" ] [features] default = [ "dim2", "async-collider", "debug-render-2d" ] dim2 = ["bevy/bevy_render"] -debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_render", "rapier2d/debug-render" ] -debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_render", "rapier2d/debug-render" ] +debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier2d/debug-render" ] +debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier2d/debug-render" ] parallel = [ "rapier2d/parallel" ] simd-stable = [ "rapier2d/simd-stable" ] simd-nightly = [ "rapier2d/simd-nightly" ] diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index cba68f75..92f2b2c4 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -21,8 +21,8 @@ required-features = [ "dim3" ] default = [ "dim3", "async-collider", "debug-render-3d" ] dim3 = ["bevy/bevy_render"] debug-render = [ "debug-render-3d" ] -debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_render", "rapier3d/debug-render" ] -debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_render", "rapier3d/debug-render" ] +debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier3d/debug-render" ] +debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier3d/debug-render" ] parallel = [ "rapier3d/parallel" ] simd-stable = [ "rapier3d/simd-stable" ] simd-nightly = [ "rapier3d/simd-nightly" ] diff --git a/src/render/lines/debuglines.wgsl b/src/render/lines/debuglines.wgsl deleted file mode 100644 index 4f5a373e..00000000 --- a/src/render/lines/debuglines.wgsl +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef LINES_3D - #import bevy_pbr::mesh_view_bindings -#else - #import bevy_sprite::mesh2d_view_bindings -#endif - -struct Vertex { - @location(0) pos: vec3, - @location(1) color: vec4, -} - -struct VertexOutput { - @builtin(position) clip_position: vec4, - @location(0) color: vec4, -} - -struct FragmentOutput { -#ifdef LINES_3D // We don’t need frag_depth 2D. - @builtin(frag_depth) depth: f32, -#endif - @location(0) color: vec4, -} - -@vertex -fn vertex(vertex: Vertex) -> VertexOutput { - var out: VertexOutput; - - out.clip_position = view.view_proj * vec4(vertex.pos, 1.0); - out.color = vertex.color; - - return out; -} - -@fragment -fn fragment(in: VertexOutput) -> FragmentOutput { - var out: FragmentOutput; - -// This should be #ifdef DEPTH_TEST_ENABLED && LINES_3D, but the -// preprocessor doesn't support that yet. -// Luckily, DEPTH_TEST_ENABLED isn't set in 2d anyway. -#ifdef LINES_3D - #ifdef DEPTH_TEST_ENABLED - out.depth = in.clip_position.z; - #else - out.depth = 1.0; - #endif -#endif - out.color = in.color; - return out; -} diff --git a/src/render/lines/mod.rs b/src/render/lines/mod.rs deleted file mode 100644 index d583fd44..00000000 --- a/src/render/lines/mod.rs +++ /dev/null @@ -1,397 +0,0 @@ -#![allow(warnings)] - -/** - * - * NOTE: this module and its submodules are only temporary. It is a copy-paste of the bevy-debug-lines - * crate: https://github.com/Toqozz/bevy_debug_lines (MIT license) - * It has been partially updated to work with bevy 0.7, but hasn’t been released yet. - * So, in the mean time, we are keeping a version here that we will replace by the - * upstream dependency once: - * 1. The version compatible with bevy 0.7 is released to crates.io. - * 2. We find a way to make the 2D version work with our examples. The problem - * only happens when running our own examples because cargo’s unification of - * features will enable the `3d` feature of `bevy_debug_lines` when running - * a `2d` example. - * - */ -use bevy::{ - asset::{load_internal_asset, Assets, HandleUntyped}, - prelude::*, - reflect::TypeUuid, - render::{ - mesh::{/*Indices,*/ Mesh, VertexAttributeValues}, - render_phase::AddRenderCommand, - render_resource::PrimitiveTopology, - render_resource::Shader, - view::NoFrustumCulling, - Extract, Render, - }, -}; -use std::sync::{Arc, RwLock}; - -mod render_dim; - -// This module exists to "isolate" the `#[cfg]` attributes to this part of the -// code. Otherwise, we would pollute the code with a lot of feature -// gates-specific code. -#[cfg(feature = "debug-render-3d")] -mod dim3 { - pub(crate) use super::render_dim::r3d::{queue, DebugLinePipeline, DrawDebugLines}; - pub(crate) use bevy::core_pipeline::core_3d::Opaque3d as Phase; -} -#[cfg(feature = "debug-render-2d")] -mod dim2 { - pub(crate) use super::render_dim::r2d::{queue, DebugLinePipeline, DrawDebugLines}; - pub(crate) use bevy::core_pipeline::core_2d::Transparent2d as Phase; -} - -pub(crate) const SHADER_FILE: &str = include_str!("debuglines.wgsl"); -pub(crate) const DEBUG_LINES_SHADER_HANDLE: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 17477439189930443325); - -#[derive(Resource, Clone)] -pub(crate) struct DebugLinesConfig { - pub always_on_top: Arc>, // Don’t know how to do this properly since this resource lives in a sub-app. -} - -impl DebugLinesConfig { - fn always_on_top(on_top: bool) -> Self { - Self { - always_on_top: Arc::new(RwLock::new(on_top)), - } - } -} - -/// Bevy plugin, for initializing stuff. -/// -/// # Usage -/// -/// ```.ignore -/// use bevy::prelude::*; -/// use bevy_prototype_debug_lines::*; -/// -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugin(DebugLinesPlugin::default()) -/// .run(); -/// ``` -/// -/// Alternatively, you can initialize the plugin with depth testing, so that -/// debug lines cut through geometry. To do this, use [`DebugLinesPlugin::with_depth_test(true)`]. -/// ```.ignore -/// use bevy::prelude::*; -/// use bevy_prototype_debug_lines::*; -/// -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugin(DebugLinesPlugin::with_depth_test(true)) -/// .run(); -/// ``` -#[derive(Debug, Default, Clone)] -pub struct DebugLinesPlugin { - always_on_top: bool, -} - -impl DebugLinesPlugin { - /// Controls whether debug lines should be drawn with depth testing enabled - /// or disabled. - /// - /// # Arguments - /// - /// * `val` - True if lines should intersect with other geometry, or false - /// if lines should always draw on top be drawn on top (the default). - pub fn always_on_top(val: bool) -> Self { - Self { always_on_top: val } - } -} - -#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)] -pub struct DrawLinesLabel; - -impl Plugin for DebugLinesPlugin { - fn build(&self, app: &mut App) { - use bevy::render::{render_resource::SpecializedMeshPipelines, RenderApp, RenderSet}; - let mut shaders = app.world.get_resource_mut::>().unwrap(); - shaders.set_untracked(DEBUG_LINES_SHADER_HANDLE, Shader::from_wgsl(SHADER_FILE)); - - let lines_config = DebugLinesConfig::always_on_top(self.always_on_top); - app.init_resource::() - .add_startup_system(setup) - .add_systems(PostUpdate, update.in_set(DrawLinesLabel)) - .insert_resource(lines_config.clone()); - - #[cfg(feature = "debug-render-3d")] - app.sub_app_mut(RenderApp) - .add_render_command::() - .init_resource::() - .init_resource::>() - .add_systems(Render, dim3::queue.in_set(RenderSet::Queue)); - - #[cfg(feature = "debug-render-2d")] - app.sub_app_mut(RenderApp) - .add_render_command::() - .init_resource::() - .init_resource::>() - .add_systems(Render, dim2::queue.in_set(RenderSet::Queue)); - - app.sub_app_mut(RenderApp) - .insert_resource(lines_config) - .add_systems(ExtractSchedule, extract); - - #[cfg(feature = "debug-render-3d")] - info!("Loaded 3d debug lines plugin."); - #[cfg(feature = "debug-render-2d")] - info!("Loaded 2d debug lines plugin."); - } -} - -// Number of meshes to separate line buffers into. -// We don't really do culling currently but this is a gateway to that. -const MESH_COUNT: usize = 4; -// Maximum number of points for each individual mesh. -const MAX_POINTS_PER_MESH: usize = 2_usize.pow(16); -const _MAX_LINES_PER_MESH: usize = MAX_POINTS_PER_MESH / 2; -/// Maximum number of points. -pub const MAX_POINTS: usize = MAX_POINTS_PER_MESH * MESH_COUNT; -/// Maximum number of unique lines to draw at once. -pub const MAX_LINES: usize = MAX_POINTS / 2; - -fn setup(mut cmds: Commands, mut meshes: ResMut>) { - // Spawn a bunch of meshes to use for lines. - for i in 0..MESH_COUNT { - // Create a new mesh with the number of vertices we need. - let mut mesh = Mesh::new(PrimitiveTopology::LineList); - mesh.insert_attribute( - Mesh::ATTRIBUTE_POSITION, - VertexAttributeValues::Float32x3(Vec::with_capacity(MAX_POINTS_PER_MESH)), - ); - mesh.insert_attribute( - Mesh::ATTRIBUTE_COLOR, - VertexAttributeValues::Float32x4(Vec::with_capacity(MAX_POINTS_PER_MESH)), - ); - // https://github.com/Toqozz/bevy_debug_lines/issues/16 - //mesh.set_indices(Some(Indices::U16(Vec::with_capacity(MAX_POINTS_PER_MESH)))); - - let mesh_handle = meshes.add(mesh); - - cmds.spawn(( - SpatialBundle::INHERITED_IDENTITY, - NoFrustumCulling, - DebugLinesMesh(i), - #[cfg(feature = "debug-render-3d")] - ( - mesh_handle.clone(), - bevy::pbr::NotShadowCaster, - bevy::pbr::NotShadowReceiver, - ), - #[cfg(feature = "debug-render-2d")] - bevy::sprite::Mesh2dHandle(mesh_handle), - )); - } -} - -fn update( - #[cfg(feature = "debug-render-3d")] debug_line_meshes_3d: Query<( - &Handle, - &DebugLinesMesh, - )>, - #[cfg(feature = "debug-render-2d")] debug_line_meshes_2d: Query<( - &bevy::sprite::Mesh2dHandle, - &DebugLinesMesh, - )>, - time: Res