Skip to content

Commit

Permalink
Upgrade to Bevy 0.13 and add outlines (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett authored May 16, 2024
1 parent bbfce93 commit cecdf62
Show file tree
Hide file tree
Showing 14 changed files with 1,483 additions and 1,261 deletions.
2,231 changes: 1,139 additions & 1,092 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ inspector = ["bevy-inspector-egui"]
debugdump = ["bevy_mod_debugdump"]

[dependencies]
bevy = "0.12"
bevy_rapier3d = { version = "0.23", features = ["debug-render-3d"] }
bevy_dolly = { version = "0.0.2" }
bevy_asset_loader = "0.18.0"
bevy-inspector-egui = { version = "0.21", optional = true }
leafwing-input-manager = "0.11"
bevy-ui-navigation = "0.33.0"
bevy_mod_debugdump = { version = "0.9.0", optional = true }
bevy_pipelines_ready = "0.2.0"

bevy-tnua = "0.13.0"
bevy-tnua-physics-integration-layer = "0.1.0"
bevy-tnua-rapier3d = "0.1.0"
bevy = "0.13"
bevy_rapier3d = { version = "0.25", features = ["debug-render-3d"] }
bevy_dolly = { version = "0.0.3" }
bevy_asset_loader = "0.20.0"
bevy-inspector-egui = { version = "0.23", optional = true }
leafwing-input-manager = "0.13"
# BLOCKED due to cuicui sub-dep
bevy-alt-ui-navigation-lite = { git = "https://github.com/rparrett/bevy-alt-ui-navigation-lite/" }
bevy_mod_debugdump = { version = "0.10", optional = true }
bevy_pipelines_ready = "0.3.0"
bevy_two_entities = { git = "https://github.com/rparrett/bevy_two_entities/" }
bevy-tnua = "0.15.0"
bevy-tnua-physics-integration-layer = "0.2.0"
bevy-tnua-rapier3d = "0.3.0"

rand = "0.8.5"
serde = "*"
ron = "0.8.0"
bevy_mod_outline = "0.7.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "*", features = ["console", "Window", "Storage"] }
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ All other assets are original creations by me for this project.
- make LastTile a small FIFO in case the user places a tower on their own tile and then falls
- add loading bar for assets and pipelines
- upgrade towers by feeding them a tower kit?
- use `bevy_mod_outline` to highlight
- where object will be placed (tower -> tile, or ammo -> tower)
- which object will be picked up
8 changes: 1 addition & 7 deletions assets/shaders/starfield.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
#import bevy_render::instance_index::get_instance_index

struct StarfieldMaterial {
pos: vec2<f32>,
_wasm_padding: vec2<f32>,
};

@group(1) @binding(0)
@group(2) @binding(0)
var<uniform> material: StarfieldMaterial;


Expand Down Expand Up @@ -73,11 +72,6 @@ fn fragment(
finalColor = finalColor + (starfield(starfield_coords, threshold) * layer_brightness);
}

// Hack: this ensures the push constant is always used, which works around this issue:
// https://github.com/bevyengine/bevy/issues/10509
// This can be probably be removed after Bevy 0.13 is released.
finalColor.x += min(f32(get_instance_index(0u)), 0.0);

let fragColor = vec4<f32>(finalColor, 1.0);

return fragColor;
Expand Down
4 changes: 2 additions & 2 deletions src/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ fn movement(
} else {
commands.spawn(AudioBundle {
source: game_audio.damage.clone(),
settings: PlaybackSettings::ONCE
.with_volume(Volume::new_absolute(**audio_setting as f32 / 100.)),
settings: PlaybackSettings::DESPAWN
.with_volume(Volume::new(**audio_setting as f32 / 100.)),
});

lives.0 = lives.0.saturating_sub(1);
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::Fonts,
Expand Down
36 changes: 26 additions & 10 deletions src/loading.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
use bevy_asset_loader::prelude::*;
use bevy_mod_outline::{OutlineBundle, OutlineVolume};
use bevy_pipelines_ready::{PipelinesReady, PipelinesReadyPlugin};

use crate::GameState;
Expand Down Expand Up @@ -64,23 +65,27 @@ pub struct Images {
}

#[cfg(not(target_arch = "wasm32"))]
const EXPECTED_PIPELINES: usize = 15;
const EXPECTED_PIPELINES: usize = 22;
#[cfg(target_arch = "wasm32")]
const EXPECTED_PIPELINES: usize = 13;
const EXPECTED_PIPELINES: usize = 20;

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::Pipelines),
LoadingState::new(GameState::Loading)
.load_collection::<Models>()
.load_collection::<Fonts>()
.load_collection::<Images>()
.load_collection::<Sounds>()
.continue_to_state(GameState::Pipelines),
)
.add_collection_to_loading_state::<_, Models>(GameState::Loading)
.add_collection_to_loading_state::<_, Fonts>(GameState::Loading)
.add_collection_to_loading_state::<_, Images>(GameState::Loading)
.add_collection_to_loading_state::<_, Sounds>(GameState::Loading)
.add_systems(
Update,
pipelines_done.run_if(in_state(GameState::Pipelines)),
(
pipelines_print.run_if(resource_changed::<PipelinesReady>),
pipelines_done.run_if(in_state(GameState::Pipelines)),
),
)
.add_systems(OnExit(GameState::Pipelines), cleanup)
.add_systems(OnEnter(GameState::Pipelines), setup_pipelines);
Expand Down Expand Up @@ -118,10 +123,19 @@ fn setup_pipelines(
commands.spawn((
PipelinesMarker,
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.25 })),
mesh: meshes.add(Mesh::from(Cuboid::new(0.25, 0.25, 0.25))),
material: path_mat.clone(),
..default()
},
// Make sure this gets outlined so that outline pipelines are created
OutlineBundle {
outline: OutlineVolume {
width: 1.,
colour: Color::WHITE,
visible: true,
},
..default()
},
));

commands.spawn((
Expand All @@ -144,9 +158,11 @@ fn setup_pipelines(
));
}

fn pipelines_done(ready: Res<PipelinesReady>, mut next_state: ResMut<NextState<GameState>>) {
fn pipelines_print(ready: Res<PipelinesReady>) {
info!("Pipelines Ready: {}/{}", ready.get(), EXPECTED_PIPELINES);
}

fn pipelines_done(ready: Res<PipelinesReady>, mut next_state: ResMut<NextState<GameState>>) {
if ready.get() >= EXPECTED_PIPELINES {
next_state.set(GameState::MainMenu);
}
Expand Down
Loading

0 comments on commit cecdf62

Please sign in to comment.