Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bevy 0.10 #324

Merged
merged 19 commits into from Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions bevy_rapier2d/Cargo.toml
Expand Up @@ -37,7 +37,8 @@ async-collider = [ ]


[dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
bevy = { path = "../../bevy", default-features = false, features = ["bevy_asset", "bevy_scene"] }
irate-devil marked this conversation as resolved.
Show resolved Hide resolved
# bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
nalgebra = { version = "0.32.0", features = [ "convert-glam022" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier2d = "0.17.0"
Expand All @@ -47,7 +48,7 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["x11"]}
bevy = { path = "../../bevy", default-features = false, features = ["x11"]}
oorandom = "11"
approx = "0.5.1"
glam = { version = "0.22", features = [ "approx" ] }
Expand Down
134 changes: 52 additions & 82 deletions bevy_rapier2d/examples/custom_system_setup2.rs
@@ -1,42 +1,11 @@
use bevy::{core::FrameCount, prelude::*};
use bevy_rapier2d::prelude::*;

struct SpecialStagingPlugin {
#[derive(Resource)]
struct SpecialSchedule {
schedule: Schedule,
}

impl SpecialStagingPlugin {
pub fn new(schedule: Schedule) -> Self {
Self { schedule }
}
}

impl SpecialStagingPlugin {
fn build(self, app: &mut App) {
app.add_stage_after(
CoreStage::Update,
"special_staging_plugin_stage",
SpecialStage::new(self.schedule),
);
}
}

struct SpecialStage {
schedule: Schedule,
}

impl SpecialStage {
pub fn new(schedule: Schedule) -> Self {
Self { schedule }
}
}

impl Stage for SpecialStage {
fn run(&mut self, world: &mut World) {
self.schedule.run_once(world);
}
}

fn main() {
let mut app = App::new();

Expand All @@ -48,69 +17,70 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(RapierDebugRenderPlugin::default())
.add_startup_system(setup_graphics)
.add_startup_system(setup_physics);

// Do the stage setup however we want, maybe in a special plugin that has
// its very own schedule
SpecialStagingPlugin::new(
Schedule::default()
.with_stage(
PhysicsStages::SyncBackend,
SystemStage::parallel().with_system_set(
RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsStages::SyncBackend),
),
)
.with_stage_after(
PhysicsStages::SyncBackend,
PhysicsStages::StepSimulation,
SystemStage::parallel()
.with_system(despawn_one_box) // We can add a special despawn to determine cleanup later
.with_system_set(RapierPhysicsPlugin::<NoUserData>::get_systems(
PhysicsStages::StepSimulation,
)),
)
.with_stage_after(
PhysicsStages::StepSimulation,
PhysicsStages::Writeback,
SystemStage::parallel().with_system_set(
RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsStages::Writeback),
),
),
)
.build(&mut app);

// Be sure to setup all four stages
app.add_stage_before(
CoreStage::Last,
PhysicsStages::DetectDespawn,
SystemStage::parallel().with_system_set(RapierPhysicsPlugin::<NoUserData>::get_systems(
PhysicsStages::DetectDespawn,
)),
.add_startup_system(setup_physics)
.add_system(run_schedule.in_base_set(CoreSet::PostUpdate));

// Do the setup however we want, maybe in its very own schedule
let mut schedule = Schedule::new();

schedule.configure_sets(
(
PhysicsSet::SyncBackend,
PhysicsSet::SyncBackendFlush,
PhysicsSet::StepSimulation,
PhysicsSet::Writeback,
)
.chain(),
);

app.add_plugin(
RapierPhysicsPlugin::<NoUserData>::default()
.with_physics_scale(100.)
.with_default_system_setup(false),
schedule.add_systems(
RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::SyncBackend)
.in_base_set(PhysicsSet::SyncBackend),
);

// schedule.add_systems(
// RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::SyncBackendFlush)
// .in_base_set(PhysicsSet::SyncBackendFlush),
// );
app.add_system(apply_system_buffers.in_base_set(PhysicsSet::SyncBackendFlush));

schedule.add_systems(
RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::StepSimulation)
.in_base_set(PhysicsSet::StepSimulation),
);
schedule.add_system(despawn_one_box.in_base_set(PhysicsSet::StepSimulation));

app.run();
schedule.add_systems(
RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::Writeback)
.in_base_set(PhysicsSet::Writeback),
);

app.insert_resource(SpecialSchedule { schedule })
.add_plugin(
RapierPhysicsPlugin::<NoUserData>::default()
.with_physics_scale(100.)
.with_default_system_setup(false),
)
.run();
}

fn run_schedule(world: &mut World) {
world.resource_scope(|world, mut special: Mut<SpecialSchedule>| {
special.schedule.run(world);
})
}

fn despawn_one_box(
mut commands: Commands,
mut frame_count: ResMut<FrameCount>,
frame_count: ResMut<FrameCount>,
query: Query<Entity, (With<Collider>, With<RigidBody>)>,
) {
frame_count.0 += 1;

// Delete a box every 10 frames
if frame_count.0 % 10 == 0 && !query.is_empty() {
let count = query.iter().count();
let len = query.iter().len();
if let Some(entity) = query
.iter()
.skip(frame_count.0 as usize % count) // Get a "random" box to make sim interesting
.take(1)
.skip(frame_count.0 as usize % len) // Get a "random" box to make sim interesting
.next()
{
commands.entity(entity).despawn();
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier2d/examples/events2.rs
Expand Up @@ -13,7 +13,7 @@ fn main() {
.add_plugin(RapierDebugRenderPlugin::default())
.add_startup_system(setup_graphics)
.add_startup_system(setup_physics)
.add_system_to_stage(CoreStage::PostUpdate, display_events)
.add_system(display_events.in_base_set(CoreSet::PostUpdate))
.run();
}

Expand Down
11 changes: 5 additions & 6 deletions bevy_rapier2d/examples/player_movement2.rs
@@ -1,15 +1,14 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::WindowResolution};
use bevy_rapier2d::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
primary_window: Some(Window {
resolution: WindowResolution::new(1000., 1000.),
title: "Player Movement Example".to_string(),
width: 1000.0,
height: 1000.0,
..Default::default()
},
..default()
}),
..default()
}))
.add_startup_system(spawn_player)
Expand Down
5 changes: 3 additions & 2 deletions bevy_rapier3d/Cargo.toml
Expand Up @@ -38,7 +38,8 @@ headless = [ ]
async-collider = [ ]

[dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
bevy = { path = "../../bevy", default-features = false, features = ["bevy_asset", "bevy_scene"] }
# bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
nalgebra = { version = "^0.32.0", features = [ "convert-glam022" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier3d = "0.17.0"
Expand All @@ -48,7 +49,7 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["x11"]}
bevy = { path = "../../bevy", default-features = false, features = ["x11"]}
approx = "0.5.1"
glam = { version = "0.22", features = [ "approx" ] }

Expand Down