Skip to content

Commit

Permalink
feat: bevy 0.11 and related deps update (#1)
Browse files Browse the repository at this point in the history
* Updates project to Bevy `0.11.3` and updates related dependencies.
  * Necessary fixes for breaking changes introduced by updates.
* Switched to `bevy_ggrs` main branch to resolve a parent->child transform propagation regression ( See [here](gschup/bevy_ggrs#74) )
  • Loading branch information
mikeder authored Oct 23, 2023
1 parent d28295c commit 5ee5450
Show file tree
Hide file tree
Showing 24 changed files with 918 additions and 698 deletions.
967 changes: 559 additions & 408 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turtle_time"
version = "0.10.3"
version = "0.10.4"
publish = false
authors = ["Mike Eder <mikedernet@gmail.com>"]
edition = "2021"
Expand All @@ -23,14 +23,16 @@ lto = "thin"

# WASM requirements
[target.'cfg(target_arch = "wasm32")'.dependencies]
bevy_ggrs = { version = "0.12", features = ["wasm-bindgen"] }
bevy_ggrs = { git = "https://github.com/gschup/bevy_ggrs.git", branch = "main", features = [
"wasm-bindgen",
] }
js-sys = { version = "0.3" }
wasm-bindgen = { version = "0.2.84" }
wasm-bindgen-futures = { version = "0.4.34" }

# Main requirements
[dependencies]
bevy = { version = "0.10.1", default-features = false, features = [
bevy = { version = "0.11.3", default-features = false, features = [
"bevy_gltf",
"bevy_winit",
"bevy_render",
Expand All @@ -43,13 +45,11 @@ bevy = { version = "0.10.1", default-features = false, features = [
"png",
"x11",
] }
bevy_kira_audio = { version = "0.15" }
bevy_asset_loader = { version = "0.15" }
bevy_ggrs = { version = "0.12" }
bevy_matchbox = { version = "*", features = [
"ggrs",
], git = "https://github.com/johanhelsing/matchbox.git", rev = "8e864f121d616fdd4307819e058133ff959f7e3f" }
bevy-inspector-egui = "0.18.3"
bevy_kira_audio = { git = "https://github.com/NiklasEi/bevy_kira_audio.git", branch = "bevy_main" }
bevy_asset_loader = { version = "0.17" }
bevy_ggrs = { git = "https://github.com/gschup/bevy_ggrs.git", branch = "main" }
bevy_matchbox = { version = "0.7.0", features = ["ggrs"] }
bevy-inspector-egui = "0.19"
bytemuck = { version = "1.7.3", features = ["derive"] }
ggrs = { version = "0.9.4", features = ["sync-send"] }
percentage = { version = "*" }
Expand Down
2 changes: 1 addition & 1 deletion src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct AsciiText;

impl Plugin for AsciiPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(load_ascii);
app.add_systems(Startup, load_ascii);
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{AppState, GameState, FPS};
use bevy::core::FrameCount;
use bevy::prelude::*;
use bevy::utils::{HashMap, HashSet};
use bevy_ggrs::Rollback;
use bevy_kira_audio::prelude::*;
use bevy_kira_audio::{Audio, AudioPlugin};

Expand All @@ -16,13 +15,13 @@ pub struct InternalAudioPlugin;
// This plugin is responsible to control the game audio
impl Plugin for InternalAudioPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(AudioPlugin)
app.add_plugins(AudioPlugin)
.init_resource::<PlaybackStates>()
.add_system(init_audio.in_schedule(OnExit(AppState::Loading)))
.add_system(sync_rollback_sounds)
.add_system(remove_finished_sounds)
.add_system(update_looped_sounds)
.add_system(stop_all_sounds.in_schedule(OnEnter(GameState::Paused)));
.add_systems(OnExit(AppState::Loading), init_audio)
.add_systems(Update, sync_rollback_sounds)
.add_systems(Update, remove_finished_sounds)
.add_systems(Update, update_looped_sounds)
.add_systems(OnEnter(GameState::Paused), stop_all_sounds);
}
}

Expand All @@ -49,8 +48,6 @@ impl RollbackSound {
#[derive(Bundle)]
pub struct RollbackSoundBundle {
pub sound: RollbackSound,
/// an id to make sure that the entity will be removed in case of rollbacks
pub rollback: Rollback,
}

fn init_audio(audio: Res<Audio>) {
Expand Down Expand Up @@ -115,7 +112,7 @@ fn sync_rollback_sounds(
// stop interrupted sound effects
for (_, instance_handle) in current_state
.playing
.drain_filter(|key, _| !live.contains(key))
.extract_if(|key, _| !live.contains(key))
{
if let Some(instance) = audio_instances.get_mut(&instance_handle) {
// todo: add config to use linear tweening, stop or keep playing as appropriate
Expand Down
5 changes: 4 additions & 1 deletion src/debug/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
position: UiRect::new(Val::Px(10.), Val::Auto, Val::Px(5.), Val::Auto),
left: Val::Px(10.),
right: Val::Auto,
top: Val::Px(5.),
bottom: Val::Auto,
flex_direction: FlexDirection::Column,
align_content: AlignContent::Center,
align_items: AlignItems::Center,
Expand Down
38 changes: 26 additions & 12 deletions src/debug/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
player::{
checksum::Checksum,
components::{Edible, EdibleSpawnTimer, Player, PlayerHealth},
resources::HealthBarsAdded,
},
AppState, GameState,
};
Expand All @@ -22,15 +23,16 @@ pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
if cfg!(debug_assertions) {
app.add_plugin(WorldInspectorPlugin::new())
app.add_plugins(WorldInspectorPlugin::new())
.register_type::<Checksum>()
.register_type::<ConsoleReady>()
.register_type::<LocalHandle>()
.register_type::<EdibleTarget>()
.register_type::<Edible>()
.register_type::<EdibleSpawnTimer>()
.register_type::<Player>()
.register_type::<PlayerHealth>();
.register_type::<PlayerHealth>()
.register_type::<HealthBarsAdded>();
}
}
}
Expand All @@ -39,13 +41,25 @@ pub struct ConsolePlugin;

impl Plugin for ConsolePlugin {
fn build(&self, app: &mut App) {
app.add_system(setup_ui.in_schedule(OnExit(AppState::Loading)))
.add_system(log_ggrs_events.in_set(OnUpdate(GameState::Playing)))
.add_system(open_console)
.add_system(count_edibles.run_if(resource_exists::<EdibleCount>()))
.add_system(update_console_text.run_if(resource_exists::<PeerInfo>()))
.add_system(reset_console_ready.run_if(resource_exists::<PeerInfo>()))
.add_system(update_peer_info.run_if(resource_exists::<Session<GGRSConfig>>()));
app.add_systems(OnExit(AppState::Loading), setup_ui)
.add_systems(Update, log_ggrs_events.run_if(in_state(GameState::Playing)))
.add_systems(Update, open_console)
.add_systems(
Update,
count_edibles.run_if(resource_exists::<EdibleCount>()),
)
.add_systems(
Update,
update_console_text.run_if(resource_exists::<PeerInfo>()),
)
.add_systems(
Update,
reset_console_ready.run_if(resource_exists::<PeerInfo>()),
)
.add_systems(
Update,
update_peer_info.run_if(resource_exists::<Session<GGRSConfig>>()),
);
}
}

Expand All @@ -63,7 +77,7 @@ pub fn update_peer_info(
if timer.0.tick(time.delta()).just_finished() {
let mut tmp = String::new();
match session.as_ref() {
Session::P2PSession(s) => {
Session::P2P(s) => {
for player_handle in s.remote_player_handles() {
let stats = match s.network_stats(player_handle) {
Ok(res) => {
Expand All @@ -80,7 +94,7 @@ pub fn update_peer_info(
tmp.push_str("\n");
}
}
Session::SyncTestSession(s) => {
Session::SyncTest(s) => {
let line = format!("Local players {}", s.num_players());
tmp.reserve(line.len() + 1);
tmp.push_str("\n");
Expand All @@ -95,7 +109,7 @@ pub fn update_peer_info(

pub fn log_ggrs_events(mut session: ResMut<Session<GGRSConfig>>) {
match session.as_mut() {
Session::P2PSession(s) => {
Session::P2P(s) => {
for event in s.events() {
info!("GGRS Event: {:?}", event);
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct Border;

impl Plugin for GraphicsPlugin {
fn build(&self, app: &mut App) {
app.add_system(Self::load_graphics.in_schedule(OnEnter(AppState::MenuMain)))
.add_system(Self::frame_animation);
app.add_systems(OnEnter(AppState::MenuMain), Self::load_graphics)
.add_systems(Update, Self::frame_animation);
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use bevy::diagnostic::LogDiagnosticsPlugin;
pub const ASPECT_RATIO: f32 = 16.0 / 9.0;
pub const MAP_HEIGHT: f32 = 768.0;
pub const TILE_SIZE: f32 = 32.0;
pub const HEALTH_BAR_Y_OFFSET: f32 = TILE_SIZE + 10.;
pub const FPS: usize = 60;
pub const FIXED_TICK_MS: u64 = 1000 / FPS as u64; // use fixed duration tick delta to keep in sync with GGRSSchedule

Expand Down Expand Up @@ -77,22 +78,26 @@ impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_state::<AppState>()
.add_state::<GameState>()
.add_plugin(AsciiPlugin)
.add_plugin(LoadingPlugin)
.add_plugin(GraphicsPlugin)
.add_plugin(TileMapPlugin)
.add_plugin(MenuPlugin)
.add_plugin(InternalAudioPlugin)
.add_plugin(PlayerPlugin)
.add_plugin(GoosePlugin)
.add_plugin(ConsolePlugin);
.add_plugins((
AsciiPlugin,
LoadingPlugin,
GraphicsPlugin,
TileMapPlugin,
MenuPlugin,
InternalAudioPlugin,
PlayerPlugin,
GoosePlugin,
ConsolePlugin,
));

#[cfg(debug_assertions)]
{
// With FPS
app.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(DebugPlugin)
.add_plugin(LogDiagnosticsPlugin::default());
app.add_plugins((
FrameTimeDiagnosticsPlugin::default(),
DebugPlugin,
LogDiagnosticsPlugin::default(),
));

// Without FPS
// app.add_plugin(DebugPlugin)
Expand Down
19 changes: 10 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy::winit::WinitWindows;
use bevy::DefaultPlugins;
use bevy_ggrs::GGRSPlugin;
use bevy_ggrs::{GgrsApp, GgrsPlugin, ReadInputs};
use std::io::Cursor;
use turtle_time::npc::components::{EdibleTarget, Goose, HasTarget};
use turtle_time::player::checksum::Checksum;
use turtle_time::player::components::{
Edible, EdibleSpawnTimer, Expired, Fireball, FireballAmmo, FireballMovement, FireballReady,
FireballTimer, Player, PlayerHealth, PlayerPoop, PlayerPoopTimer, PlayerSpeed,
FireballTimer, Player, PlayerHealth, PlayerHealthBar, PlayerPoop, PlayerPoopTimer, PlayerSpeed,
PlayerSpeedBoost, RoundComponent,
};
use turtle_time::player::input::{input, GGRSConfig, PlayerControls};
Expand All @@ -21,9 +21,10 @@ use winit::window::Icon;
fn main() {
let mut app = App::new();

GGRSPlugin::<GGRSConfig>::new()
.with_update_frequency(FPS)
.with_input_system(input)
// TODO: move GGRS plugin setup out of mains
app.add_plugins(GgrsPlugin::<GGRSConfig>::default())
.set_rollback_schedule_fps(FPS)
.add_systems(ReadInputs, input)
.register_rollback_component::<Checksum>()
.register_rollback_component::<Edible>()
.register_rollback_component::<EdibleTarget>()
Expand All @@ -37,15 +38,15 @@ fn main() {
.register_rollback_component::<HasTarget>()
.register_rollback_component::<Player>()
.register_rollback_component::<PlayerHealth>()
.register_rollback_component::<PlayerHealthBar>()
.register_rollback_component::<PlayerSpeed>()
.register_rollback_component::<PlayerSpeedBoost>()
.register_rollback_component::<PlayerControls>()
.register_rollback_component::<PlayerPoop>()
.register_rollback_component::<PlayerPoopTimer>()
.register_rollback_component::<RoundComponent>()
.register_rollback_component::<Transform>()
.register_rollback_resource::<EdibleSpawnTimer>()
.build(&mut app);
.register_rollback_resource::<EdibleSpawnTimer>();

app.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.0, 0.3, 0.0)))
Expand All @@ -68,8 +69,8 @@ fn main() {
level: bevy::log::Level::WARN,
}),
)
.add_plugin(GamePlugin)
.add_system(set_window_icon.on_startup())
.add_plugins(GamePlugin)
.add_systems(Startup, set_window_icon)
.run();
}

Expand Down
6 changes: 3 additions & 3 deletions src/map/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub struct TileCollider;

impl Plugin for TileMapPlugin {
fn build(&self, app: &mut App) {
app.add_system(Self::spawn_map.in_schedule(OnExit(AppState::Loading)))
.add_system(Self::show_map.in_schedule(OnEnter(GameState::Playing)))
.add_system(Self::hide_map.in_schedule(OnEnter(GameState::Paused)));
app.add_systems(OnExit(AppState::Loading), Self::spawn_map)
.add_systems(OnEnter(GameState::Playing), Self::show_map)
.add_systems(OnEnter(GameState::Paused), Self::hide_map);
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/menu/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn lobby_system(
.start_p2p_session(channel)
.expect("Session could not be created.");

commands.insert_resource(Session::P2PSession(sess));
commands.insert_resource(Session::P2P(sess));
commands.insert_resource(AgreedRandom::new(peers));
app_state.set(AppState::RoundOnline);
game_state.set(GameState::Playing);
Expand All @@ -129,7 +129,10 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
position: UiRect::all(Val::Px(0.)),
left: Val::Px(0.),
right: Val::Px(0.),
top: Val::Px(0.),
bottom: Val::Px(0.),
flex_direction: FlexDirection::Column,
align_content: AlignContent::Center,
align_items: AlignItems::Center,
Expand Down Expand Up @@ -165,7 +168,8 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
parent
.spawn(ButtonBundle {
style: Style {
size: Size::new(Val::Px(250.0), Val::Px(65.0)),
width: Val::Px(250.),
height: Val::Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
margin: UiRect::all(Val::Px(16.)),
Expand Down Expand Up @@ -201,7 +205,7 @@ pub fn btn_visuals(
) {
for (interaction, mut color) in interaction_query.iter_mut() {
match *interaction {
Interaction::Clicked => {
Interaction::Pressed => {
*color = PRESSED_BUTTON.into();
}
Interaction::Hovered => {
Expand All @@ -219,7 +223,7 @@ pub fn btn_listeners(
mut interaction_query: Query<(&Interaction, &MenuConnectBtn), Changed<Interaction>>,
) {
for (interaction, btn) in interaction_query.iter_mut() {
if let Interaction::Clicked = *interaction {
if let Interaction::Pressed = *interaction {
match btn {
MenuConnectBtn::Back => {
state.set(AppState::MenuMain);
Expand Down
Loading

0 comments on commit 5ee5450

Please sign in to comment.