Upgrade to bevy 0.15

master
hheik 2025-01-17 23:56:14 +02:00
parent 17b4e74ca0
commit 9db0030511
4 changed files with 2147 additions and 1347 deletions

3399
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,13 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.13.0"
bevy-inspector-egui = "0.23.2"
bevy_mod_debugdump = "0.10.0"
bevy_rapier2d = "0.25.0"
num-traits = "0.2.18"
# NOTE: Fork with bevy 0.13 support, remove when upstream updates
bevy_prototype_debug_lines = { git = "https://github.com/hheik/bevy_debug_lines", rev = "cdf57a6", features = [] }
bevy = "0.15.1"
bevy-inspector-egui = "0.28.1"
bevy_mod_debugdump = "0.12.1"
bevy_rapier2d = "0.28.0"
num-traits = "0.2.19"
# Enable a small amount of optimization in debug mode
[profile.dev]

View File

@ -11,7 +11,6 @@ impl Plugin for DebugPlugin {
app.insert_resource(DebugMode::on())
.add_plugins((
bevy_prototype_debug_lines::DebugLinesPlugin::default(),
bevy_inspector_egui::quick::WorldInspectorPlugin::new().run_if(is_debug_enabled),
bevy_rapier2d::prelude::RapierDebugRenderPlugin::default(),
))

View File

@ -1,38 +1,38 @@
use crate::{debug, game_setup};
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
pub fn init(app: &mut App) {
let mut app = app.add_plugins((
let app = app.add_plugins((
game_setup::GameSetupPlugin,
bevy_rapier2d::prelude::RapierPhysicsPlugin::<bevy_rapier2d::prelude::NoUserData>::default(
),
RapierPhysicsPlugin::<NoUserData>::default(),
debug::DebugPlugin,
));
app.add_systems(Startup, setup_2d)
.add_systems(Update, demo_2d);
// NOTE: If using 3D, make sure you have '3d' feature enabled for the
// 'bevy_prototype_debug_lines' crate
// app.add_systems(Startup, setup_3d)
// .add_systems(Update, demo_3d);
}
fn setup_2d(mut commands: Commands) {
commands.spawn(Camera2dBundle {
transform: Transform::from_xyz(0.0, 0.0, 100.0),
..default()
});
commands.spawn((
Name::from("Demo 2D camera"),
Camera2d,
Transform::from_xyz(0.0, 0.0, 10.0),
));
commands.spawn((
Name::from("Demo 2D sprite"),
Sprite::sized(Vec2::splat(256.0)),
));
}
fn demo_2d(
mut camera_query: Query<(&mut Transform, &mut OrthographicProjection)>,
mut mouse_events: EventReader<bevy::input::mouse::MouseMotion>,
mut scroll_events: EventReader<bevy::input::mouse::MouseWheel>,
mut debug_lines: ResMut<bevy_prototype_debug_lines::DebugLines>,
mut debug_shapes: ResMut<bevy_prototype_debug_lines::DebugShapes>,
mouse_input: Res<ButtonInput<MouseButton>>,
time: Res<Time>,
) {
let raw_mouse_motion: Vec2 = mouse_events.read().map(|e| e.delta).sum();
let raw_scroll_motion: f32 = scroll_events
@ -50,34 +50,29 @@ fn demo_2d(
transform.translation += mouse_motion.extend(0.0);
}
}
debug_lines.line_colored(Vec3::ZERO, Vec3::X * 50.0, 0.0, Color::RED);
debug_lines.line_colored(Vec3::ZERO, Vec3::Y * 50.0, 0.0, Color::GREEN);
debug_shapes
.rect()
.size(Vec2::splat(200.0))
.rotation(Quat::from_euler(
EulerRot::YXZ,
0.0,
0.0,
time.elapsed_seconds(),
))
.color(Color::WHITE);
}
fn setup_3d(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 10.0),
..default()
});
fn setup_3d(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
Name::from("Demo 3D camera"),
Camera3d::default(),
Transform::from_xyz(0.0, 0.0, 10.0),
PointLight::default(),
));
commands.spawn((
Name::from("Demo 3D cuboid"),
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
MeshMaterial3d(materials.add(Color::from(bevy::color::palettes::css::ORANGE))),
));
}
fn demo_3d(
mut camera_query: Query<&mut Transform>,
mut camera_query: Query<&mut Transform, With<Camera3d>>,
mut mouse_events: EventReader<bevy::input::mouse::MouseMotion>,
mut debug_lines: ResMut<bevy_prototype_debug_lines::DebugLines>,
mut debug_shapes: ResMut<bevy_prototype_debug_lines::DebugShapes>,
mouse_input: Res<ButtonInput<MouseButton>>,
key_input: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
@ -112,27 +107,12 @@ fn demo_3d(
for mut transform in camera_query.iter_mut() {
let mouse_motion = raw_mouse_motion * Vec2::new(-1.0, -1.0) * 0.002;
transform.rotate_axis(Vec3::Y, mouse_motion.x);
transform.rotate_axis(Dir3::Y, mouse_motion.x);
transform.rotate_local_x(mouse_motion.y);
let local_movement = raw_movement * time.delta_seconds() * 10.0;
let local_movement = raw_movement * time.delta_secs() * 10.0;
let movement = transform.rotation * local_movement;
transform.translation += movement;
}
}
debug_lines.line_colored(Vec3::ZERO, Vec3::X, 0.0, Color::RED);
debug_lines.line_colored(Vec3::ZERO, Vec3::Y, 0.0, Color::GREEN);
debug_lines.line_colored(Vec3::ZERO, Vec3::Z, 0.0, Color::BLUE);
debug_shapes
.cuboid()
.size(Vec3::splat(3.0))
.rotation(Quat::from_euler(
EulerRot::YXZ,
time.elapsed_seconds(),
0.0,
0.0,
))
.color(Color::WHITE);
}