Skip to content

Commit

Permalink
Update to bevy v0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
mattzque committed Mar 19, 2024
1 parent a15ea9a commit e219f1c
Show file tree
Hide file tree
Showing 17 changed files with 1,047 additions and 571 deletions.
1,462 changes: 975 additions & 487 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ opt-level = 1
opt-level = 3

[dependencies]
bevy = { version = "0.12.1", features = ["animation", "jpeg"] }
bevy = { version = "0.13.1", features = ["animation", "jpeg"] }
anyhow = "1.0"
thiserror = "1.0"
serde = "1.0"
serde_json = "1.0"
rand = "0.8"
bevy_egui = "0.23"
bevy_prototype_lyon = "0.10"
bevy_egui = "0.26"
bevy_prototype_lyon = "0.11"

# cargo build / cargo build --release --no-default-features
[features]
Expand Down
4 changes: 1 addition & 3 deletions src/game/assets/icons.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::TypeUuid,
utils::BoxedFuture,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -36,8 +35,7 @@ pub struct IconSheet {
pub tiles: Vec<Icon>,
}

#[derive(Asset, Debug, TypeUuid, TypePath)]
#[uuid = "bb63465d-326f-47b6-8c49-008128f3e863"]
#[derive(Asset, Debug, TypePath)]
pub struct IconSheetAsset(pub Vec<IconSheet>);

#[derive(Default)]
Expand Down
4 changes: 2 additions & 2 deletions src/game/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashSet;

use bevy::asset::RecursiveDependencyLoadState;
use bevy::prelude::*;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::render::render_resource::{Extent3d, TextureDimension, TextureFormat};
use bevy::render::texture::{ImageFilterMode, ImageSampler, ImageSamplerDescriptor};

Expand Down Expand Up @@ -157,8 +158,7 @@ fn assets_loaded_system(
TextureDimension::D2,
data,
TextureFormat::Rgba8UnormSrgb,
// TextureFormat::Rgba8Unorm,
// TextureFormat::// Rgba8UnormSrgb,
RenderAssetUsages::RENDER_WORLD, // unload / only loaded in render world
);
texture_array.sampler = ImageSampler::Descriptor(ImageSamplerDescriptor {
mag_filter: ImageFilterMode::Nearest,
Expand Down
18 changes: 11 additions & 7 deletions src/game/audio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::audio::VolumeLevel;
use bevy::prelude::*;
use bevy::{audio::PlaybackMode, audio::Volume};

Expand Down Expand Up @@ -51,7 +50,7 @@ impl Plugin for AudioPlugin {
);
app.add_systems(
Update,
update_sound_volume.run_if(resource_changed::<AudioSettingsResource>()),
update_sound_volume.run_if(resource_changed::<AudioSettingsResource>),
);
app.add_systems(Update, update_music_playback_system);
}
Expand All @@ -75,10 +74,11 @@ fn init_music_playback_system(
source: resource.music.first().unwrap().clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume::Absolute(VolumeLevel::new(audio_settings.music_volume())),
volume: Volume::new(audio_settings.music_volume()),
speed: 1.0,
paused: false,
spatial: false,
..Default::default()
},
},
MusicPlayer(0),
Expand Down Expand Up @@ -145,10 +145,11 @@ fn play_sound_effects_system(
source: resource.shoot.clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume::Absolute(VolumeLevel::new(audio_settings.effects_volume())),
volume: Volume::new(audio_settings.effects_volume()),
speed: 1.0,
paused: false,
spatial: false,
..Default::default()
},
},
SoundEffectTag,
Expand All @@ -161,10 +162,11 @@ fn play_sound_effects_system(
source: resource.hit.clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume::Absolute(VolumeLevel::new(audio_settings.effects_volume())),
volume: Volume::new(audio_settings.effects_volume()),
speed: 1.0,
paused: false,
spatial: false,
..Default::default()
},
},
SoundEffectTag,
Expand All @@ -177,10 +179,11 @@ fn play_sound_effects_system(
source: resource.capture.clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume::Absolute(VolumeLevel::new(audio_settings.effects_volume())),
volume: Volume::new(audio_settings.effects_volume()),
speed: 1.0,
paused: false,
spatial: false,
..Default::default()
},
},
SoundEffectTag,
Expand All @@ -193,10 +196,11 @@ fn play_sound_effects_system(
source: resource.damage.clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume::Absolute(VolumeLevel::new(audio_settings.effects_volume())),
volume: Volume::new(audio_settings.effects_volume()),
speed: 1.0,
paused: false,
spatial: false,
..Default::default()
},
},
SoundEffectTag,
Expand Down
5 changes: 1 addition & 4 deletions src/game/camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::core_pipeline::clear_color::ClearColorConfig;
use bevy::input::mouse::MouseWheel;
use bevy::prelude::*;
use bevy::render::view::RenderLayers;
Expand Down Expand Up @@ -58,12 +57,10 @@ fn setup_cameras(mut commands: Commands) {

commands.spawn((
Camera2dBundle {
camera_2d: Camera2d {
clear_color: ClearColorConfig::None, // ::Custom(Color::rgba(0.0, 0.0, 0.0, 0.0)),
},
camera: Camera {
order: 1,
is_active: true,
clear_color: ClearColorConfig::None,
..Default::default()
},
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions src/game/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl Plugin for DebugPlugin {
}
}

pub fn toggle_debug(keys: Res<Input<KeyCode>>, mut show_debug: ResMut<ShowDebug>) {
if keys.just_pressed(KeyCode::O) {
pub fn toggle_debug(keys: Res<ButtonInput<KeyCode>>, mut show_debug: ResMut<ShowDebug>) {
if keys.just_pressed(KeyCode::KeyO) {
show_debug.show = !show_debug.show;
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/game/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Command for ScoreScreen {
world.resource_scope::<FontResource, ()>(|world, resource| {
world.resource_scope::<DiagnosticsStore, ()>(|world, diagnostics| {
let mut contents = format!("Score: {}", self.score_line()); // \nFPS: {:.2}", self.score_line(), diagn);
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(fps) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FPS) {
if let Some(value) = fps.smoothed() {
contents.push_str(&format!("\n{:.2} FPS", value));
}
Expand Down Expand Up @@ -388,6 +388,9 @@ impl Command for TitleScreen {
height: Val::Vh(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
position_type: PositionType::Absolute,
top: Val::Px(0.0),
left: Val::Px(0.0),
..Default::default()
},
background_color: Color::hex("#12141844").unwrap().into(), // Color::rgba(1.0, 0.0, 0.0, 0.1).into(),
Expand Down Expand Up @@ -462,7 +465,7 @@ impl Command for TitleScreen {
color: Color::hex("#adbacb").unwrap(),
},
)
.with_text_alignment(TextAlignment::Center),
.with_text_justify(JustifyText::Center),
RenderLayers::layer(CAMERA_LAYER_UI),
));
});
Expand Down Expand Up @@ -645,7 +648,7 @@ impl Command for GameOverScreen {
color: Color::hex("#adbacb").unwrap(),
},
)
.with_text_alignment(TextAlignment::Center),
.with_text_justify(JustifyText::Center),
RenderLayers::layer(CAMERA_LAYER_UI),
));
});
Expand Down Expand Up @@ -886,7 +889,7 @@ fn show_icon_follower_added_system(
}

fn toggle_game_pause_system(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
current_state: Res<State<GameState>>,
mut state: ResMut<NextState<GameState>>,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/game/icons/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ fn spawn_projectile_system(
mut commands: Commands,
player: Query<&IconTransform, With<IconPlayerController>>,
followers: Res<IconFollowers>,
keys: Res<Input<KeyCode>>,
mouse_button_input: Res<Input<MouseButton>>,
keys: Res<ButtonInput<KeyCode>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
settings: Res<SettingsResource>,
boundaries: Res<WorldBoundaryResource>,
time: Res<Time>,
Expand Down
10 changes: 5 additions & 5 deletions src/game/icons/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn update_player_rotation(
fn update_key_input(
time: Res<Time>,
mut query: Query<(Entity, &mut IconTransform, &mut IconVelocity), With<IconPlayerController>>,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
settings: Res<SettingsResource>,
) {
let dt = time.delta_seconds();
Expand Down Expand Up @@ -82,19 +82,19 @@ fn update_key_input(
let strafe_vector = Vec2::new(rotation.cos(), rotation.sin());

let mut accel = Vec2::ZERO;
if keys.any_pressed([KeyCode::Up, KeyCode::W]) {
if keys.any_pressed([KeyCode::ArrowUp, KeyCode::KeyW]) {
// forward
accel += forward_vector * -1.0;
}
if keys.any_pressed([KeyCode::Down, KeyCode::S]) {
if keys.any_pressed([KeyCode::ArrowDown, KeyCode::KeyS]) {
// backward
accel += forward_vector * 1.0;
}
if keys.any_pressed([KeyCode::Left, KeyCode::A]) {
if keys.any_pressed([KeyCode::ArrowLeft, KeyCode::KeyA]) {
// strafe left
accel += strafe_vector * -1.0;
}
if keys.any_pressed([KeyCode::Right, KeyCode::D]) {
if keys.any_pressed([KeyCode::ArrowRight, KeyCode::KeyD]) {
// strafe right
accel += strafe_vector * 1.0;
}
Expand Down
6 changes: 2 additions & 4 deletions src/game/icons/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::prelude::*;
use bevy::render::batching::NoAutomaticBatching;
use bevy::render::mesh::shape;
use bevy::render::view::{NoFrustumCulling, RenderLayers};
use bevy::sprite::Mesh2dHandle;
use rand::prelude::*;
Expand Down Expand Up @@ -216,9 +215,8 @@ fn init_icons_system(

// info!("Spawned {} icons", count);

let mesh = Mesh::from(shape::Quad {
size: Vec2::splat(ICON_SIZE),
flip: false,
let mesh = Mesh::from(Rectangle {
half_size: Vec2::splat(ICON_SIZE / 2.0),
});
let mesh_handle = meshes.add(mesh);
commands.spawn((
Expand Down
32 changes: 16 additions & 16 deletions src/game/icons/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use bevy::core_pipeline::core_2d::Transparent2d;
use bevy::ecs::query::QueryItem;
use bevy::ecs::query::ROQueryItem;
use bevy::ecs::system::lifetimeless::SRes;
use bevy::ecs::system::lifetimeless::*;
use bevy::ecs::system::SystemParamItem;
use bevy::prelude::*;
Expand Down Expand Up @@ -34,11 +32,11 @@ pub struct GpuIconInstanceData {
}

impl ExtractComponent for IconInstanceData {
type Query = &'static IconInstanceData;
type Filter = ();
type QueryData = &'static IconInstanceData;
type QueryFilter = ();
type Out = GpuIconInstanceData;

fn extract_component(item: QueryItem<'_, Self::Query>) -> Option<GpuIconInstanceData> {
fn extract_component(item: QueryItem<'_, Self::QueryData>) -> Option<GpuIconInstanceData> {
Some(GpuIconInstanceData {
data: item.instances_data(),
n_instances: item.n_instances as usize,
Expand Down Expand Up @@ -233,11 +231,10 @@ impl FromWorld for CustomPipeline {
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
};
let texture_bind_group_layout =
render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
entries: &[texture_uniform_layout_entry, texture_sampler_layout_entry],
label: Some("icons_texture_array"),
});
let texture_bind_group_layout = render_device.create_bind_group_layout(
Some("icons_texture_array"),
&[texture_uniform_layout_entry, texture_sampler_layout_entry],
);

CustomPipeline {
shader,
Expand Down Expand Up @@ -310,14 +307,14 @@ type DrawCustom = (
pub struct SetTextureBindGroup<const I: usize>;
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetTextureBindGroup<I> {
type Param = SRes<TextureBindGroup>;
type ViewWorldQuery = ();
type ItemWorldQuery = ();
type ViewQuery = ();
type ItemQuery = ();

#[inline]
fn render<'w>(
_item: &P,
_view: (),
_item_query: ROQueryItem<'w, Self::ItemWorldQuery>,
_instance_buffer: Option<()>,
texture_bind_group: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
Expand All @@ -333,14 +330,14 @@ pub struct DrawMesh2dInstanced;

impl<P: PhaseItem> RenderCommand<P> for DrawMesh2dInstanced {
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMesh2dInstances>);
type ViewWorldQuery = ();
type ItemWorldQuery = Read<InstanceBuffer>;
type ViewQuery = ();
type ItemQuery = Read<InstanceBuffer>;

#[inline]
fn render<'w>(
item: &P,
_view: (),
instance_buffer: &'w InstanceBuffer,
instance_buffer: Option<&'w InstanceBuffer>,
(meshes, render_mesh2d_instances): SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
Expand All @@ -355,6 +352,9 @@ impl<P: PhaseItem> RenderCommand<P> for DrawMesh2dInstanced {
let Some(gpu_mesh) = meshes.get(*mesh_asset_id) else {
return RenderCommandResult::Failure;
};
let Some(instance_buffer) = instance_buffer else {
return RenderCommandResult::Failure;
};

pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
pass.set_vertex_buffer(1, instance_buffer.buffer.slice(..));
Expand Down
2 changes: 1 addition & 1 deletion src/game/icons/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct IconSheetResource {
}

#[derive(Resource)]
pub struct SpatialIndexResource(pub SpatialIndex<Entity>);
pub struct SpatialIndexResource(pub SpatialIndex);

#[derive(Resource, Default)]
pub struct HoveredIcon(pub Option<Entity>);
2 changes: 1 addition & 1 deletion src/game/icons/roaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn get_icon_velocity(
position: &Vec2,
rotation: &f32,
velocity: &Vec2,
spatial_index: &SpatialIndex<Entity>,
spatial_index: &SpatialIndex,
settings: &SettingsResource,
boundaries: &WorldBoundaryResource,
target_position: &Vec2,
Expand Down
Loading

0 comments on commit e219f1c

Please sign in to comment.