Skip to content

Commit

Permalink
Upgrade Avian to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
idanarye committed Dec 21, 2024
1 parent d6c593a commit 26cd95e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bevy = { version = "^0.15", default-features = false, features = [
"x11",
# "filesystem_watcher",
] }
avian3d = { git = "https://github.com/Jondolf/avian", features = ["3d", "debug-plugin", "parallel", "parry-f32"] }
avian3d = { version = "^0.2", features = ["3d", "debug-plugin", "parallel", "parry-f32"] }
bevy-tnua-avian3d = { path = "avian3d" }

[package.metadata.docs.rs]
Expand Down
10 changes: 7 additions & 3 deletions avian2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ readme = "../README.md"

[dependencies]
bevy = { version = "^0.15", default-features = false }
avian2d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["2d", "debug-plugin", "parallel"]}
avian2d = { version = "^0.2", default-features = false, features = ["2d", "debug-plugin", "parallel"]}
bevy-tnua-physics-integration-layer = { version = "^0.5", path = "../physics-integration-layer" }

[package.metadata.docs.rs]
all-features = true
features = ["bevy/bevy_asset"]

[features]
default = [ "avian2d/parry-f32" ]
f64 = ["avian2d/parry-f64", "bevy-tnua-physics-integration-layer/f64" ]
default = [ "avian2d/f32", "avian2d/parry-f32" ]
f64 = [
"avian2d/f64",
"avian2d/parry-f64",
"bevy-tnua-physics-integration-layer/f64",
]
6 changes: 0 additions & 6 deletions avian2d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ impl TnuaAvian2dPlugin {
}
}

impl Default for TnuaAvian2dPlugin {
fn default() -> Self {
Self::new(Update)
}
}

impl Plugin for TnuaAvian2dPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
Expand Down
8 changes: 8 additions & 0 deletions avian3d/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ NOTES:
* Avian used to be named bevy_xpbd. The old bevy-tnua-xpbd changelog can be seen [here](https://github.com/idanarye/bevy-tnua/blob/3cba881c8825633a8d8bdca1fe30e54500e655b8/xpbd3d/CHANGELOG.md).

## [Unreleased]
### Changed
- Upgrade to Bevy 0.15 and avian 0.2.

### Removed
- `TnuaAvian#dPlugin` no longer implements `Default`. Since Avian changed their
default schedule from `PostUpdate` to `FixedPostUpdate`, user code that just
uses the de-facto default `Update` will start having weird results. This
forces the user to make a deliberate decision regarding which schedule to run.

## 0.1.1 - 2024-08-02
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion avian3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "../README.md"

[dependencies]
bevy = { version = "^0.15", default-features = false }
avian3d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["3d", "debug-plugin", "parallel"] }
avian3d = { version = "^0.2", default-features = false, features = ["3d", "debug-plugin", "parallel"] }
bevy-tnua-physics-integration-layer = { version = "^0.5", path = "../physics-integration-layer" }

[package.metadata.docs.rs]
Expand Down
6 changes: 0 additions & 6 deletions avian3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ impl TnuaAvian3dPlugin {
}
}

impl Default for TnuaAvian3dPlugin {
fn default() -> Self {
Self::new(Update)
}
}

impl Plugin for TnuaAvian3dPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
Expand Down
12 changes: 8 additions & 4 deletions demos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ exclude = [

[features]
default = [
"avian3d?/parry-f32",
"avian2d?/f32",
"avian2d?/parry-f32",
"avian3d?/f32",
"avian3d?/parry-f32",
# Comment these out when Bevy gets upgraded and a dependency lags behind
"egui",
]
Expand All @@ -20,8 +22,10 @@ rapier = []
rapier2d = ["rapier", "dep:bevy_rapier2d", "dep:bevy-tnua-rapier2d"]
rapier3d = ["rapier", "dep:bevy_rapier3d", "dep:bevy-tnua-rapier3d"]
f64 = [
"avian3d?/parry-f64",
"avian2d?/f64",
"avian2d?/parry-f64",
"avian3d?/f64",
"avian3d?/parry-f64",
"bevy-tnua-physics-integration-layer/f64",
"bevy-tnua/f64",
]
Expand Down Expand Up @@ -61,10 +65,10 @@ bevy-tnua-rapier2d = { path = "../rapier2d", optional = true }
bevy_rapier3d = { version = "^0.28", features = ["debug-render-3d"], optional = true }
bevy-tnua-rapier3d = { path = "../rapier3d", optional = true }

avian2d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["2d","debug-plugin", "parallel"], optional = true}
avian2d = { version = "^0.2", default-features = false, features = ["2d","debug-plugin", "parallel"], optional = true}
bevy-tnua-avian2d = { path = "../avian2d", default-features = false, optional = true }

avian3d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["3d","debug-plugin", "parallel"], optional = true }
avian3d = { version = "^0.2", default-features = false, features = ["3d","debug-plugin", "parallel"], optional = true }
bevy-tnua-avian3d = { path = "../avian3d", default-features = false, optional = true }

bevy_egui = { version = "0.31", optional = true, default-features = false, features = ["default_fonts", "render"] }
Expand Down
20 changes: 19 additions & 1 deletion demos/src/app_setup_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use clap::{Parser, ValueEnum};

#[derive(Resource, Debug, Parser, Clone)]
pub struct AppSetupConfiguration {
#[arg(long = "schedule", default_value = "update")]
//#[arg(long = "schedule", default_value = "update")]
#[arg(long = "schedule", default_value_t = if cfg!(feature = "avian") {
ScheduleToUse::FixedUpdate
} else {
ScheduleToUse::Update
})]
pub schedule_to_use: ScheduleToUse,
#[arg(long = "level")]
pub level_to_load: Option<String>,
Expand All @@ -25,6 +30,8 @@ impl AppSetupConfiguration {
Self {
schedule_to_use: if let Some(value) = url_params.get("schedule") {
ScheduleToUse::from_str(&value, true).unwrap()
} else if cfg!(feature = "avian") {
ScheduleToUse::FixedUpdate
} else {
ScheduleToUse::Update
},
Expand Down Expand Up @@ -63,6 +70,17 @@ pub enum ScheduleToUse {
PhysicsSchedule,
}

impl std::fmt::Display for ScheduleToUse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Update => "update",
Self::FixedUpdate => "fixed-update",
#[cfg(feature = "avian")]
Self::PhysicsSchedule => "physics-schedule",
})
}
}

impl ScheduleToUse {
#[cfg(feature = "egui")]
pub fn pick_different_option(&self, ui: &mut egui::Ui) -> Option<Self> {
Expand Down
6 changes: 3 additions & 3 deletions demos/src/bin/platformer_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ fn main() {
app.add_plugins(PhysicsDebugPlugin::default());
match app_setup_configuration.schedule_to_use {
ScheduleToUse::Update => {
app.add_plugins(PhysicsPlugins::default());
app.add_plugins(PhysicsPlugins::new(PostUpdate));
// To use Tnua with avian2d, you need the `TnuaAvian2dPlugin` plugin from
// bevy-tnua-avian2d.
app.add_plugins(TnuaAvian2dPlugin::default());
app.add_plugins(TnuaAvian2dPlugin::new(Update));
}
ScheduleToUse::FixedUpdate => {
app.add_plugins(PhysicsPlugins::new(FixedUpdate));
app.add_plugins(PhysicsPlugins::new(FixedPostUpdate));
app.add_plugins(TnuaAvian2dPlugin::new(FixedUpdate));
}
ScheduleToUse::PhysicsSchedule => {
Expand Down
6 changes: 3 additions & 3 deletions demos/src/bin/platformer_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ fn main() {
{
match app_setup_configuration.schedule_to_use {
ScheduleToUse::Update => {
app.add_plugins(PhysicsPlugins::default());
app.add_plugins(PhysicsPlugins::new(PostUpdate));
// To use Tnua with avian3d, you need the `TnuaAvian3dPlugin` plugin from
// bevy-tnua-avian3d.
app.add_plugins(TnuaAvian3dPlugin::default());
app.add_plugins(TnuaAvian3dPlugin::new(Update));
}
ScheduleToUse::FixedUpdate => {
app.add_plugins(PhysicsPlugins::new(FixedUpdate));
app.add_plugins(PhysicsPlugins::new(FixedPostUpdate));
app.add_plugins(TnuaAvian3dPlugin::new(FixedUpdate));
}
ScheduleToUse::PhysicsSchedule => {
Expand Down
6 changes: 3 additions & 3 deletions demos/src/bin/shooter_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ fn main() {
{
match app_setup_configuration.schedule_to_use {
ScheduleToUse::Update => {
app.add_plugins(PhysicsPlugins::default());
app.add_plugins(PhysicsPlugins::new(PostUpdate));
// To use Tnua with avian3d, you need the `TnuaAvian3dPlugin` plugin from
// bevy-tnua-avian3d.
app.add_plugins(TnuaAvian3dPlugin::default());
app.add_plugins(TnuaAvian3dPlugin::new(Update));
}
ScheduleToUse::FixedUpdate => {
app.add_plugins(PhysicsPlugins::new(FixedUpdate));
app.add_plugins(PhysicsPlugins::new(FixedPostUpdate));
app.add_plugins(TnuaAvian3dPlugin::new(FixedUpdate));
}
ScheduleToUse::PhysicsSchedule => {
Expand Down
9 changes: 6 additions & 3 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ fn main() {
PhysicsPlugins::default(),
// We need both Tnua's main controller plugin, and the plugin to connect to the physics
// backend (in this case XBPD-3D)
TnuaControllerPlugin::default(),
TnuaAvian3dPlugin::default(),
TnuaControllerPlugin::new(FixedUpdate),
TnuaAvian3dPlugin::new(FixedUpdate),
))
.add_systems(
Startup,
(setup_camera_and_lights, setup_level, setup_player),
)
.add_systems(Update, apply_controls.in_set(TnuaUserControlsSystemSet))
.add_systems(
FixedUpdate,
apply_controls.in_set(TnuaUserControlsSystemSet),
)
.run();
}

Expand Down
6 changes: 3 additions & 3 deletions examples/example_animating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn main() {
.add_plugins((
DefaultPlugins,
PhysicsPlugins::default(),
TnuaControllerPlugin::default(),
TnuaAvian3dPlugin::default(),
TnuaControllerPlugin::new(FixedUpdate),
TnuaAvian3dPlugin::new(FixedUpdate),
))
.add_systems(
Startup,
(setup_camera_and_lights, setup_level, setup_player),
)
.add_systems(
Update,
FixedUpdate,
(
apply_controls.in_set(TnuaUserControlsSystemSet),
prepare_animations,
Expand Down

0 comments on commit 26cd95e

Please sign in to comment.