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 all 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
8 changes: 4 additions & 4 deletions bevy_rapier2d/Cargo.toml
Expand Up @@ -37,8 +37,8 @@ async-collider = [ ]


[dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
nalgebra = { version = "0.32.0", features = [ "convert-glam022" ] }
bevy = { version = "0.10", 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"
bitflags = "1"
Expand All @@ -47,10 +47,10 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["x11"]}
bevy = { version = "0.10", default-features = false, features = ["x11"]}
oorandom = "11"
approx = "0.5.1"
glam = { version = "0.22", features = [ "approx" ] }
glam = { version = "0.23", features = [ "approx" ] }

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
Expand Down
141 changes: 52 additions & 89 deletions bevy_rapier2d/examples/custom_system_setup2.rs
@@ -1,41 +1,8 @@
use bevy::{core::FrameCount, prelude::*};
use bevy::{core::FrameCount, ecs::schedule::ScheduleLabel, prelude::*};
use bevy_rapier2d::prelude::*;

struct SpecialStagingPlugin {
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);
}
}
#[derive(ScheduleLabel, Hash, Debug, PartialEq, Eq, Clone)]
struct SpecialSchedule;

fn main() {
let mut app = App::new();
Expand All @@ -48,71 +15,67 @@ 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(
(|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();

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

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_plugin(
RapierPhysicsPlugin::<NoUserData>::default()
.with_physics_scale(100.)
.with_default_system_setup(false),
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.add_schedule(SpecialSchedule, schedule)
.add_plugin(
RapierPhysicsPlugin::<NoUserData>::default()
.with_physics_scale(100.)
.with_default_system_setup(false),
)
.run();
}

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();
if let Some(entity) = query
.iter()
.skip(frame_count.0 as usize % count) // Get a "random" box to make sim interesting
.take(1)
.next()
{
let len = query.iter().len();
// Get a "random" box to make sim interesting
if let Some(entity) = query.iter().nth(frame_count.0 as usize % len) {
commands.entity(entity).despawn();
}
}
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier2d/examples/debug_despawn2.rs
Expand Up @@ -258,7 +258,7 @@ fn clear_filled_rows(
}

for row_blocks in blocks_per_row {
if row_blocks.len() == game.n_lanes as usize {
if row_blocks.len() == game.n_lanes {
game.stats.cleared_blocks += game.n_lanes as i32;

for block_entity in row_blocks {
Expand Down
6 changes: 3 additions & 3 deletions 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 All @@ -26,11 +26,11 @@ fn display_events(
mut contact_force_events: EventReader<ContactForceEvent>,
) {
for collision_event in collision_events.iter() {
println!("Received collision event: {:?}", collision_event);
println!("Received collision event: {collision_event:?}");
}

for contact_force_event in contact_force_events.iter() {
println!("Received contact force event: {:?}", contact_force_event);
println!("Received contact force event: {contact_force_event:?}");
}
}

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
8 changes: 4 additions & 4 deletions bevy_rapier3d/Cargo.toml
Expand Up @@ -38,8 +38,8 @@ headless = [ ]
async-collider = [ ]

[dependencies]
bevy = { version = "0.9.0", default-features = false, features = ["bevy_asset", "bevy_scene"] }
nalgebra = { version = "^0.32.0", features = [ "convert-glam022" ] }
bevy = { version = "0.10", 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"
bitflags = "1"
Expand All @@ -48,9 +48,9 @@ log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

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

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
Expand Down