Skip to content

Commit

Permalink
Update to Bevy 0.14
Browse files Browse the repository at this point in the history
Doing this in the UI branch because there are some 0.15 features that
will be very useful for UI.

There are still some lighting issues, but since I'm about to update to 0
.15 anyway, I'll fix them after that in case any more lighting changes
happen then.
  • Loading branch information
Waridley committed Dec 5, 2024
1 parent 6e01365 commit 050bcd3
Show file tree
Hide file tree
Showing 36 changed files with 1,825 additions and 771 deletions.
2,155 changes: 1,576 additions & 579 deletions rs/Cargo.lock

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ default = [
]

[workspace.dependencies.bevy]
version = "0.13.1"
version = "0.14.2"
default-features = false
features = [
# "asset_processor", # only on desktop
Expand All @@ -37,7 +37,7 @@ features = [
"bevy_sprite",
"bevy_text",
# "bevy_ui", # Will be making my own game UI
"multi-threaded",
"multi_threaded",
"png",
"hdr",
"ktx2",
Expand All @@ -50,8 +50,12 @@ features = [
"tonemapping_luts",
# "default_font", # For editor, but probably not in-game
"webgl2", # Needed so it doesn't default to WebGPU
"bevy_state",
]

[workspace.dependencies.bevy_asset]
features = ["multi_threaded"]

[workspace.dependencies]
# Mine
engine = { package = "sond-has-engine", path = "engine" }
Expand All @@ -61,18 +65,18 @@ macros = { package = "sond-has-macros", path = "engine/macros" }

# Engine
bevy_dylib = "0.13.0"
bevy_rapier3d = { version = "0.25.0", default-features = false, features = ["dim3"] }
rapier3d = { version = "*", features = ["wasm-bindgen", "serde-serialize"] }
bevy_kira_audio = "0.19.0"
leafwing-input-manager = "0.13.0"
bevy_rapier3d = { version = "0.27.0", default-features = false, features = ["dim3"] }
rapier3d = { version = "0.21.0", features = ["wasm-bindgen", "serde-serialize"] }
bevy_kira_audio = "0.20.0"
leafwing-input-manager = "0.14.0"
bevy_quickmenu = "0.2.0"
bevy_common_assets = { version = "0.10.0", features = ["ron"] }

# Util
ab_glyph = "0.2.26"
array-init = "2.1.0"
base64 = "0.21.7"
bevy_pkv = "0.10.0" # settings
bevy_pkv = "0.11.0" # settings
bevy_svg = { version = "0.13.0", path = "../vend/bevy_svg" }
bytemuck = "1.14.1" # mostly for seeds
crossbeam = "0.8.2"
Expand All @@ -90,12 +94,13 @@ rand_xorshift = "0.3.0"
ron = "0.8.1"
static_assertions = "1.1.0"
serde = "1"
smallvec = "*" # same as bevy
smol_str = "0.2.1"
web-time = "1.0.0"

# Debugging/Editor
bevy-inspector-egui = "0.23"
egui_plot = "0.26.2"
bevy-inspector-egui = "0.27.0"
egui_plot = "0.29.0"

# Testing
linkme = "0.3.22"
Expand All @@ -119,6 +124,7 @@ nanorand = { workspace = true }
rand = { workspace = true }
rand_xorshift = { workspace = true }
serde = { workspace = true }
smallvec = { workspace = true }
web-time = { workspace = true }

# Debugging
Expand Down
12 changes: 6 additions & 6 deletions rs/assets/globals.scn.ron
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
minor_resolution: 3,
),
antigrav_pulse_mat: (
base_color: Rgba( red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 ),
emissive: Rgba( red: 0.0, green: 120.0, blue: 72.0, alpha: 1.0 ),
base_color: LinearRgba(( red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 )),
emissive: ( red: 0.0, green: 120.0, blue: 72.0, alpha: 1.0 ),
reflectance: 0.0,
),
arm_particle_radius: 0.1,
Expand All @@ -41,16 +41,16 @@
subdivisions: 2,
),
arm_mats: (
Rgba( red: 0.0, green: 60.0, blue: 0.0, alpha: 1.0 ),
Rgba( red: 30.0, green: 30.0, blue: 30.0, alpha: 1.0 ),
Rgba( red: 0.0, green: 60.0, blue: 60.0, alpha: 1.0 ),
( red: 0.0, green: 60.0, blue: 0.0, alpha: 1.0 ),
( red: 30.0, green: 30.0, blue: 30.0, alpha: 1.0 ),
( red: 0.0, green: 60.0, blue: 60.0, alpha: 1.0 ),
),
crosshair_mesh: (
major_radius: 0.5,
minor_radius: 0.1,
),
crosshair_mat: (
base_color: Rgba( red: 1.0, green: 1.0, blue: 0.0, alpha: 1.0 ),
base_color: LinearRgba(( red: 1.0, green: 1.0, blue: 0.0, alpha: 1.0 )),
depth_bias: inf,
unlit: true,
),
Expand Down
2 changes: 1 addition & 1 deletion rs/assets/pickups/pickup_material.mat.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ExtendedMaterial(
extension: BubbleMaterial(
glow_color: Rgba ( red: 4.0, green: 1.0, blue: 0.0, alpha: 0.12 ),
glow_color: ( red: 4.0, green: 1.0, blue: 0.0, alpha: 0.12 ),
),
base: ExtendedMaterial( extension: (), base: StandardMaterial(
specular_transmission: 1.0,
Expand Down
4 changes: 2 additions & 2 deletions rs/assets/shaders/skybox.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

struct SkyCube {
face_index: u32,
face_width: f32,
face_width: u32,
face_rotation: mat3x3<f32>,
rotation: mat3x3<f32>,
time_of_day: f32,
Expand All @@ -15,7 +15,7 @@ struct SkyCube {
@group(0) @binding(2) var<uniform> globals: Globals;

fn ray_dir(position: vec2<f32>) -> vec3<f32> {
return cube.face_rotation * normalize(vec3((position / (cube.face_width * 0.5)) - vec2(1.0), 1.0));
return cube.face_rotation * normalize(vec3((position / (f32(cube.face_width) * 0.5)) - vec2(1.0), 1.0));
}

struct VertexOutput {
Expand Down
2 changes: 1 addition & 1 deletion rs/assets/shaders/terrain.mat.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ExtendedMaterial(
extension: ( near_start: 0.0 ),
base: StandardMaterial(
base_color: Rgba ( red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0),
base_color: LinearRgba(( red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0 )),
reflectance: 0.3,
perceptual_roughness: 0.0,
),
Expand Down
1 change: 1 addition & 0 deletions rs/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ordered-float = { workspace = true }
rand = { workspace = true }
ron = { workspace = true }
serde = { workspace = true }
smallvec = { workspace = true }
smol_str = { workspace = true }
web-time = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions rs/engine/src/anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl<T: Component> ComponentDelta<T> {

pub type DynApply<T> = dyn FnOnce(Mut<T>, f32) + Send + Sync + 'static;

#[derive(Component)]
pub struct Delta<T> {
/// Current progress the animation has made. Return a finite number if progress can
/// be determined and the animation should be blended. Any non-finite number, such
Expand Down
28 changes: 19 additions & 9 deletions rs/engine/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::{
},
};
use std::f32::consts::{FRAC_PI_2, PI, TAU};
use bevy::utils::smallvec::{smallvec, SmallVec};
use smallvec::{smallvec, SmallVec};

/// The corners of a square with dimensions [1.0, 1.0], centered around the origin.
#[inline]
Expand Down Expand Up @@ -84,7 +84,7 @@ pub struct PlanarPolyLine {
/// Also, if any inner `Vec` is empty, the last color from the previous one will be used.
/// If the outer `Vec` is shorter than `points`, the last color will also be repeated for
/// all remaining vertices.
pub colors: SmallVec<[SmallVec<[Color; 1]>; 2]>,
pub colors: SmallVec<[SmallVec<[LinearRgba; 1]>; 2]>,
/// If `true`, the last point will be connected to the first, closing the shape.
///
/// Defaults to `true`.
Expand Down Expand Up @@ -114,8 +114,8 @@ impl FromIterator<Vec2> for PlanarPolyLine {

/// Construct a `PlanarPolyLine` with a square cross-section and a single
/// color at each corner.
impl FromIterator<(Vec2, Color)> for PlanarPolyLine {
fn from_iter<T: IntoIterator<Item = (Vec2, Color)>>(iter: T) -> Self {
impl FromIterator<(Vec2, LinearRgba)> for PlanarPolyLine {
fn from_iter<T: IntoIterator<Item = (Vec2, LinearRgba)>>(iter: T) -> Self {
let (points, colors) = iter
.into_iter()
.map(|(point, color)| (point, smallvec![color]))
Expand All @@ -129,9 +129,10 @@ impl FromIterator<(Vec2, Color)> for PlanarPolyLine {
}

impl Meshable for PlanarPolyLine {
type Output = Mesh;
type Output = PlanarPolylineMeshBuilder;

fn mesh(&self) -> Self::Output {
// FIXME: Move this impl to `PlanarPolylineMeshBuilder::build
fn point_to_3d(p: Vec2) -> Vec3 {
Vec3::new(p.x, 0.0, p.y)
}
Expand All @@ -143,7 +144,7 @@ impl Meshable for PlanarPolyLine {
Vec::new()
};
let mut normals = Vec::with_capacity(verts.len());
let mut color = Color::BLACK.as_rgba_f32();
let mut color = Color::BLACK.to_linear().to_f32_array();
let mut colors = self.colors.iter();
if !self.closed {
for (b, c) in
Expand Down Expand Up @@ -175,7 +176,7 @@ impl Meshable for PlanarPolyLine {
verts.push(vert);
normals.push(normal);
if let Some(new_color) = colors.next() {
color = new_color.as_rgba_f32();
color = new_color.to_f32_array();
}
if self.colors.len() > 0 {
vert_colors.push(color);
Expand Down Expand Up @@ -217,13 +218,13 @@ impl Meshable for PlanarPolyLine {
if self.colors.len() > 0 {
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, vert_colors);
}
mesh
PlanarPolylineMeshBuilder(mesh)
}
}

impl From<PlanarPolyLine> for Mesh {
fn from(value: PlanarPolyLine) -> Self {
value.mesh()
value.mesh().build()
}
}

Expand All @@ -246,3 +247,12 @@ impl PlanarPolyLine {
}
}
}

pub struct PlanarPolylineMeshBuilder(Mesh);

impl MeshBuilder for PlanarPolylineMeshBuilder {
fn build(&self) -> Mesh {
// FIXME: Should move `mesh` impl here instead
self.0.clone()
}
}
1 change: 1 addition & 0 deletions rs/engine/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bevy::{
ButtonState,
},
prelude::*,
state::state::States,
utils::HashMap,
};
use leafwing_input_manager::{buttonlike::MouseMotionDirection, prelude::*};
Expand Down
16 changes: 9 additions & 7 deletions rs/engine/src/input/map/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use crate::{
};
use bevy::{
prelude::*,
utils::{smallvec::SmallVec, HashMap},
utils::HashMap,
};
use bevy::utils::smallvec::smallvec;
use bevy::color::palettes::css::AQUAMARINE;
use smallvec::{smallvec, SmallVec};
use bevy_svg::prelude::Origin;

pub struct DetectBindingPopupPlugin;
Expand Down Expand Up @@ -87,14 +88,15 @@ pub fn setup(
meshes.add(
PlanarPolyLine {
colors: smallvec![
smallvec![Color::rgba(0.0, 0.2, 0.2, 0.6)],
smallvec![Color::rgba(0.0, 0.4, 0.1, 0.6)],
smallvec![Color::rgba(0.0, 0.2, 0.2, 0.6)],
smallvec![Color::rgba(0.0, 0.1, 0.4, 0.6)],
smallvec![LinearRgba::new(0.0, 0.2, 0.2, 0.6)],
smallvec![LinearRgba::new(0.0, 0.4, 0.1, 0.6)],
smallvec![LinearRgba::new(0.0, 0.2, 0.2, 0.6)],
smallvec![LinearRgba::new(0.0, 0.1, 0.4, 0.6)],
],
..PlanarPolyLine::rect(8.0, 6.0, 0.25)
}
.mesh()
.build()
.with_duplicated_vertices()
.with_computed_flat_normals(),
),
Expand All @@ -121,7 +123,7 @@ pub fn setup(
extension: default(),
base: Matter {
extension: DistanceDither::ui(),
base: Color::AQUAMARINE.into(),
base: Color::from(AQUAMARINE).into(),
},
}),
transform: Transform {
Expand Down
4 changes: 2 additions & 2 deletions rs/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl Plugin for EnginePlugin {
fn build(&self, app: &mut App) {
app.add_plugins((ui::UiPlugin, input::InputPlugin, SvgPlugin));
DEBUG_COMPONENTS
.set(app.world.register_system(debug_component_names))
.set(app.world_mut().register_system(debug_component_names))
.expect("`DEBUG_COMPONENTS` shouldn't already be set");
ERROR_COMPONENTS
.set(app.world.register_system(error_component_names))
.set(app.world_mut().register_system(error_component_names))
.expect("`ERROR_COMPONENTS` shouldn't already be set");
}
}
9 changes: 5 additions & 4 deletions rs/engine/src/mats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::{
prelude::*,
render::render_resource::{AsBindGroup, ShaderRef},
};
use bevy::color::palettes::basic::GRAY;
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -28,7 +29,7 @@ pub struct MatsPlugin;
impl Plugin for MatsPlugin {
fn build(&self, app: &mut App) {
Box::leak(Box::new(
app.world
app.world()
.resource::<AssetServer>()
.load::<Shader>("shaders/util.wgsl"),
));
Expand All @@ -40,7 +41,7 @@ impl Plugin for MatsPlugin {
MaterialPlugin::<ExtMat<DitherFade>>::default(),
));

let registry = app.world.get_resource::<AppTypeRegistry>().unwrap().clone();
let registry = app.world().get_resource::<AppTypeRegistry>().unwrap().clone();
{
let mut reg = registry.write();
reg.register::<BubbleMaterial>();
Expand All @@ -57,13 +58,13 @@ impl Plugin for MatsPlugin {
#[reflect(Default)]
pub struct BubbleMaterial {
#[uniform(200)]
pub glow_color: Color,
pub glow_color: LinearRgba,
}

impl Default for BubbleMaterial {
fn default() -> Self {
Self {
glow_color: Color::GRAY,
glow_color: GRAY.into(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions rs/engine/src/mats/fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Plugin for MatterPlugin {
))
.add_systems(Update, (update_matter_globals,));

let registry = app.world.get_resource::<AppTypeRegistry>().unwrap().clone();
let registry = app.world().get_resource::<AppTypeRegistry>().unwrap().clone();
{
let mut reg = registry.write();
reg.register::<DistanceDither>();
Expand All @@ -53,7 +53,7 @@ impl Plugin for MatterPlugin {
}

fn finish(&self, app: &mut App) {
let mut assets = app.world.resource_mut::<Assets<Image>>();
let mut assets = app.world_mut().resource_mut::<Assets<Image>>();

let image = Image::from_buffer(
include_bytes!("bayer16.png").as_ref(),
Expand All @@ -78,7 +78,7 @@ impl Plugin for MatterPlugin {
)
.unwrap();

assets.insert(BAYER_HANDLE, image);
assets.insert(BAYER_HANDLE.id(), image);
}
}

Expand Down
Loading

0 comments on commit 050bcd3

Please sign in to comment.