Skip to content

Commit

Permalink
feat: update bevy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeder committed Aug 15, 2023
1 parent d28295c commit b7446ba
Show file tree
Hide file tree
Showing 22 changed files with 845 additions and 644 deletions.
963 changes: 558 additions & 405 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ lto = "thin"

# WASM requirements
[target.'cfg(target_arch = "wasm32")'.dependencies]
bevy_ggrs = { version = "0.12", features = ["wasm-bindgen"] }
bevy_ggrs = { version = "0.13", 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.0", default-features = false, features = [
"bevy_gltf",
"bevy_winit",
"bevy_render",
Expand All @@ -43,13 +43,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 = { version = "0.13" }
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
34 changes: 23 additions & 11 deletions src/debug/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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>()
Expand All @@ -39,13 +39,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 +75,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 +92,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 +107,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
28 changes: 16 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,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
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy::winit::WinitWindows;
use bevy::DefaultPlugins;
use bevy_ggrs::GGRSPlugin;
use bevy_ggrs::GgrsPlugin;
use std::io::Cursor;
use turtle_time::npc::components::{EdibleTarget, Goose, HasTarget};
use turtle_time::player::checksum::Checksum;
Expand All @@ -21,7 +21,7 @@ use winit::window::Icon;
fn main() {
let mut app = App::new();

GGRSPlugin::<GGRSConfig>::new()
GgrsPlugin::<GGRSConfig>::new()
.with_update_frequency(FPS)
.with_input_system(input)
.register_rollback_component::<Checksum>()
Expand Down Expand Up @@ -68,8 +68,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 b7446ba

Please sign in to comment.