Skip to content

Commit

Permalink
Upgrade rust, bevy, hanabi and others
Browse files Browse the repository at this point in the history
Bevy 0.11 is the big one.
  • Loading branch information
haihala committed Aug 30, 2023
1 parent 68aa2a0 commit d752628
Show file tree
Hide file tree
Showing 53 changed files with 1,047 additions and 955 deletions.
1,478 changes: 785 additions & 693 deletions client/Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ incremental = true
opt-level = 3

[workspace.dependencies]
bevy = "0.10"
bevy-inspector-egui = "0.18"
bevy_hanabi = "0.6"
bevy = "0.11.2"
bevy-inspector-egui = "0.19.0"
bevy_hanabi = "0.7.0"
rand = "0.8"
map-macro = "0.2"
strum = "0.24"
strum_macros = "0.24"
strum = "0.25.0"
strum_macros = "0.25.2"
clap = {version = "4.1.7", features = ["derive"] }
2 changes: 1 addition & 1 deletion client/characters/src/moves/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;

use crate::{Action, Movement, PropertyType, ToHit};

#[derive(Debug, Clone, PartialEq, Component, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Component, Reflect)]
pub struct Attack {
pub to_hit: ToHit,
pub self_on_hit: Vec<Action>,
Expand Down
3 changes: 2 additions & 1 deletion client/characters/src/moves/move_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use wag_core::MoveId;
use crate::{Action, Move};

use super::FlowControl;
#[derive(Debug, Default, Clone, Reflect, FromReflect)]

#[derive(Debug, Default, Clone, Reflect)]
pub struct MoveHistory {
pub move_id: MoveId,
#[reflect(ignore)]
Expand Down
4 changes: 2 additions & 2 deletions client/characters/src/moves/move_phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{Attack, PropertyType};

use super::Situation;

#[derive(Debug, Clone, Copy, PartialEq, Default, Reflect, FromReflect)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Reflect)]
pub struct Movement {
pub amount: Vec2,
pub duration: usize,
Expand All @@ -20,7 +20,7 @@ impl Movement {
}
}

#[derive(Debug, Clone, PartialEq, Default, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Default, Reflect)]
pub enum Action {
// TODO: Figure out a better way to handle actions that change depending on game state
// Maybe hoist AnimationRequest?
Expand Down
14 changes: 6 additions & 8 deletions client/characters/src/moves/to_hit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;

use wag_core::{Area, Joint, Model};

#[derive(Debug, Clone, Copy, PartialEq, Reflect, FromReflect)]
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
pub struct ToHit {
pub block_type: BlockType,
pub hitbox: Hitbox,
Expand All @@ -29,33 +29,31 @@ impl Default for ToHit {
}
}

#[derive(Clone, Copy, Debug, Reflect, FromReflect, Eq, PartialEq, Default)]
#[derive(Clone, Copy, Debug, Reflect, Eq, PartialEq, Default)]
pub enum AttackHeight {
Low,
#[default]
Mid,
High,
}

#[derive(Clone, Copy, Debug, Reflect, FromReflect, Eq, PartialEq, Default, Component)]
#[derive(Clone, Copy, Debug, Reflect, Eq, PartialEq, Default, Component)]
pub enum BlockType {
Constant(AttackHeight),
Grab,
#[default]
Dynamic,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect, FromReflect)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect)]
pub struct Projectile {
pub model: Model,
}

#[derive(
Default, Clone, Copy, Deref, DerefMut, Debug, Component, Reflect, FromReflect, PartialEq,
)]
#[derive(Default, Clone, Copy, Deref, DerefMut, Debug, Component, Reflect, PartialEq)]
pub struct Hitbox(pub Area);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect, FromReflect)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect)]
pub struct Lifetime {
pub despawn_on_hit: bool,
pub despawn_on_landing: bool,
Expand Down
4 changes: 2 additions & 2 deletions client/characters/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{prelude::*, utils::HashMap};

use wag_core::{GameButton, Stats, StickPosition};

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Reflect, FromReflect)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Reflect)]
pub enum PropertyType {
Health,
Meter,
Expand Down Expand Up @@ -36,7 +36,7 @@ impl Properties {
),
]
.into_iter()
.chain(additional_properties.into_iter())
.chain(additional_properties)
.collect(),
)
}
Expand Down
4 changes: 2 additions & 2 deletions client/input_parsing/src/helper_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use map_macro::set;
use map_macro::hash_set;
use std::collections::HashSet;

use wag_core::{GameButton, StickPosition};
Expand Down Expand Up @@ -70,7 +70,7 @@ fn add_or_init(base: Option<HashSet<GameButton>>, button: GameButton) -> HashSet
pressed.insert(button);
pressed
} else {
set! {button}
hash_set! {button}
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/input_parsing/src/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mod test {

fn new(moves: Vec<(MoveId, &'static str)>) -> TestInterface {
let mut app = App::new();
app.add_system(parse_input::<TestStream>);
app.add_systems(Update, parse_input::<TestStream>);

app.world.spawn((
TestInputBundle::new(moves.into_iter().collect()),
Expand Down
1 change: 1 addition & 0 deletions client/input_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl PadReserve {
impl Plugin for InputParsingPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(PadReserve::default()).add_systems(
Update,
(
update_pads,
update_parrots::<PadStream>,
Expand Down
4 changes: 2 additions & 2 deletions client/input_parsing/src/motion_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl From<&str> for MotionInput {

#[cfg(test)]
mod test {
use map_macro::set;
use map_macro::hash_set;
use wag_core::StickPosition;

use super::*;
Expand All @@ -266,7 +266,7 @@ mod test {
let motion: MotionInput = "6f".into();

let diff = Diff {
pressed: Some(set! {GameButton::Fast}),
pressed: Some(hash_set! {GameButton::Fast}),
..default()
};

Expand Down
3 changes: 2 additions & 1 deletion client/integration_tests/src/test_helpers/app_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl AppWrapper {
let players = self.world().resource::<Players>();
let p1 = players.one;
let p2 = players.two;
drop(players);
// TODO: Migration to bevy 0.11.2 broke this
// drop(players);
(p1, p2)
}

Expand Down
33 changes: 20 additions & 13 deletions client/integration_tests/src/test_helpers/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{
};

use bevy::{
app::ScheduleRunnerSettings, asset::AssetPlugin, input::InputPlugin, prelude::*,
app::{RunMode, ScheduleRunnerPlugin},
asset::AssetPlugin,
input::InputPlugin,
prelude::*,
render::RenderPlugin,
};

Expand Down Expand Up @@ -39,18 +42,21 @@ impl TestRunner {
/// Setup the game env for a test case
fn setup(&self, spec: TestSpec) -> App {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.insert_resource(ScheduleRunnerSettings {
run_mode: bevy::app::RunMode::Loop { wait: None },
});
app.add_plugin(AssetPlugin::default());
app.add_plugin(WindowPlugin::default());
app.add_plugin(InputPlugin::default());
app.add_plugin(RenderPlugin::default());
app.add_plugin(ImagePlugin::default());
app.add_plugins(MinimalPlugins.build().disable::<ScheduleRunnerPlugin>());

app.add_plugins(WAGLib::integration().build());
app.add_system(parse_input::<PreWrittenStream>);
app.add_plugins((
ScheduleRunnerPlugin {
run_mode: RunMode::Loop { wait: None },
},
AssetPlugin::default(),
WindowPlugin::default(),
InputPlugin::default(),
RenderPlugin::default(),
ImagePlugin::default(),
WAGLib::integration().build(),
));

app.add_systems(Update, parse_input::<PreWrittenStream>);
app.update();

// Go to combat
Expand All @@ -62,7 +68,8 @@ impl TestRunner {
let players = app.world.resource::<Players>();
let p1 = players.one;
let p2 = players.two;
drop(players); // Needs to drop because couldn't figure out how to get the Players resource without by value.
// TODO: Migration to bevy 0.11.2 broke this
// drop(players); // Needs to drop because couldn't figure out how to get the Players resource without by value.

app.world.entity_mut(p1).insert(spec.p1_bundle);
app.world.entity_mut(p2).insert(spec.p2_bundle);
Expand Down
4 changes: 3 additions & 1 deletion client/lib/src/assets/animations/animation_helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::take;

use bevy::{prelude::*, scene::SceneInstance};

use wag_core::{Animation, Facing};
Expand Down Expand Up @@ -82,7 +84,7 @@ fn find_animation_player_entity(
let mut next_candidates: Vec<Entity> = candidates.iter().map(|e| e.to_owned()).collect();
let mut scene_root = None;
while !next_candidates.is_empty() {
for candidate in next_candidates.drain(..).collect::<Vec<Entity>>() {
for candidate in take(&mut next_candidates) {
if players.get(candidate).is_ok() {
return (Some(candidate), scene_root);
} else if let Ok(new) = children.get(candidate) {
Expand Down
54 changes: 29 additions & 25 deletions client/lib/src/assets/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,36 @@ fn particle_explosion(
amount: f32,
) -> Entity {
let spawner = Spawner::once(amount.into(), false);
let mut module = Module::default();

let position_modifier = SetPositionSphereModifier {
dimension: ShapeDimension::Surface,
radius: module.lit(0.2),
center: module.lit(Vec3::ZERO),
};

let velocity_modifier = SetVelocitySphereModifier {
center: module.lit(Vec3::ZERO),
speed: module.lit(speed),
};

let lifetime = SetAttributeModifier::new(Attribute::LIFETIME, module.lit(1.0));

let gravity = AccelModifier::new(module.lit(Vec3::new(0.0, -2.0, 0.0)));

let effect = effects.add(
EffectAsset {
name: name.into(),
capacity: 1000,
spawner,
..default()
}
.init(InitPositionSphereModifier {
dimension: ShapeDimension::Surface,
radius: 0.2,
..default()
})
.init(InitVelocitySphereModifier {
center: Vec3::ZERO,
speed: speed.into(),
})
.init(InitLifetimeModifier {
lifetime: Value::Single(1.0),
})
.update(AccelModifier::constant(Vec3::new(0.0, -2.0, 0.0)))
.render(ColorOverLifetimeModifier {
gradient: color_gradient,
})
.render(SizeOverLifetimeModifier {
gradient: size_gradient,
}),
EffectAsset::new(1000, spawner, module)
.init(position_modifier)
.init(velocity_modifier)
.init(lifetime)
.update(gravity)
.render(ColorOverLifetimeModifier {
gradient: color_gradient,
})
.render(SizeOverLifetimeModifier {
gradient: size_gradient,
..default()
}),
);

commands
Expand Down
25 changes: 14 additions & 11 deletions client/lib/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub struct AssetsPlugin;

impl Plugin for AssetsPlugin {
fn build(&self, app: &mut App) {
app.add_startup_systems(
app.add_systems(
PreStartup,
(
loaders::colors,
loaders::fonts,
Expand All @@ -48,16 +49,18 @@ impl Plugin for AssetsPlugin {
loaders::animations,
loaders::sounds,
loaders::particles,
)
.in_base_set(StartupSet::PreStartup),
),
)
.add_systems((
animations::setup_helpers,
animations::update_animation,
animations::mirror_after_load,
models::find_joints,
sounds::play_queued,
particles::handle_requests,
));
.add_systems(
Update,
(
animations::setup_helpers,
animations::update_animation,
animations::mirror_after_load,
models::find_joints,
sounds::play_queued,
particles::handle_requests,
),
);
}
}
8 changes: 4 additions & 4 deletions client/lib/src/assets/particles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use bevy_hanabi::ParticleEffect;
use bevy_hanabi::EffectSpawner;
use std::collections::HashMap;

use wag_core::VisualEffect;
Expand Down Expand Up @@ -33,16 +33,16 @@ impl Particles {
}

pub fn handle_requests(
mut transforms: Query<(&mut ParticleEffect, &mut Transform)>,
mut transforms: Query<(&mut EffectSpawner, &mut Transform)>,
mut particles: ResMut<Particles>,
) {
for ParticleRequest { effect, position } in
particles.queue.drain(..).collect::<Vec<_>>().into_iter()
{
let emitter = particles.get(effect);
if let Ok((mut effect, mut tf)) = transforms.get_mut(emitter) {
if let Ok((mut spawner, mut tf)) = transforms.get_mut(emitter) {
tf.translation = position;
effect.maybe_spawner().unwrap().reset();
spawner.reset();
}
}
}
14 changes: 6 additions & 8 deletions client/lib/src/assets/sounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ impl Sounds {
}
}

pub fn play_queued(mut sounds: ResMut<Sounds>, audio: Option<Res<Audio>>) {
// audio is not present in unit tests
// This way the sound system behaves the same despite this.
let clips = sounds.queue.drain(..);
if let Some(player) = audio {
for clip in clips {
player.play(clip);
}
pub fn play_queued(mut commands: Commands, mut sounds: ResMut<Sounds>) {
for source in sounds.queue.drain(..) {
commands.spawn(AudioBundle {
source,
..default()
});
}
}

Expand Down
Loading

0 comments on commit d752628

Please sign in to comment.