Skip to content

Commit 48e9553

Browse files
committed
Migrating to Bevy 0.16
* Some useful references that informed changes: * https://bevyengine.org/learn/migration-guides/0-15-to-0-16/ * bevyengine/bevy#8265 * Cargo clippy fix over all code * Updated simple example so it works with Bevy 0.16
1 parent 73e4969 commit 48e9553

File tree

10 files changed

+57
-37
lines changed

10 files changed

+57
-37
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_godot4"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2024"
55

66
[lib]
@@ -12,8 +12,8 @@ assets = [] # experimental feature, see assets::GodotResourceLoader
1212

1313
[dependencies]
1414
anyhow = "1"
15-
bevy = { version = "0.15", default-features = false, features = ["bevy_asset"] }
15+
bevy = { version = "0.16", default-features = false, features = ["bevy_asset", "bevy_log"] }
1616
godot = "0.2.4"
1717
bevy_godot4_proc_macros = { path = "./proc_macros" }
18-
lazy_static = "1.4.0"
18+
lazy_static = "1.5.0"
1919
send_wrapper = "0.6"

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,41 @@ The architecture in this crate is based on [bevy_godot](https://github.com/rand0
1313

1414
1. Follow the steps outlined in the [GDExtension Getting Started](https://godot-rust.github.io/book/intro/index.html).
1515

16-
2. Add this library as a dependency (along with the GDExtension godot crate):
17-
```
16+
2. Add this library as a dependency (along with the GDExtension godot crate):
17+
```toml
1818
[dependencies]
19+
bevy = { version = "0.16", default-features = false, features = [
20+
"bevy_asset",
21+
"bevy_state",
22+
] }
1923
bevy_godot4 = { git = "https://github.com/jrockett6/bevy_godot4", branch = "main" }
20-
godot = "0.1.3"
24+
godot = "0.2.4"
2125
```
26+
27+
> **_NOTE:_** You can, of course, enable other features in `bevy`; in the above
28+
> example, we've simply minimized our feature set in order to minimize compile
29+
> times and built-artifact size.
30+
2231
3. Create a function that takes a `&mut App` and builds your bevy app, and annotate it with `#[bevy_app]`:
2332
```rust
2433
#[bevy_app]
2534
fn build_app(app: &mut App) {
2635
app.add_system(my_system)
2736
}
2837
```
29-
4. Cargo build your project, and make sure the dll is found by Godot via the .gdextension file. You should now have the `BevyApp` Node avaiable to you in the Godot editor (you may need to refresh the project in the editor).
38+
39+
4. Cargo build your project, and make sure the dll is found by Godot via the .gdextension file. You should now have the `BevyApp` Node avaiable to you in the Godot editor (you may need to refresh the project in the editor).
3040

3141
5. Add this `BevyApp` Node as a Godot autoload named `BevyAppSingleton` in the Godot project settings.
3242

43+
## Version Compatibility Matrix
44+
45+
| Godot-Bevy | Bevy | Godot-Rust | Godot |
46+
|------------|------|------------|-------|
47+
| 0.2.x | 0.15 | 0.2.4 | 4.4.x |
48+
| 0.3.x | 0.16 | 0.2.4 | 4.4.x |
49+
50+
3351
## Features
3452

3553
### Godot nodes as components

examples/simple/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name = "simple"
1212
crate-type = ["cdylib"]
1313

1414
[dependencies]
15-
bevy = { version = "0.15.3", default-features = false, features = [
15+
bevy = { version = "0.16", default-features = false, features = [
1616
"bevy_asset",
1717
"bevy_state",
1818
] }

examples/simple/godot/main.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[gd_scene format=3 uid="uid://dvaikj6lrfk3e"]
22

33
[node name="Node2D" type="Node2D"]
4-
position = Vector2(1, 0)

examples/simple/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use bevy::{
22
app::{App, Update},
3-
ecs::system::Res,
4-
prelude::{
5-
in_state, AppExtStates, Commands, IntoSystemConfigs, OnEnter, Query, Resource, States,
6-
},
3+
ecs::{schedule::IntoScheduleConfigs, system::Res},
4+
prelude::{AppExtStates, Commands, OnEnter, Query, Resource, States, in_state},
75
state::app::StatesPlugin,
86
};
97
use bevy_godot4::prelude::{
10-
bevy_app, AsPhysicsSystem, ErasedGd, ErasedGdResource, GodotScene, SystemDeltaTimer,
8+
AsPhysicsSystem, ErasedGd, ErasedGdResource, GodotScene, SystemDeltaTimer, bevy_app,
119
};
1210
use godot::{
1311
builtin::Vector2,
@@ -57,7 +55,7 @@ fn spawn_sprite(mut commands: Commands, assets: Res<MyAssets>) {
5755
}
5856

5957
fn move_sprite(mut sprite: Query<&mut ErasedGd>, mut delta: SystemDeltaTimer) {
60-
if let Ok(mut sprite) = sprite.get_single_mut() {
58+
if let Ok(mut sprite) = sprite.single_mut() {
6159
let mut sprite = sprite.get::<Sprite2D>();
6260
let delta = delta.delta_seconds() * 20.0;
6361
let position = sprite.get_position();

src/app.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use bevy::app::App;
22
use godot::{
33
classes::{INode, Node},
44
obj::Base,
5-
prelude::{godot_api, GodotClass},
5+
prelude::{GodotClass, godot_api},
66
};
77

88
use crate::prelude::*;
99
use std::{
10-
panic::{catch_unwind, resume_unwind, AssertUnwindSafe},
10+
panic::{AssertUnwindSafe, catch_unwind, resume_unwind},
1111
sync::Mutex,
1212
};
1313

@@ -45,13 +45,11 @@ impl INode for BevyApp {
4545

4646
let mut app = App::new();
4747
(APP_BUILDER_FN.lock().unwrap().as_mut().unwrap())(&mut app);
48-
app.add_plugins(bevy::core::TaskPoolPlugin::default())
48+
app.add_plugins(bevy::app::TaskPoolPlugin::default())
4949
.add_plugins(bevy::log::LogPlugin::default())
50-
.add_plugins(bevy::core::TypeRegistrationPlugin)
51-
.add_plugins(bevy::core::FrameCountPlugin)
50+
.add_plugins(bevy::diagnostic::FrameCountPlugin)
5251
.add_plugins(bevy::diagnostic::DiagnosticsPlugin)
5352
.add_plugins(bevy::time::TimePlugin)
54-
.add_plugins(bevy::hierarchy::HierarchyPlugin)
5553
.add_plugins(crate::scene::PackedScenePlugin)
5654
.init_non_send_resource::<crate::scene_tree::SceneTreeRefImpl>();
5755
// .add_plugins(GodotSignalsPlugin)

src/erased_gd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::prelude::Component;
22
use godot::{
33
classes::{Node, Object, Resource},
4-
obj::{bounds::DynMemory, Bounds, Gd, GodotClass, Inherits, InstanceId, RawGd},
4+
obj::{Bounds, Gd, GodotClass, Inherits, InstanceId, RawGd, bounds::DynMemory},
55
sys,
66
};
77

@@ -86,7 +86,7 @@ impl Clone for ErasedGdResource {
8686
maybe_inc_ref_opt::<Resource>(&mut Gd::try_from_instance_id(self.resource_id).ok());
8787

8888
Self {
89-
resource_id: self.resource_id.clone(),
89+
resource_id: self.resource_id,
9090
}
9191
}
9292
}

src/scene.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::str::FromStr;
33
use crate::prelude::*;
44
use bevy::{
55
app::{App, Plugin, PostUpdate},
6+
log::tracing,
67
prelude::{Commands, Component, Entity, Query, Without},
7-
utils::tracing,
88
};
99
use godot::{
1010
builtin::{GString, Transform2D, Transform3D, Vector2, Vector3},
@@ -134,7 +134,9 @@ fn spawn_scene(
134134
{
135135
Some(mut app) => app.add_child(&instance),
136136
None => {
137-
tracing::error!("attempted to add a child to the BevyAppSingleton autoload, but the BevyAppSingleton autoload wasn't found");
137+
tracing::error!(
138+
"attempted to add a child to the BevyAppSingleton autoload, but the BevyAppSingleton autoload wasn't found"
139+
);
138140
return;
139141
}
140142
}
@@ -144,13 +146,17 @@ fn spawn_scene(
144146
GodotSceneTransform::Transform2D(transform) => {
145147
match instance.clone().try_cast::<Node2D>().ok() {
146148
Some(mut node2d) => node2d.set_global_transform(*transform),
147-
None => tracing::error!("attempted to spawn a scene with a transform on Node that did not inherit from Node3D, the transform was not set"),
149+
None => tracing::error!(
150+
"attempted to spawn a scene with a transform on Node that did not inherit from Node3D, the transform was not set"
151+
),
148152
}
149153
}
150154
GodotSceneTransform::Transform3D(transform) => {
151155
match instance.clone().try_cast::<Node3D>().ok() {
152156
Some(mut node3d) => node3d.set_global_transform(*transform),
153-
None => tracing::error!("attempted to spawn a scene with a transform on Node that did not inherit from Node3D, the transform was not set"),
157+
None => tracing::error!(
158+
"attempted to spawn a scene with a transform on Node that did not inherit from Node3D, the transform was not set"
159+
),
154160
}
155161
}
156162
}

src/scene_tree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use std::marker::PhantomData;
88
#[derive(SystemParam)]
99
pub struct SceneTreeRef<'w, 's> {
1010
gd: NonSendMut<'w, SceneTreeRefImpl>,
11-
#[system_param(ignore)]
1211
phantom: PhantomData<&'s ()>,
1312
}
1413

15-
impl<'w, 's> SceneTreeRef<'w, 's> {
14+
impl SceneTreeRef<'_, '_> {
1615
pub fn get(&mut self) -> Gd<SceneTree> {
1716
self.gd.0.clone()
1817
}

src/utils.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use bevy::{
2-
ecs::{schedule::SystemConfigs, system::SystemParam},
2+
ecs::{
3+
schedule::ScheduleConfigs,
4+
system::{ScheduleSystem, SystemParam},
5+
},
36
prelude::*,
47
};
58
use std::{
@@ -18,23 +21,23 @@ pub struct GodotPhysicsFrame;
1821
/// Adds `as_physics_system` that schedules a system only for the physics frame
1922
pub trait AsPhysicsSystem<Params> {
2023
#[allow(clippy::wrong_self_convention)]
21-
fn as_physics_system(self) -> SystemConfigs;
24+
fn as_physics_system(self) -> ScheduleConfigs<ScheduleSystem>;
2225
}
2326

2427
impl<Params, T: IntoSystem<(), (), Params>> AsPhysicsSystem<Params> for T {
25-
fn as_physics_system(self) -> SystemConfigs {
28+
fn as_physics_system(self) -> ScheduleConfigs<ScheduleSystem> {
2629
self.run_if(resource_exists::<GodotPhysicsFrame>)
2730
}
2831
}
2932

3033
/// Adds `as_visual_system` that schedules a system only for the frame
3134
pub trait AsVisualSystem<Params> {
3235
#[allow(clippy::wrong_self_convention)]
33-
fn as_visual_system(self) -> SystemConfigs;
36+
fn as_visual_system(self) -> ScheduleConfigs<ScheduleSystem>;
3437
}
3538

3639
impl<Params, T: IntoSystem<(), (), Params>> AsVisualSystem<Params> for T {
37-
fn as_visual_system(self) -> SystemConfigs {
40+
fn as_visual_system(self) -> ScheduleConfigs<ScheduleSystem> {
3841
self.run_if(resource_exists::<GodotVisualFrame>)
3942
}
4043
}
@@ -46,11 +49,10 @@ impl<Params, T: IntoSystem<(), (), Params>> AsVisualSystem<Params> for T {
4649
#[derive(SystemParam)]
4750
pub struct SystemDeltaTimer<'w, 's> {
4851
last_time: Local<'s, Option<Instant>>,
49-
#[system_param(ignore)]
5052
marker: PhantomData<&'w ()>,
5153
}
5254

53-
impl<'w, 's> SystemDeltaTimer<'w, 's> {
55+
impl SystemDeltaTimer<'_, '_> {
5456
/// Returns the time passed since the last invocation
5557
pub fn delta(&mut self) -> Duration {
5658
let now = Instant::now();
@@ -68,4 +70,4 @@ impl<'w, 's> SystemDeltaTimer<'w, 's> {
6870
pub fn delta_seconds_f64(&mut self) -> f64 {
6971
self.delta().as_secs_f64()
7072
}
71-
}
73+
}

0 commit comments

Comments
 (0)