Skip to content

Commit

Permalink
update to bevy 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Nov 7, 2023
1 parent 40dc555 commit df2922f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ name = "bevy_mod_physx"
path = "src/lib.rs"

[dependencies]
bevy = "0.11.0"
bevy = "0.12.0"
derive_more = "0.99.17"
enumflags2 = "0.7.7"
physx = "0.19.0"
physx-sys = "0.11.5"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
bevy-inspector-egui = "0.20.0"
bevy-inspector-egui = "0.21.0"

[features]
serialize = ["dep:serde", "bevy/serialize"]
10 changes: 7 additions & 3 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Duration;

use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::input::common_conditions::input_toggle_active;
use bevy::pbr::DirectionalLightShadowMap;
use bevy::pbr::{DirectionalLightShadowMap, ShadowFilteringMethod};
use bevy::prelude::*;
use bevy_mod_physx::prelude::*;

Expand Down Expand Up @@ -48,6 +48,9 @@ impl Plugin for DemoUtils {
brightness: 1.0 / 5.0f32,
});
app.insert_resource(Msaa::default());

// using 4096x4096 shadow maps to get the best possible quality
// for demos, but it's not great for performance
app.insert_resource(DirectionalLightShadowMap { size: 4096 });

// log fps to console
Expand All @@ -68,7 +71,7 @@ impl Plugin for DemoUtils {
app.add_systems(Update, spacebar_pauses_simulation);

if SIMULATION_STARTS_PAUSED {
app.add_systems(Startup, |mut time: ResMut<Time>| time.pause());
app.add_systems(Startup, |mut time: ResMut<Time<Virtual>>| time.pause());
}

app.add_systems(Update, bevy::window::close_on_esc);
Expand Down Expand Up @@ -102,6 +105,7 @@ fn adjust_camera_settings(
let (yaw, pitch, _roll) = transform.rotation.to_euler(EulerRot::YXZ);

commands.entity(entity)
.insert(ShadowFilteringMethod::Jimenez14)
.insert(OrbitCamera {
gimbal_x: -yaw,
gimbal_y: -pitch,
Expand All @@ -113,7 +117,7 @@ fn adjust_camera_settings(

fn spacebar_pauses_simulation(
keys: Res<Input<KeyCode>>,
mut time: ResMut<Time>,
mut time: ResMut<Time<Virtual>>,
) {
if keys.just_pressed(KeyCode::Space) {
if time.is_paused() {
Expand Down
8 changes: 4 additions & 4 deletions examples/common/orbit_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ fn apply_camera_controls(

let mut events = vec![];

for ev in scroll_events.iter() {
for ev in scroll_events.read() {
events.push(MyEvent::Zoom(ev.y));
}

if buttons.pressed(MouseButton::Left) {
for ev in move_events.iter() {
for ev in move_events.read() {
events.push(MyEvent::Rotate((ev.delta.x, ev.delta.y)));
}
} else if buttons.pressed(MouseButton::Right) {
for ev in move_events.iter() {
for ev in move_events.read() {
events.push(MyEvent::Pan((ev.delta.x, ev.delta.y)));
}
}

for ev in gamepad_events.iter() {
for ev in gamepad_events.read() {
match ev {
GamepadEvent::Axis(ev) => {
match ev.axis_type {
Expand Down
2 changes: 1 addition & 1 deletion examples/detect_contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn highlight_on_hit(
mut events: EventReader<CollisionEvent>,
highlighable: Query<(), With<Highlightable>>,
) {
for event in events.iter() {
for event in events.read() {
for entity in [ event.actor0, event.actor1 ] {
if highlighable.get(entity).is_ok() {
commands.entity(entity)
Expand Down
4 changes: 2 additions & 2 deletions examples/test_fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
// this example demonstrates how to run physics within bevy's FixedTimestep,
// you can similar approach if you need to control when to run physics (e.g. pause on demand)
App::new()
.insert_resource(FixedTime::new_from_secs(0.05))
.insert_resource(Time::<Fixed>::from_seconds(0.05))
.add_plugins(DefaultPlugins)
.add_plugins(PhysicsPlugins.set(
PhysicsCore::new()
Expand All @@ -24,7 +24,7 @@ fn main() {
}

pub fn run_physics_schedule(world: &mut World) {
let period = world.resource::<FixedTime>().period;
let period = world.resource::<Time<Fixed>>().timestep();
let mut pxtime = world.resource_mut::<PhysicsTime>();
pxtime.update(period);
world.run_schedule(PhysicsSchedule);
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use physx_sys::{

use crate::prelude::{self as bpx, *};

#[derive(TypeUuid, TypePath, Clone, Deref, DerefMut)]
#[derive(Asset, TypeUuid, TypePath, Clone, Deref, DerefMut)]
#[uuid = "db246120-e6af-4ebf-a95a-a6efe1c54d9f"]
/// Geometry object defines the characteristics of a spatial object.
pub struct Geometry {
Expand Down
2 changes: 1 addition & 1 deletion src/core/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use physx::prelude::*;
use crate::prelude as bpx;
use crate::types::PxMaterial;

#[derive(TypeUuid, TypePath, Deref, DerefMut)]
#[derive(Asset, TypeUuid, TypePath, Deref, DerefMut)]
#[uuid = "5351ec05-c0fd-426a-b35e-62008a6b10e1"]
/// Material object represents a set of surface properties.
pub struct Material(Owner<PxMaterial>);
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ impl Plugin for PhysicsCore {
app.add_plugins(AssetPlugin::default());
}

app.add_asset::<bpx::Geometry>();
app.add_asset::<bpx::Material>();
app.init_asset::<bpx::Geometry>();
app.init_asset::<bpx::Material>();

app.register_type::<PhysicsTime>();
app.insert_resource(PhysicsTime::new(self.timestep));
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kinematic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn kinematic_disable(
mut removed: RemovedComponents<Kinematic>,
mut handles: Query<&mut RigidDynamicHandle>,
) {
for entity in removed.iter() {
for entity in removed.read() {
if let Ok(mut actor) = handles.get_mut(entity) {
let mut rigid_body = actor.get_mut(&mut scene);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn sleep_marker_sync(
mut commands: Commands,
mut events: EventReader<WakeSleepEvent>,
) {
for WakeSleepEvent { entities, is_waking } in events.iter() {
for WakeSleepEvent { entities, is_waking } in events.read() {
for entity in entities.iter() {
let Some(mut cmd) = commands.get_entity(*entity) else { continue; };
if *is_waking {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

use std::sync::mpsc::Receiver;
use std::sync::Mutex;

use bevy::ecs::event::event_update_system;
use bevy::prelude::*;

use crate::{PhysicsSchedule, PhysicsSet};

#[derive(Resource, Deref, DerefMut)]
Expand All @@ -36,7 +39,7 @@ impl AppExtensions for App {
if !self.world.contains_resource::<Events<T>>() {
self.init_resource::<Events<T>>();
self.add_systems(PhysicsSchedule, (
Events::<T>::update_system,
event_update_system::<T>,
).before(PhysicsSet::Create));
}
self
Expand All @@ -51,7 +54,7 @@ impl AppExtensions for App {
self.add_event::<T>();
self.add_systems(PhysicsSchedule, (
channel_to_event::<T>,
).after(Events::<T>::update_system).before(PhysicsSet::Create));
).after(event_update_system::<T>).before(PhysicsSet::Create));

self.insert_resource(ChannelReceiver(Mutex::new(receiver)));
self
Expand All @@ -66,7 +69,7 @@ impl AppExtensions for App {
self.add_physics_event::<T>();
self.add_systems(PhysicsSchedule, (
channel_to_event::<T>,
).after(Events::<T>::update_system).before(PhysicsSet::Create));
).after(event_update_system::<T>).before(PhysicsSet::Create));

self.insert_resource(ChannelReceiver(Mutex::new(receiver)));
self
Expand Down

0 comments on commit df2922f

Please sign in to comment.