Skip to content

Commit f14e00d

Browse files
committed
update to bevy 0.10
1 parent 6b13ee8 commit f14e00d

File tree

8 files changed

+59
-61
lines changed

8 files changed

+59
-61
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ exclude = [
2121
]
2222

2323
[dependencies]
24-
bevy = { version = "0.9.1", default-features = false, features = [
24+
bevy = { version = "0.10.1", default-features = false, features = [
2525
"bevy_audio",
2626
"bevy_gilrs",
2727
"bevy_gltf",
28+
"bevy_render",
29+
"bevy_text",
2830
"bevy_winit",
29-
"render",
3031
"png",
3132
"hdr",
3233
"mp3",
3334
"x11",
3435
"vorbis",
3536
] }
36-
bevy_prototype_lyon = "0.7"
37+
bevy_prototype_lyon = "0.8"
3738
ron = "0.8"
3839
serde = { version = "1.0", features = [ "derive" ] }
3940

examples/collider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() {
7171
// Start with the "game" part
7272
let mut game = Game::new();
7373
game.show_colliders = true;
74-
game.window_settings(WindowDescriptor {
74+
game.window_settings(Window {
7575
title: "Collider Creator".into(),
7676
..Default::default()
7777
});

examples/placement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ struct GameState {}
1010
fn main() {
1111
let mut game = Game::new();
1212

13-
let mut car1 = game.add_sprite("car1", SpritePreset::RacingCarRed);
13+
let car1 = game.add_sprite("car1", SpritePreset::RacingCarRed);
1414
car1.translation = Vec2::new(-300.0, 0.0);
1515
car1.rotation = UP;
1616
car1.scale = 1.0;
1717

18-
let mut car2 = game.add_sprite("car2", SpritePreset::RacingCarGreen);
18+
let car2 = game.add_sprite("car2", SpritePreset::RacingCarGreen);
1919
car2.translation = Vec2::new(0.0, 0.0);
2020
car2.rotation = UP;
2121
car2.scale = 1.0;
2222

23-
let mut car3 = game.add_sprite("car3", SpritePreset::RacingCarBlue);
23+
let car3 = game.add_sprite("car3", SpritePreset::RacingCarBlue);
2424
car3.translation = Vec2::new(300.0, 0.0);
2525
car3.rotation = UP;
2626
car3.scale = 1.0;

examples/scenarios/car_shoot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
};
2424

2525
// Set the title of the window
26-
game.window_settings(WindowDescriptor {
26+
game.window_settings(Window {
2727
title: "Car Shoot".into(),
2828
..Default::default()
2929
});

examples/window.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ struct GameState {}
1010
fn main() {
1111
let mut game = Game::new();
1212

13-
game.window_settings(WindowDescriptor {
14-
width: 800.0,
15-
height: 200.0,
16-
resize_constraints: WindowResizeConstraints {
17-
min_width: 700.0,
18-
min_height: 150.0,
19-
max_width: 900.0,
20-
max_height: 300.0,
21-
},
13+
let mut cursor = Cursor::default();
14+
cursor.visible = false;
15+
16+
game.window_settings(Window {
17+
resolution: WindowResolution::new(800.0, 200.0),
2218
title: "Custom Window Settings".into(),
23-
resizable: true,
19+
resizable: false,
2420
decorations: false,
25-
cursor_visible: false,
26-
..Default::default() // for the rest of the options, see https://docs.rs/bevy/0.5.0/bevy/window/struct.WindowDescriptor.html
21+
cursor,
22+
..Default::default() // for the rest of the options, see https://docs.rs/bevy/0.11.3/bevy/window/struct.Window.html
2723
});
2824
let _ = game.add_text(
2925
"message",
30-
"This is a heavily-customized window.\nYou may resize it a little bit.\nPress Esc to exit.",
26+
"This is a heavily-customized window.\nResizing and window decorations have been disabled.\nPress Esc to exit.",
3127
);
3228
game.run(GameState {});
3329
}

src/game.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
use bevy::{
22
app::AppExit,
3-
prelude::{
4-
debug, App, AssetServer, Camera2dBundle, Color, Commands, Component, DefaultPlugins,
5-
Entity, EventReader, EventWriter, HorizontalAlign, ImagePlugin, ParamSet, PluginGroup,
6-
Query, Res, ResMut, Resource, SpriteBundle, Text as BevyText, Text2dBundle, TextAlignment,
7-
TextStyle, Transform, Vec2, VerticalAlign, Windows,
8-
},
3+
prelude::{Text as BevyText, *},
94
time::Time,
105
utils::HashMap,
11-
window::{close_on_esc, WindowPlugin},
6+
window::{close_on_esc, PrimaryWindow, WindowPlugin},
127
};
138
use bevy_prototype_lyon::prelude::*;
149
use std::{
@@ -29,7 +24,7 @@ use crate::{
2924
};
3025

3126
// Public re-export
32-
pub use bevy::window::{WindowDescriptor, WindowMode, WindowResizeConstraints};
27+
pub use bevy::window::{Cursor, Window, WindowMode, WindowResolution};
3328

3429
/// Engine is the primary way that you will interact with Rusty Engine. Each frame this struct
3530
/// is provided to the "logic" functions (or closures) that you provided to [`Game::add_logic`]. The
@@ -172,11 +167,19 @@ fn add_collider_lines(commands: &mut Commands, sprite: &mut Sprite) {
172167
let line = path_builder.build();
173168
let transform = sprite.bevy_transform();
174169
commands
175-
.spawn(GeometryBuilder::build_as(
176-
&line,
177-
DrawMode::Stroke(StrokeMode::new(Color::WHITE, 1.0 / transform.scale.x)),
178-
transform,
170+
.spawn((
171+
ShapeBundle {
172+
path: GeometryBuilder::new().add(&line).build(),
173+
transform,
174+
..Default::default()
175+
},
176+
Stroke::new(Color::WHITE, 1.0 / transform.scale.x),
179177
))
178+
// .spawn(GeometryBuilder::build_as(
179+
// &line,
180+
// DrawMode::Stroke(StrokeMode::new(Color::WHITE, 1.0 / transform.scale.x)),
181+
// transform,
182+
// ))
180183
.insert(ColliderLines {
181184
sprite_label: sprite.label.clone(),
182185
});
@@ -222,10 +225,7 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
222225
color: Color::WHITE,
223226
},
224227
)
225-
.with_alignment(TextAlignment {
226-
vertical: VerticalAlign::Center,
227-
horizontal: HorizontalAlign::Center,
228-
}),
228+
.with_alignment(TextAlignment::Center),
229229
transform,
230230
..Default::default()
231231
},
@@ -235,14 +235,18 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
235235

236236
/// system - update current window dimensions in the engine, because people resize windows
237237
#[doc(hidden)]
238-
pub fn update_window_dimensions(windows: Res<Windows>, mut engine: ResMut<Engine>) {
239-
// It's possible to not have window dimensions for the first frame or two
240-
if let Some(window) = windows.get_primary() {
241-
let screen_dimensions = Vec2::new(window.width(), window.height());
242-
if screen_dimensions != engine.window_dimensions {
243-
engine.window_dimensions = screen_dimensions;
244-
debug!("Set window dimensions: {}", engine.window_dimensions);
245-
}
238+
pub fn update_window_dimensions(
239+
window_query: Query<&Window, With<PrimaryWindow>>,
240+
mut engine: ResMut<Engine>,
241+
) {
242+
// It's possible to not have a window for the first frame or two
243+
let Ok(window) = window_query.get_single() else {
244+
return;
245+
};
246+
let screen_dimensions = Vec2::new(window.width(), window.height());
247+
if screen_dimensions != engine.window_dimensions {
248+
engine.window_dimensions = screen_dimensions;
249+
debug!("Set window dimensions: {}", engine.window_dimensions);
246250
}
247251
}
248252

@@ -264,7 +268,7 @@ pub struct Game<S: Resource + Send + Sync + 'static> {
264268
app: App,
265269
engine: Engine,
266270
logic_functions: LogicFuncVec<S>,
267-
window_descriptor: WindowDescriptor,
271+
window: Window,
268272
}
269273

270274
impl<S: Resource + Send + Sync + 'static> Default for Game<S> {
@@ -273,7 +277,7 @@ impl<S: Resource + Send + Sync + 'static> Default for Game<S> {
273277
app: App::new(),
274278
engine: Engine::default(),
275279
logic_functions: LogicFuncVec(vec![]),
276-
window_descriptor: WindowDescriptor {
280+
window: Window {
277281
title: "Rusty Engine".into(),
278282
..Default::default()
279283
},
@@ -294,8 +298,8 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
294298
/// Use this to set properties of the native OS window before running the game. See the
295299
/// [window](https://github.com/CleanCut/rusty_engine/blob/main/examples/window.rs) example for
296300
/// more information.
297-
pub fn window_settings(&mut self, window_descriptor: WindowDescriptor) -> &mut Self {
298-
self.window_descriptor = window_descriptor;
301+
pub fn window_settings(&mut self, window: Window) -> &mut Self {
302+
self.window = window;
299303
self
300304
}
301305

@@ -307,7 +311,7 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
307311
.add_plugins(
308312
DefaultPlugins
309313
.set(WindowPlugin {
310-
window: self.window_descriptor.clone(),
314+
primary_window: Some(self.window.clone()),
311315
..Default::default()
312316
})
313317
.set(ImagePlugin::default_nearest()),
@@ -322,7 +326,7 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
322326
.add_plugin(PhysicsPlugin)
323327
//.insert_resource(ReportExecutionOrderAmbiguities) // for debugging
324328
.add_system(update_window_dimensions)
325-
.add_system(game_logic_sync::<S>) // TODO: ensure after update_window_dimensions
329+
.add_system(game_logic_sync::<S>) // this should happen after all the rest of the systems
326330
.add_startup_system(setup);
327331
self.app.world.spawn(Camera2dBundle::default());
328332
let engine = std::mem::take(&mut self.engine);
@@ -359,7 +363,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
359363
mut query_set: ParamSet<(
360364
Query<(Entity, &mut Sprite, &mut Transform)>,
361365
Query<(Entity, &mut Text, &mut Transform, &mut BevyText)>,
362-
Query<(Entity, &mut DrawMode, &mut Transform, &ColliderLines)>,
366+
Query<(Entity, &mut Stroke, &mut Transform, &ColliderLines)>,
363367
)>,
364368
) {
365369
// Update this frame's timing info
@@ -429,7 +433,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
429433
}
430434
}
431435
// Update transform & line width
432-
for (_, mut draw_mode, mut transform, collider_lines) in query_set.p2().iter_mut() {
436+
for (_, mut stroke, mut transform, collider_lines) in query_set.p2().iter_mut() {
433437
if let Some(sprite) = engine.sprites.get(&collider_lines.sprite_label) {
434438
*transform = sprite.bevy_transform();
435439
// We want collider lines to appear on top of the sprite they are for, so they need a
@@ -438,10 +442,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
438442
}
439443
// Stroke line width gets scaled with the transform, but we want it to appear to be the same
440444
// regardless of scale, so we have to counter the scale.
441-
if let DrawMode::Stroke(ref mut stroke_mode) = *draw_mode {
442-
let line_width = 1.0 / transform.scale.x;
443-
*stroke_mode = StrokeMode::new(Color::WHITE, line_width);
444-
}
445+
stroke.options.line_width = 1.0 / transform.scale.x;
445446
}
446447
}
447448
engine.last_show_colliders = engine.show_colliders;

src/keyboard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub(crate) struct KeyboardPlugin;
1111
impl Plugin for KeyboardPlugin {
1212
fn build(&self, app: &mut bevy::prelude::App) {
1313
app.insert_resource::<KeyboardState>(KeyboardState::default())
14-
.add_system(sync_keyboard_events.before("game_logic_sync"))
15-
.add_system(sync_keyboard_state.before("game_logic_sync"));
14+
.add_system(sync_keyboard_events)
15+
.add_system(sync_keyboard_state);
1616
}
1717
}
1818

src/mouse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub(crate) struct MousePlugin;
1717
impl Plugin for MousePlugin {
1818
fn build(&self, app: &mut bevy::prelude::App) {
1919
app.insert_resource(MouseState::default())
20-
.add_system(sync_mouse_state.before("game_logic_sync"))
21-
.add_system(sync_mouse_events.before("game_logic_sync"));
20+
.add_system(sync_mouse_state)
21+
.add_system(sync_mouse_events);
2222
}
2323
}
2424

0 commit comments

Comments
 (0)