Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Bevy 0.13 #5

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,387 changes: 1,210 additions & 1,177 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ inspector = ["bevy-inspector-egui"]
debugdump = ["bevy_mod_debugdump"]

[dependencies]
bevy = { version = "0.12", features = ["wav"] }
bevy_rapier3d = "0.23"
bevy_asset_loader = "0.18"
bevy-inspector-egui = { version = "0.21", optional = true }
leafwing-input-manager = "0.11"
bevy_jornet = { git = "https://github.com/rparrett/jornet", branch = "event-0.12" }
bevy-ui-navigation = "0.33.0"
bevy_mod_debugdump = { version = "0.9", optional = true }
#bevy_tiling_background = { git = "https://github.com/BraymatterOrg/bevy_tiling_background.git", rev="85f0f82" }
bevy_tiling_background = { git = "https://github.com/rparrett/bevy_tiling_background.git", branch = "bevy-0.12" }
bevy_pipelines_ready = "0.2"
bevy = { version = "0.13", features = ["wav"] }
bevy_rapier3d = "0.25"
bevy_asset_loader = "0.20"
bevy-inspector-egui = { version = "0.23", optional = true }
leafwing-input-manager = "0.13"
bevy_jornet = { git = "https://github.com/rparrett/jornet", branch = "event-0.13" }
bevy_tiling_background = { git = "https://github.com/BraymatterOrg/bevy_tiling_background.git", rev = "c84395d" }
bevy_mod_debugdump = { version = "0.10", optional = true }
bevy-alt-ui-navigation-lite = "0.1"
bevy_pipelines_ready = "0.3"

interpolation = "0.2"
serde = "*"
Expand Down
6 changes: 3 additions & 3 deletions src/countdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ fn update(
commands.spawn(AudioBundle {
source: game_audio.three_two_one.clone(),
settings: PlaybackSettings::DESPAWN
.with_volume(Volume::new_relative(**audio_setting as f32 / 100.)),
.with_volume(Volume::new(**audio_setting as f32 / 100.)),
});
}

timer.countdown.tick(time.delta());

for mut text in text_query.iter_mut() {
let left =
timer.countdown.percent_left() * timer.countdown.duration().as_secs_f32();
timer.countdown.fraction_remaining() * timer.countdown.duration().as_secs_f32();

text.sections[0].value = format!("{}", left.ceil());
text.sections[0].style.color = Color::rgba(1., 0., 0., Ease::cubic_out(left % 1.));
Expand All @@ -71,7 +71,7 @@ fn update(
timer.go.tick(time.delta());
for mut text in text_query.iter_mut() {
text.sections[0].style.color =
Color::rgba(1., 0., 0., Ease::cubic_out(timer.go.percent_left()));
Color::rgba(1., 0., 0., Ease::cubic_out(timer.go.fraction_remaining()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_over.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use bevy_ui_navigation::prelude::*;
use bevy_alt_ui_navigation_lite::prelude::*;

use crate::{
loading::GameAssets,
Expand Down
2 changes: 1 addition & 1 deletion src/leaderboard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cmp::Ordering;

use bevy::prelude::*;
use bevy_alt_ui_navigation_lite::prelude::*;
use bevy_jornet::{JornetEvent, JornetPlugin, Leaderboard};
use bevy_ui_navigation::prelude::*;

use crate::{
loading::GameAssets,
Expand Down
17 changes: 12 additions & 5 deletions src/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ impl Plugin for LoadingPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(PipelinesReadyPlugin)
.add_loading_state(
LoadingState::new(GameState::Loading).continue_to_state(GameState::Decorating),
LoadingState::new(GameState::Loading)
.load_collection::<GameAssets>()
.load_collection::<AudioAssets>()
.continue_to_state(GameState::Decorating),
)
.add_collection_to_loading_state::<_, GameAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, AudioAssets>(GameState::Loading)
.add_systems(
Update,
check_pipelines.run_if(in_state(GameState::Pipelines)),
(
check_pipelines.run_if(in_state(GameState::Pipelines)),
log_pipelines.run_if(resource_changed::<PipelinesReady>),
),
)
.add_systems(OnExit(GameState::Pipelines), cleanup)
.add_systems(OnEnter(GameState::Pipelines), setup_pipelines);
Expand All @@ -62,12 +66,15 @@ fn setup_pipelines(mut commands: Commands) {
}

fn check_pipelines(ready: Res<PipelinesReady>, mut next_state: ResMut<NextState<GameState>>) {
info!("Pipelines: {}/{}", ready.get(), EXPECTED_PIPELINES);
if ready.get() >= EXPECTED_PIPELINES {
next_state.set(GameState::MainMenu);
}
}

fn log_pipelines(pipelines: Res<PipelinesReady>) {
info!("Pipelines: {}/{}", pipelines.get(), EXPECTED_PIPELINES);
}

fn cleanup(mut commands: Commands, query: Query<Entity, With<PipelinesMarker>>) {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
Expand Down
118 changes: 54 additions & 64 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,21 @@ use std::f32::consts::TAU;
use std::{fs::File, io::Write};

use bevy::{
asset::AssetMetaCheck,
audio::Volume,
core_pipeline::clear_color::ClearColorConfig,
log::LogPlugin,
pbr::CascadeShadowConfigBuilder,
prelude::*,
render::view::{NoFrustumCulling, RenderLayers},
time::Stopwatch,
transform::TransformSystem,
asset::AssetMetaCheck, audio::Volume, log::LogPlugin, pbr::CascadeShadowConfigBuilder,
prelude::*, render::view::RenderLayers, time::Stopwatch, transform::TransformSystem,
};
#[cfg(feature = "inspector")]
use bevy_inspector_egui::quick::WorldInspectorPlugin;

use bevy_alt_ui_navigation_lite::{systems::InputMapping, DefaultNavigationPlugins};
use bevy_rapier3d::prelude::*;
use bevy_tiling_background::{
BackgroundImageBundle, BackgroundMaterial, SetImageRepeatingExt, TilingBackgroundPlugin,
};
use bevy_ui_navigation::{systems::InputMapping, DefaultNavigationPlugins};

use countdown::CountdownPlugin;
use game_over::GameOverPlugin;
use interpolation::{Ease, Lerp};
use interpolation::Ease;
use leaderboard::{get_leaderboard_credentials, LeaderboardPlugin};
use leafwing_input_manager::{axislike::AxisType, prelude::*};
use loading::{AudioAssets, GameAssets, LoadingPlugin};
Expand Down Expand Up @@ -99,9 +92,6 @@ pub enum GameSet {
#[derive(Component)]
struct MusicController;

#[derive(Component)]
struct LightContainer;

#[derive(Component, Deref, DerefMut)]
struct SpeedLimit(f32);

Expand Down Expand Up @@ -192,11 +182,11 @@ fn main() {
.set(LogPlugin {
filter: "info,bevy_ecs=debug,wgpu_core=warn,wgpu_hal=warn,combine_racers=debug".into(),
level: bevy::log::Level::DEBUG,
..default()
})
.set(WindowPlugin {
primary_window: Some(Window {
title: "Combine Racers".into(),
fit_canvas_to_parent: true,
..default()
}),
..default()
Expand All @@ -214,7 +204,7 @@ fn main() {
app.add_plugins(default_plugins);

app.insert_resource(ClearColor(Color::BLACK))
.add_state::<GameState>()
.init_state::<GameState>()
.add_plugins(LoadingPlugin)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.insert_resource(InputMapping {
Expand All @@ -235,11 +225,6 @@ fn main() {
{
app.add_plugins(WorldInspectorPlugin::new());
app.add_plugins(RapierDebugRenderPlugin::default());

// Don't show debug viz on 2d background camera.
let mut config = GizmoConfig::default();
config.render_layers = RenderLayers::layer(1);
app.insert_resource(config);
}

app.init_resource::<RaceTime>().init_resource::<Zoom>();
Expand All @@ -254,6 +239,8 @@ fn main() {
.before(TransformSystem::TransformPropagate),
);

app.add_systems(Startup, configure_gizmos);

app.add_systems(OnExit(GameState::Loading), spawn_camera)
.add_systems(OnEnter(GameState::Decorating), setup_game)
.add_systems(
Expand Down Expand Up @@ -346,20 +333,19 @@ enum Action {

fn spawn_camera(mut commands: Commands, zoom: Res<Zoom>) {
// For the background
commands.spawn((
Camera2dBundle {
camera: Camera {
order: -1,
..default()
},
commands.spawn(Camera2dBundle {
camera: Camera {
order: -1,
..default()
},
UiCameraConfig { show_ui: false },
));
..default()
});

// TODO don't render UI to the background camera

commands.spawn((
Camera3dBundle {
camera_3d: Camera3d {
camera: Camera {
clear_color: ClearColorConfig::None,
..default()
},
Expand Down Expand Up @@ -441,17 +427,15 @@ fn setup_game(
) {
commands.set_image_repeating(assets.background.clone());

commands.spawn((
commands.spawn(
BackgroundImageBundle::from_image(assets.background.clone(), materials.as_mut())
.with_movement_scale(1.0)
.at_z_layer(0.1),
// Workaround for https://github.com/BraymatterOrg/bevy_tiling_background/issues/22
NoFrustumCulling,
));
);

commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 32_000.0,
illuminance: 10_000.0,
shadows_enabled: true,
..default()
},
Expand All @@ -466,7 +450,7 @@ fn setup_game(

// ambient light
commands.insert_resource(AmbientLight {
brightness: 0.15,
brightness: 60.0,
..default()
});

Expand Down Expand Up @@ -498,35 +482,35 @@ fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
axes.insert(LockedAxes::TRANSLATION_LOCKED_Z);

let mut input_map = InputMap::new([
(KeyCode::Left, Action::Back),
(KeyCode::A, Action::Back),
(KeyCode::Right, Action::Forward),
(KeyCode::D, Action::Forward),
(KeyCode::Q, Action::RotateLeft),
(KeyCode::E, Action::RotateRight),
(KeyCode::Space, Action::Jump),
(KeyCode::Z, Action::ToggleZoom),
(KeyCode::Escape, Action::Reset),
(Action::Back, KeyCode::ArrowLeft),
(Action::Back, KeyCode::KeyA),
(Action::Forward, KeyCode::ArrowRight),
(Action::Forward, KeyCode::KeyD),
(Action::RotateLeft, KeyCode::KeyQ),
(Action::RotateRight, KeyCode::KeyE),
(Action::Jump, KeyCode::Space),
(Action::ToggleZoom, KeyCode::KeyZ),
(Action::Reset, KeyCode::Escape),
]);

input_map.insert_multiple([
(GamepadButtonType::DPadLeft, Action::Back),
(GamepadButtonType::DPadRight, Action::Forward),
(GamepadButtonType::LeftTrigger, Action::RotateLeft),
(GamepadButtonType::RightTrigger, Action::RotateRight),
(GamepadButtonType::South, Action::Jump),
(GamepadButtonType::North, Action::ToggleZoom),
(GamepadButtonType::Select, Action::Reset),
(Action::Back, GamepadButtonType::DPadLeft),
(Action::Forward, GamepadButtonType::DPadRight),
(Action::RotateLeft, GamepadButtonType::LeftTrigger),
(Action::RotateRight, GamepadButtonType::RightTrigger),
(Action::Jump, GamepadButtonType::South),
(Action::ToggleZoom, GamepadButtonType::North),
(Action::Reset, GamepadButtonType::Select),
]);

input_map.insert_multiple([
(
SingleAxis::negative_only(AxisType::Gamepad(GamepadAxisType::LeftStickX), -0.3),
Action::Back,
SingleAxis::negative_only(AxisType::Gamepad(GamepadAxisType::LeftStickX), -0.3),
),
(
SingleAxis::positive_only(AxisType::Gamepad(GamepadAxisType::LeftStickX), 0.3),
Action::Forward,
SingleAxis::positive_only(AxisType::Gamepad(GamepadAxisType::LeftStickX), 0.3),
),
]);

Expand Down Expand Up @@ -645,19 +629,19 @@ fn player_movement(
{
force.force = Vec3::ZERO;

if action_state.pressed(Action::Back) && **jump_wheels >= 1 {
if action_state.pressed(&Action::Back) && **jump_wheels >= 1 {
force.force = transform.rotation * -Vec3::X * DRIVE_FORCE;
}
if action_state.pressed(Action::Forward) && **jump_wheels >= 1 {
if action_state.pressed(&Action::Forward) && **jump_wheels >= 1 {
force.force = transform.rotation * Vec3::X * DRIVE_FORCE;
}
if action_state.pressed(Action::RotateLeft) {
if action_state.pressed(&Action::RotateLeft) {
velocity.angvel += Vec3::Z * ROT_SPEED * time.delta_seconds();
}
if action_state.pressed(Action::RotateRight) {
if action_state.pressed(&Action::RotateRight) {
velocity.angvel += -Vec3::Z * ROT_SPEED * time.delta_seconds();
}
if action_state.just_pressed(Action::Jump) && **jump_wheels >= 1 && !**jump_cooldown {
if action_state.just_pressed(&Action::Jump) && **jump_wheels >= 1 && !**jump_cooldown {
// We don't want a jump from an angled ramp to impart any impulse in the backwards
// direction, slowing the player down.
//
Expand Down Expand Up @@ -898,7 +882,7 @@ fn track_trick(
commands.spawn(AudioBundle {
source: game_audio.trick.clone(),
settings: PlaybackSettings::DESPAWN
.with_volume(Volume::new_relative(**audio_setting as f32 / 100.)),
.with_volume(Volume::new(**audio_setting as f32 / 100.)),
});
}

Expand Down Expand Up @@ -933,7 +917,7 @@ fn race_time(time: Res<Time>, mut race_time: ResMut<RaceTime>) {

fn start_zoom(query: Query<&ActionState<Action>, With<Player>>, mut zoom: ResMut<Zoom>) {
let action_state = query.single();
if action_state.just_pressed(Action::ToggleZoom) && zoom.timer.paused() {
if action_state.just_pressed(&Action::ToggleZoom) && zoom.timer.paused() {
(zoom.target, zoom.from) = (zoom.from, zoom.target);

zoom.timer.reset();
Expand All @@ -956,7 +940,7 @@ fn zoom(

let z = zoom
.from
.lerp(&zoom.target, &Ease::quadratic_in_out(zoom.timer.percent()));
.lerp(zoom.target, Ease::quadratic_in_out(zoom.timer.fraction()));

camera.translation.z = z;

Expand All @@ -976,7 +960,7 @@ fn bonk_sound(
commands.spawn(AudioBundle {
source: game_audio.bonk.clone(),
settings: PlaybackSettings::ONCE
.with_volume(Volume::new_relative(**audio_setting as f32 / 100.)),
.with_volume(Volume::new(**audio_setting as f32 / 100.)),
});
}
}
Expand All @@ -1001,7 +985,7 @@ fn reset_action(
mut race_time: ResMut<RaceTime>,
) {
let action_state = query.single();
if action_state.just_pressed(Action::Reset) {
if action_state.just_pressed(&Action::Reset) {
race_time.pause();
next_state.set(GameState::GameOver);
}
Expand All @@ -1017,3 +1001,9 @@ fn reset(
}
race_time.reset();
}

fn configure_gizmos(mut config_store: ResMut<GizmoConfigStore>) {
for (_, config, _) in config_store.iter_mut() {
config.render_layers = RenderLayers::layer(1);
}
}
Loading
Loading