update to bevy 13

This commit is contained in:
Joe Ardent 2024-06-13 13:00:39 -07:00
parent 82f95cf070
commit 63ed962155
12 changed files with 2194 additions and 972 deletions

3031
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,14 +8,14 @@ rand = "0.8"
# bevy_polyline = "0.4" # bevy_polyline = "0.4"
noise = { git = "https://github.com/Razaekel/noise-rs" } noise = { git = "https://github.com/Razaekel/noise-rs" }
hexasphere = "8" hexasphere = "8"
wgpu = "0.15" wgpu = "0.19"
bevy-inspector-egui = "0.18" bevy-inspector-egui = "0.24"
[features] [features]
inspector = [] inspector = []
[dependencies.bevy] [dependencies.bevy]
version = "0.10" version = "0.13"
default-features = false default-features = false
features = [ features = [
"bevy_gilrs", "bevy_gilrs",
@ -31,7 +31,7 @@ features = [
[dependencies.bevy_rapier3d] [dependencies.bevy_rapier3d]
features = ["debug-render-3d"] features = ["debug-render-3d"]
version = "0.21" version = "0.26"
# Maybe also enable only a small amount of optimization for our code: # Maybe also enable only a small amount of optimization for our code:
[profile.dev] [profile.dev]

View file

@ -1,7 +1,7 @@
use bevy::{ use bevy::{
diagnostic::FrameTimeDiagnosticsPlugin, diagnostic::FrameTimeDiagnosticsPlugin,
ecs::reflect::ReflectResource, ecs::reflect::ReflectResource,
prelude::{App, IntoSystemConfigs, Plugin, Resource}, prelude::{App, IntoSystemConfigs, Plugin, Resource, Startup, Update},
reflect::Reflect, reflect::Reflect,
}; };
use bevy_rapier3d::prelude::{NoUserData, RapierPhysicsPlugin}; use bevy_rapier3d::prelude::{NoUserData, RapierPhysicsPlugin};
@ -28,10 +28,11 @@ impl Plugin for CyberActionPlugin {
.init_resource::<CyberLean>() .init_resource::<CyberLean>()
.register_type::<CyberLean>() .register_type::<CyberLean>()
.register_type::<CatControllerSettings>() .register_type::<CatControllerSettings>()
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default()) .add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_startup_system(timestep_setup) .add_systems(Startup, timestep_setup)
.add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_systems( .add_systems(
Update,
( (
gravity, gravity,
cyber_lean, cyber_lean,

View file

@ -53,7 +53,7 @@ pub(super) fn gravity(
) { ) {
let (xform, mut forces) = query.single_mut(); let (xform, mut forces) = query.single_mut();
#[cfg(feature = "inspectorb")] #[cfg(feature = "inspector")]
{ {
if debug_instant.elapsed().as_millis() > 6000 { if debug_instant.elapsed().as_millis() > 6000 {
dbg!(&forces); dbg!(&forces);
@ -75,7 +75,7 @@ pub(super) fn cyber_lean(
mut lean: ResMut<CyberLean>, mut lean: ResMut<CyberLean>,
) { ) {
let (velocity, xform) = bike_state.single(); let (velocity, xform) = bike_state.single();
let vel = velocity.linvel.dot(xform.forward()); let vel = velocity.linvel.dot(*xform.forward());
let v_squared = vel.powi(2); let v_squared = vel.powi(2);
let steering_angle = yaw_to_angle(input.yaw); let steering_angle = yaw_to_angle(input.yaw);
let wheels: Vec<_> = wheels.iter().map(|w| w.translation).collect(); let wheels: Vec<_> = wheels.iter().map(|w| w.translation).collect();
@ -101,13 +101,13 @@ pub(super) fn falling_cat(
) { ) {
let (xform, mut forces, mut control_vars) = bike_query.single_mut(); let (xform, mut forces, mut control_vars) = bike_query.single_mut();
let world_up = xform.translation.normalize(); let world_up = xform.translation.normalize();
let rot = Quat::from_axis_angle(xform.back(), lean.lean); let rot = Quat::from_axis_angle(*xform.back(), lean.lean);
let target_up = rotate_point(&world_up, &rot).normalize(); let target_up = rotate_point(&world_up, &rot).normalize();
let bike_right = xform.right(); let bike_right = xform.right();
let roll_error = bike_right.dot(target_up); let roll_error = bike_right.dot(target_up);
let pitch_error = world_up.dot(xform.back()); let pitch_error = world_up.dot(*xform.back());
// only try to correct roll if we're not totally vertical // only try to correct roll if we're not totally vertical
if pitch_error.abs() < 0.95 { if pitch_error.abs() < 0.95 {
@ -135,7 +135,7 @@ pub(super) fn input_forces(
// thrust // thrust
let thrust = xform.forward() * input.throttle * settings.accel; let thrust = xform.forward() * input.throttle * settings.accel;
let point = xform.translation + xform.back(); let point = xform.translation + *xform.back();
let force = ExternalForce::at_point(thrust, point, xform.translation); let force = ExternalForce::at_point(thrust, point, xform.translation);
*forces += force; *forces += force;
@ -227,7 +227,7 @@ pub(super) fn tunnel_out(
continue; continue;
} }
tunneling.frames -= 1; tunneling.frames -= 1;
force.force = tunneling.dir * settings.gravity * 1.5 * mprops.0.mass; force.force = tunneling.dir * settings.gravity * 1.5 * mprops.get().mass;
#[cfg(feature = "inspector")] #[cfg(feature = "inspector")]
dbg!(&tunneling); dbg!(&tunneling);
} }

View file

@ -2,9 +2,7 @@ mod body;
mod components; mod components;
mod wheels; mod wheels;
use bevy::prelude::{ use bevy::prelude::{App, Assets, Mesh, Plugin, PostStartup, ResMut, StandardMaterial};
App, Assets, IntoSystemConfig, Mesh, Plugin, ResMut, StandardMaterial, StartupSet,
};
use bevy_rapier3d::prelude::Group; use bevy_rapier3d::prelude::Group;
pub(crate) use self::components::*; pub(crate) use self::components::*;
@ -23,6 +21,6 @@ impl Plugin for CyberBikePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(WheelConfig::default()) app.insert_resource(WheelConfig::default())
.register_type::<WheelConfig>() .register_type::<WheelConfig>()
.add_startup_system(spawn_cyberbike.in_base_set(StartupSet::PostStartup)); .add_systems(PostStartup, spawn_cyberbike);
} }
} }

View file

@ -81,7 +81,7 @@ fn follow_cyberbike(
// handle input pitch // handle input pitch
let angle = input.pitch.powi(3) * MAX_PITCH; let angle = input.pitch.powi(3) * MAX_PITCH;
let axis = cam_xform.right(); let axis = cam_xform.right();
cam_xform.rotate(Quat::from_axis_angle(axis, angle)); cam_xform.rotate(Quat::from_axis_angle(*axis, angle));
} }
CyberCameras::Debug => { CyberCameras::Debug => {
let mut ncx = bike_xform.to_owned(); let mut ncx = bike_xform.to_owned();
@ -101,7 +101,7 @@ fn update_active_camera(
) { ) {
// find the camera with the current state, set it as the ActiveCamera // find the camera with the current state, set it as the ActiveCamera
query.iter_mut().for_each(|(mut cam, cyber)| { query.iter_mut().for_each(|(mut cam, cyber)| {
if cyber.eq(&state.0) { if cyber.eq(&state.get()) {
cam.is_active = true; cam.is_active = true;
} else { } else {
cam.is_active = false; cam.is_active = false;
@ -112,13 +112,13 @@ fn update_active_camera(
fn cycle_cam_state( fn cycle_cam_state(
state: Res<State<CyberCameras>>, state: Res<State<CyberCameras>>,
mut next: ResMut<NextState<CyberCameras>>, mut next: ResMut<NextState<CyberCameras>>,
mut keys: ResMut<Input<KeyCode>>, mut keys: ResMut<ButtonInput<KeyCode>>,
) { ) {
if keys.just_pressed(KeyCode::D) { if keys.just_pressed(KeyCode::KeyD) {
let new_state = state.0.next(); let new_state = state.get().next();
info!("{:?}", new_state); info!("{:?}", new_state);
next.set(new_state); next.set(new_state);
keys.reset(KeyCode::D); keys.reset(KeyCode::KeyD);
} }
} }
@ -132,9 +132,10 @@ impl Plugin for CyberCamPlugin {
fn common(app: &mut bevy::prelude::App) { fn common(app: &mut bevy::prelude::App) {
app.insert_resource(DebugCamOffset::default()) app.insert_resource(DebugCamOffset::default())
.add_startup_system(setup_cybercams) .add_systems(Startup, setup_cybercams)
.add_state::<CyberCameras>() .init_state::<CyberCameras>()
.add_system(cycle_cam_state) .add_systems(
.add_system(update_active_camera) Update,
.add_system(follow_cyberbike); (cycle_cam_state, update_active_camera, follow_cyberbike),
);
} }

View file

@ -23,12 +23,12 @@ impl Plugin for CyberGlamorPlugin {
let rplugin = RapierDebugRenderPlugin { let rplugin = RapierDebugRenderPlugin {
style, style,
always_on_top: true, // always_on_top: true,
enabled: true, enabled: true,
mode, mode,
}; };
app.add_plugin(rplugin); app.add_plugins(rplugin);
} }
} }
} }

View file

@ -14,22 +14,22 @@ pub(crate) struct InputState {
pub pitch: f32, pub pitch: f32,
} }
fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<KeyCode>>) { fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) {
let keyset: HashSet<_> = keys.get_pressed().collect(); let keyset: HashSet<_> = keys.get_pressed().collect();
let shifted = keyset.contains(&KeyCode::LShift) || keyset.contains(&KeyCode::RShift); let shifted = keyset.contains(&KeyCode::ShiftLeft) || keyset.contains(&KeyCode::ShiftRight);
for key in keyset { for key in keyset {
match key { match key {
KeyCode::Left => offset.rot -= 5.0, KeyCode::ArrowLeft => offset.rot -= 5.0,
KeyCode::Right => offset.rot += 5.0, KeyCode::ArrowRight => offset.rot += 5.0,
KeyCode::Up => { KeyCode::ArrowUp => {
if shifted { if shifted {
offset.alt += 0.5; offset.alt += 0.5;
} else { } else {
offset.dist -= 0.5; offset.dist -= 0.5;
} }
} }
KeyCode::Down => { KeyCode::ArrowDown => {
if shifted { if shifted {
offset.alt -= 0.5; offset.alt -= 0.5;
} else { } else {
@ -41,16 +41,17 @@ fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<K
} }
if keys.get_just_released().len() > 0 { if keys.get_just_released().len() > 0 {
let unpressed = keys.just_released(KeyCode::LShift) || keys.just_released(KeyCode::RShift); let unpressed =
keys.just_released(KeyCode::ShiftLeft) || keys.just_released(KeyCode::ShiftRight);
keys.reset_all(); keys.reset_all();
if shifted && !unpressed { if shifted && !unpressed {
keys.press(KeyCode::LShift); keys.press(KeyCode::ShiftLeft);
} }
} }
} }
fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) { fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) {
for pad_event in events.iter() { for pad_event in events.read() {
match pad_event { match pad_event {
GamepadEvent::Button(button_event) => { GamepadEvent::Button(button_event) => {
let GamepadButtonChangedEvent { let GamepadButtonChangedEvent {
@ -92,7 +93,6 @@ pub struct CyberInputPlugin;
impl Plugin for CyberInputPlugin { impl Plugin for CyberInputPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<InputState>() app.init_resource::<InputState>()
.add_system(update_input) .add_systems(Update, (update_input, update_debug_cam));
.add_system(update_debug_cam);
} }
} }

View file

@ -92,6 +92,6 @@ fn spawn_static_lights(
pub struct CyberSpaceLightsPlugin; pub struct CyberSpaceLightsPlugin;
impl Plugin for CyberSpaceLightsPlugin { impl Plugin for CyberSpaceLightsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system(spawn_static_lights); app.add_systems(Startup, spawn_static_lights);
} }
} }

View file

@ -21,18 +21,20 @@ fn main() {
}), }),
..Default::default() ..Default::default()
})) }))
.add_plugin(CyberPlanetPlugin) .add_plugins((
.add_plugin(CyberInputPlugin) CyberPlanetPlugin,
.add_plugin(CyberActionPlugin) CyberInputPlugin,
.add_plugin(CyberCamPlugin) CyberActionPlugin,
.add_plugin(CyberSpaceLightsPlugin) CyberCamPlugin,
.add_plugin(CyberUIPlugin) CyberSpaceLightsPlugin,
.add_plugin(CyberBikePlugin) CyberUIPlugin,
.add_startup_system(disable_mouse_trap) CyberBikePlugin,
.add_system(bevy::window::close_on_esc); ))
.add_systems(Startup, disable_mouse_trap)
.add_systems(Update, bevy::window::close_on_esc);
#[cfg(feature = "inspector")] #[cfg(feature = "inspector")]
app.add_plugin(CyberGlamorPlugin); app.add_plugins(CyberGlamorPlugin);
app.run(); app.run();
} }

View file

@ -1,6 +1,6 @@
use bevy::{ use bevy::{
prelude::{shape::Icosphere, *}, prelude::{shape::Icosphere, *},
render::{color::Color, mesh::Indices}, render::{color::Color, mesh::Indices, render_asset::RenderAssetUsages},
}; };
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
use hexasphere::shapes::IcoSphere; use hexasphere::shapes::IcoSphere;
@ -42,7 +42,7 @@ fn spawn_planet(
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(mesh), mesh: meshes.add(mesh),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
..Default::default() ..Default::default()
}) })
.insert(pbody) .insert(pbody)
@ -53,7 +53,7 @@ fn spawn_planet(
pub struct CyberPlanetPlugin; pub struct CyberPlanetPlugin;
impl Plugin for CyberPlanetPlugin { impl Plugin for CyberPlanetPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system(spawn_planet); app.add_systems(Startup, spawn_planet);
} }
} }
@ -110,8 +110,8 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
let indices = Indices::U32(indices); let indices = Indices::U32(indices);
let collider = Collider::trimesh(points.iter().map(|p| Vect::from_slice(p)).collect(), idxs); let collider = Collider::trimesh(points.iter().map(|p| Vect::from_slice(p)).collect(), idxs);
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList); let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all());
mesh.set_indices(Some(indices)); mesh.insert_indices(indices);
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, points); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, points);
//mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); //mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
mesh.duplicate_vertices(); mesh.duplicate_vertices();

View file

@ -1,6 +1,9 @@
use bevy::prelude::{ use bevy::{
AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text, app::{Startup, Update},
TextBundle, TextSection, TextStyle, Transform, With, prelude::{
AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text,
TextBundle, TextSection, TextStyle, Transform, With,
},
}; };
#[cfg(feature = "inspector")] #[cfg(feature = "inspector")]
use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
@ -42,7 +45,7 @@ fn update_ui(
) { ) {
let mut text = text_query.single_mut(); let mut text = text_query.single_mut();
let (velocity, xform) = state_query.single(); let (velocity, xform) = state_query.single();
let speed = velocity.linvel.dot(xform.forward()); let speed = velocity.linvel.dot(*xform.forward());
text.sections[0].value = format!("spd: {:.2}", speed); text.sections[0].value = format!("spd: {:.2}", speed);
} }
@ -51,8 +54,10 @@ pub struct CyberUIPlugin;
impl Plugin for CyberUIPlugin { impl Plugin for CyberUIPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
#[cfg(feature = "inspector")] #[cfg(feature = "inspector")]
app.add_plugin(WorldInspectorPlugin); //app.add_plugins(WorldInspectorPlugin);
app.add_startup_system(setup_ui).add_system(update_ui); //
app.add_systems(Startup, setup_ui)
.add_systems(Update, update_ui);
} }
} }