update to bevy 13
This commit is contained in:
parent
82f95cf070
commit
63ed962155
12 changed files with 2194 additions and 972 deletions
3031
Cargo.lock
generated
3031
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,14 +8,14 @@ rand = "0.8"
|
|||
# bevy_polyline = "0.4"
|
||||
noise = { git = "https://github.com/Razaekel/noise-rs" }
|
||||
hexasphere = "8"
|
||||
wgpu = "0.15"
|
||||
bevy-inspector-egui = "0.18"
|
||||
wgpu = "0.19"
|
||||
bevy-inspector-egui = "0.24"
|
||||
|
||||
[features]
|
||||
inspector = []
|
||||
|
||||
[dependencies.bevy]
|
||||
version = "0.10"
|
||||
version = "0.13"
|
||||
default-features = false
|
||||
features = [
|
||||
"bevy_gilrs",
|
||||
|
@ -31,7 +31,7 @@ features = [
|
|||
|
||||
[dependencies.bevy_rapier3d]
|
||||
features = ["debug-render-3d"]
|
||||
version = "0.21"
|
||||
version = "0.26"
|
||||
|
||||
# Maybe also enable only a small amount of optimization for our code:
|
||||
[profile.dev]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::{
|
||||
diagnostic::FrameTimeDiagnosticsPlugin,
|
||||
ecs::reflect::ReflectResource,
|
||||
prelude::{App, IntoSystemConfigs, Plugin, Resource},
|
||||
prelude::{App, IntoSystemConfigs, Plugin, Resource, Startup, Update},
|
||||
reflect::Reflect,
|
||||
};
|
||||
use bevy_rapier3d::prelude::{NoUserData, RapierPhysicsPlugin};
|
||||
|
@ -28,10 +28,11 @@ impl Plugin for CyberActionPlugin {
|
|||
.init_resource::<CyberLean>()
|
||||
.register_type::<CyberLean>()
|
||||
.register_type::<CatControllerSettings>()
|
||||
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
.add_startup_system(timestep_setup)
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
.add_systems(Startup, timestep_setup)
|
||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
gravity,
|
||||
cyber_lean,
|
||||
|
|
|
@ -53,7 +53,7 @@ pub(super) fn gravity(
|
|||
) {
|
||||
let (xform, mut forces) = query.single_mut();
|
||||
|
||||
#[cfg(feature = "inspectorb")]
|
||||
#[cfg(feature = "inspector")]
|
||||
{
|
||||
if debug_instant.elapsed().as_millis() > 6000 {
|
||||
dbg!(&forces);
|
||||
|
@ -75,7 +75,7 @@ pub(super) fn cyber_lean(
|
|||
mut lean: ResMut<CyberLean>,
|
||||
) {
|
||||
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 steering_angle = yaw_to_angle(input.yaw);
|
||||
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 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 bike_right = xform.right();
|
||||
|
||||
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
|
||||
if pitch_error.abs() < 0.95 {
|
||||
|
@ -135,7 +135,7 @@ pub(super) fn input_forces(
|
|||
|
||||
// thrust
|
||||
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);
|
||||
*forces += force;
|
||||
|
||||
|
@ -227,7 +227,7 @@ pub(super) fn tunnel_out(
|
|||
continue;
|
||||
}
|
||||
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")]
|
||||
dbg!(&tunneling);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ mod body;
|
|||
mod components;
|
||||
mod wheels;
|
||||
|
||||
use bevy::prelude::{
|
||||
App, Assets, IntoSystemConfig, Mesh, Plugin, ResMut, StandardMaterial, StartupSet,
|
||||
};
|
||||
use bevy::prelude::{App, Assets, Mesh, Plugin, PostStartup, ResMut, StandardMaterial};
|
||||
use bevy_rapier3d::prelude::Group;
|
||||
|
||||
pub(crate) use self::components::*;
|
||||
|
@ -23,6 +21,6 @@ impl Plugin for CyberBikePlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(WheelConfig::default())
|
||||
.register_type::<WheelConfig>()
|
||||
.add_startup_system(spawn_cyberbike.in_base_set(StartupSet::PostStartup));
|
||||
.add_systems(PostStartup, spawn_cyberbike);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ fn follow_cyberbike(
|
|||
// handle input pitch
|
||||
let angle = input.pitch.powi(3) * MAX_PITCH;
|
||||
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 => {
|
||||
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
|
||||
query.iter_mut().for_each(|(mut cam, cyber)| {
|
||||
if cyber.eq(&state.0) {
|
||||
if cyber.eq(&state.get()) {
|
||||
cam.is_active = true;
|
||||
} else {
|
||||
cam.is_active = false;
|
||||
|
@ -112,13 +112,13 @@ fn update_active_camera(
|
|||
fn cycle_cam_state(
|
||||
state: Res<State<CyberCameras>>,
|
||||
mut next: ResMut<NextState<CyberCameras>>,
|
||||
mut keys: ResMut<Input<KeyCode>>,
|
||||
mut keys: ResMut<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::D) {
|
||||
let new_state = state.0.next();
|
||||
if keys.just_pressed(KeyCode::KeyD) {
|
||||
let new_state = state.get().next();
|
||||
info!("{:?}", 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) {
|
||||
app.insert_resource(DebugCamOffset::default())
|
||||
.add_startup_system(setup_cybercams)
|
||||
.add_state::<CyberCameras>()
|
||||
.add_system(cycle_cam_state)
|
||||
.add_system(update_active_camera)
|
||||
.add_system(follow_cyberbike);
|
||||
.add_systems(Startup, setup_cybercams)
|
||||
.init_state::<CyberCameras>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(cycle_cam_state, update_active_camera, follow_cyberbike),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ impl Plugin for CyberGlamorPlugin {
|
|||
|
||||
let rplugin = RapierDebugRenderPlugin {
|
||||
style,
|
||||
always_on_top: true,
|
||||
// always_on_top: true,
|
||||
enabled: true,
|
||||
mode,
|
||||
};
|
||||
|
||||
app.add_plugin(rplugin);
|
||||
app.add_plugins(rplugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/input.rs
22
src/input.rs
|
@ -14,22 +14,22 @@ pub(crate) struct InputState {
|
|||
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 shifted = keyset.contains(&KeyCode::LShift) || keyset.contains(&KeyCode::RShift);
|
||||
let shifted = keyset.contains(&KeyCode::ShiftLeft) || keyset.contains(&KeyCode::ShiftRight);
|
||||
|
||||
for key in keyset {
|
||||
match key {
|
||||
KeyCode::Left => offset.rot -= 5.0,
|
||||
KeyCode::Right => offset.rot += 5.0,
|
||||
KeyCode::Up => {
|
||||
KeyCode::ArrowLeft => offset.rot -= 5.0,
|
||||
KeyCode::ArrowRight => offset.rot += 5.0,
|
||||
KeyCode::ArrowUp => {
|
||||
if shifted {
|
||||
offset.alt += 0.5;
|
||||
} else {
|
||||
offset.dist -= 0.5;
|
||||
}
|
||||
}
|
||||
KeyCode::Down => {
|
||||
KeyCode::ArrowDown => {
|
||||
if shifted {
|
||||
offset.alt -= 0.5;
|
||||
} 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 {
|
||||
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();
|
||||
if shifted && !unpressed {
|
||||
keys.press(KeyCode::LShift);
|
||||
keys.press(KeyCode::ShiftLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
GamepadEvent::Button(button_event) => {
|
||||
let GamepadButtonChangedEvent {
|
||||
|
@ -92,7 +93,6 @@ pub struct CyberInputPlugin;
|
|||
impl Plugin for CyberInputPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<InputState>()
|
||||
.add_system(update_input)
|
||||
.add_system(update_debug_cam);
|
||||
.add_systems(Update, (update_input, update_debug_cam));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,6 @@ fn spawn_static_lights(
|
|||
pub struct CyberSpaceLightsPlugin;
|
||||
impl Plugin for CyberSpaceLightsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_startup_system(spawn_static_lights);
|
||||
app.add_systems(Startup, spawn_static_lights);
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -21,18 +21,20 @@ fn main() {
|
|||
}),
|
||||
..Default::default()
|
||||
}))
|
||||
.add_plugin(CyberPlanetPlugin)
|
||||
.add_plugin(CyberInputPlugin)
|
||||
.add_plugin(CyberActionPlugin)
|
||||
.add_plugin(CyberCamPlugin)
|
||||
.add_plugin(CyberSpaceLightsPlugin)
|
||||
.add_plugin(CyberUIPlugin)
|
||||
.add_plugin(CyberBikePlugin)
|
||||
.add_startup_system(disable_mouse_trap)
|
||||
.add_system(bevy::window::close_on_esc);
|
||||
.add_plugins((
|
||||
CyberPlanetPlugin,
|
||||
CyberInputPlugin,
|
||||
CyberActionPlugin,
|
||||
CyberCamPlugin,
|
||||
CyberSpaceLightsPlugin,
|
||||
CyberUIPlugin,
|
||||
CyberBikePlugin,
|
||||
))
|
||||
.add_systems(Startup, disable_mouse_trap)
|
||||
.add_systems(Update, bevy::window::close_on_esc);
|
||||
|
||||
#[cfg(feature = "inspector")]
|
||||
app.add_plugin(CyberGlamorPlugin);
|
||||
app.add_plugins(CyberGlamorPlugin);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy::{
|
||||
prelude::{shape::Icosphere, *},
|
||||
render::{color::Color, mesh::Indices},
|
||||
render::{color::Color, mesh::Indices, render_asset::RenderAssetUsages},
|
||||
};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use hexasphere::shapes::IcoSphere;
|
||||
|
@ -42,7 +42,7 @@ fn spawn_planet(
|
|||
commands
|
||||
.spawn(PbrBundle {
|
||||
mesh: meshes.add(mesh),
|
||||
material: materials.add(Color::WHITE.into()),
|
||||
material: materials.add(Color::WHITE),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(pbody)
|
||||
|
@ -53,7 +53,7 @@ fn spawn_planet(
|
|||
pub struct CyberPlanetPlugin;
|
||||
impl Plugin for CyberPlanetPlugin {
|
||||
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 collider = Collider::trimesh(points.iter().map(|p| Vect::from_slice(p)).collect(), idxs);
|
||||
|
||||
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
|
||||
mesh.set_indices(Some(indices));
|
||||
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all());
|
||||
mesh.insert_indices(indices);
|
||||
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, points);
|
||||
//mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
|
||||
mesh.duplicate_vertices();
|
||||
|
|
13
src/ui.rs
13
src/ui.rs
|
@ -1,6 +1,9 @@
|
|||
use bevy::prelude::{
|
||||
use bevy::{
|
||||
app::{Startup, Update},
|
||||
prelude::{
|
||||
AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text,
|
||||
TextBundle, TextSection, TextStyle, Transform, With,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "inspector")]
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
@ -42,7 +45,7 @@ fn update_ui(
|
|||
) {
|
||||
let mut text = text_query.single_mut();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -51,8 +54,10 @@ pub struct CyberUIPlugin;
|
|||
impl Plugin for CyberUIPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue