Skip to content

Commit

Permalink
feat!: bevy 0.15 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cxreiff committed Dec 5, 2024
1 parent bb0c2fc commit 77904e0
Show file tree
Hide file tree
Showing 11 changed files with 908 additions and 609 deletions.
1,221 changes: 785 additions & 436 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ categories = ["game-engines", "gui", "rendering", "command-line-interface"]
keywords = ["bevy", "ratatui", "terminal", "tui", "render"]

[dependencies]
bevy = "0.14.2"
bevy = "0.15.0"
crossterm = "0.28.0"
crossbeam-channel = "0.5.13"
ratatui = "0.29.0"
ratatui-image = "3.0.0"
bevy_ratatui = "0.6.4"
bevy_ratatui = "0.7.0"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3

[lints.clippy]
type_complexity = "allow"
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ fn setup_scene_system(
mut commands: Commands,
ratatui_render: Res<RatatuiRenderContext>,
) {
// spawn objects into your scene
// spawn objects into your scene, and your camera

...

commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("main").unwrap(),
..default()
},
..default()
});
));
}

fn draw_scene_system(
Expand Down Expand Up @@ -127,6 +127,7 @@ that the following terminals display correctly:

| bevy | bevy_ratatui_render |
|-------|---------------------|
| 0.15 | 0.7 |
| 0.14 | 0.6 |
| 0.13 | 0.4 |

Expand Down
60 changes: 23 additions & 37 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::time::Duration;

use bevy::app::AppExit;
use bevy::app::ScheduleRunnerPlugin;
use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
use bevy::log::LogPlugin;
use bevy::prelude::*;
Expand Down Expand Up @@ -58,39 +57,31 @@ fn setup_scene_system(
) {
commands.spawn((
Cube,
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..Default::default()
}),
transform: Transform::default(),
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..Default::default()
},
})),
));
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(15., 15., 1.))),
Transform::from_xyz(0., 0., -6.),
));
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(15., 15., 1.)),
material: materials.add(StandardMaterial::default()),
transform: Transform::from_xyz(0., 0., -6.),
..Default::default()
});
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
..Default::default()
},
transform: Transform::from_xyz(3., 4., 6.),
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3., 3., 3.).looking_at(Vec3::ZERO, Vec3::Z),
tonemapping: Tonemapping::None,
camera: Camera {
Transform::from_xyz(3., 4., 6.),
));
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("main").unwrap(),
..default()
},
..default()
});
Transform::from_xyz(3., 3., 3.).looking_at(Vec3::ZERO, Vec3::Z),
));
}

fn draw_scene_system(
Expand Down Expand Up @@ -156,23 +147,18 @@ pub fn handle_input_system(
KeyCode::Char('q') => {
exit.send_default();
}

KeyCode::Char('p') => {
panic!("Panic!");
}

KeyCode::Char('d') => {
flags.debug = !flags.debug;
}

KeyCode::Left => {
*input = InputState::Left(0.75);
}

KeyCode::Right => {
*input = InputState::Right(0.75);
}

_ => {}
},
KeyEventKind::Release => match key_event.code {
Expand All @@ -199,12 +185,12 @@ fn rotate_cube_system(
) {
match *input {
InputState::Idle => {
cube.single_mut().rotate_z(time.delta_seconds());
cube.single_mut().rotate_z(time.delta_secs());
}
InputState::Left(duration) => {
cube.single_mut()
.rotate_z(-time.delta_seconds() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_seconds()).max(0.);
.rotate_z(-time.delta_secs() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_secs()).max(0.);
*input = if new_duration > 0. {
InputState::Left(new_duration)
} else {
Expand All @@ -213,8 +199,8 @@ fn rotate_cube_system(
}
InputState::Right(duration) => {
cube.single_mut()
.rotate_z(time.delta_seconds() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_seconds()).max(0.);
.rotate_z(time.delta_secs() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_secs()).max(0.);
*input = if new_duration > 0. {
InputState::Right(new_duration)
} else {
Expand Down
44 changes: 17 additions & 27 deletions examples/disable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io;

use bevy::app::AppExit;
use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
use bevy::input::keyboard::KeyboardInput;
use bevy::input::ButtonState;
Expand Down Expand Up @@ -40,15 +39,14 @@ fn main() {

// Use `unwrap_or_default` so the camera falls back to a normal window target.
fn setup_camera_system(mut commands: Commands, ratatui_render: Res<RatatuiRenderContext>) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3., 3., 3.).looking_at(Vec3::ZERO, Vec3::Z),
tonemapping: Tonemapping::None,
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("main").unwrap_or_default(),
..default()
},
..default()
});
Transform::from_xyz(3., 3., 3.).looking_at(Vec3::ZERO, Vec3::Z),
));
}

// Wrap `frame.render_widget` in an if-let for when `widget(id)` returns `None`.
Expand Down Expand Up @@ -98,24 +96,19 @@ fn setup_scene_system(
) {
commands.spawn((
Cube,
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..Default::default()
}),
transform: Transform::default(),
..Default::default()
},
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..default()
})),
));
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
..Default::default()
},
transform: Transform::from_xyz(3., 4., 6.),
..default()
});
Transform::from_xyz(3., 4., 6.),
));
}

pub fn handle_input_system(
Expand All @@ -130,15 +123,12 @@ pub fn handle_input_system(
KeyCode::Char('q') => {
exit.send_default();
}

KeyCode::Left => {
cube.single_mut().rotate_z(-10. * time.delta_seconds());
cube.single_mut().rotate_z(-10. * time.delta_secs());
}

KeyCode::Right => {
cube.single_mut().rotate_z(10. * time.delta_seconds());
cube.single_mut().rotate_z(10. * time.delta_secs());
}

_ => {}
},
_ => {}
Expand Down
71 changes: 29 additions & 42 deletions examples/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::time::Duration;

use bevy::app::AppExit;
use bevy::app::ScheduleRunnerPlugin;
use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
use bevy::log::LogPlugin;
use bevy::prelude::*;
Expand Down Expand Up @@ -60,51 +59,43 @@ fn setup_scene_system(
) {
commands.spawn((
Cube,
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..Default::default()
}),
transform: Transform::default(),
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb(0.4, 0.54, 0.7),
..Default::default()
},
})),
));
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
..Default::default()
},
transform: Transform::from_xyz(3., 4., 6.),
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0., 3., 0.).looking_at(Vec3::ZERO, Vec3::Z),
tonemapping: Tonemapping::None,
camera: Camera {
Transform::from_xyz(3., 4., 6.),
));
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("top_left").unwrap(),
..default()
},
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0., 0., 3.).looking_at(Vec3::ZERO, Vec3::Z),
tonemapping: Tonemapping::None,
camera: Camera {
Transform::from_xyz(0., 3., 0.).looking_at(Vec3::ZERO, Vec3::Z),
));
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("top_right").unwrap(),
..default()
},
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(2., 2., 2.).looking_at(Vec3::ZERO, Vec3::Z),
tonemapping: Tonemapping::None,
camera: Camera {
Transform::from_xyz(0., 0., 3.).looking_at(Vec3::ZERO, Vec3::Z),
));
commands.spawn((
Camera3d::default(),
Camera {
target: ratatui_render.target("bottom").unwrap(),
..default()
},
..default()
});
Transform::from_xyz(2., 2., 2.).looking_at(Vec3::ZERO, Vec3::Z),
));
}

fn draw_scene_system(
Expand Down Expand Up @@ -205,19 +196,15 @@ pub fn handle_input_system(
KeyCode::Char('q') => {
exit.send_default();
}

KeyCode::Char('d') => {
flags.debug = !flags.debug;
}

KeyCode::Left => {
*input = InputState::Left(0.75);
}

KeyCode::Right => {
*input = InputState::Right(0.75);
}

_ => {}
},
KeyEventKind::Release => match key_event.code {
Expand All @@ -244,12 +231,12 @@ fn rotate_cube_system(
) {
match *input {
InputState::Idle => {
cube.single_mut().rotate_z(time.delta_seconds());
cube.single_mut().rotate_z(time.delta_secs());
}
InputState::Left(duration) => {
cube.single_mut()
.rotate_z(-time.delta_seconds() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_seconds()).max(0.);
.rotate_z(-time.delta_secs() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_secs()).max(0.);
*input = if new_duration > 0. {
InputState::Left(new_duration)
} else {
Expand All @@ -258,8 +245,8 @@ fn rotate_cube_system(
}
InputState::Right(duration) => {
cube.single_mut()
.rotate_z(time.delta_seconds() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_seconds()).max(0.);
.rotate_z(time.delta_secs() * duration.min(0.25) * 4.);
let new_duration = (duration - time.delta_secs()).max(0.);
*input = if new_duration > 0. {
InputState::Right(new_duration)
} else {
Expand Down
Loading

0 comments on commit 77904e0

Please sign in to comment.