From 2d0a5c0381dc7452f7e841ece98bee2d4a65ed2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Lescaudey=20de=20Maneville?= Date: Wed, 21 Feb 2024 20:29:04 +0100 Subject: [PATCH] Bevy 0.13 (#149) Blocked on: * [x] https://github.com/mvlabat/bevy_egui/pull/236 * [x] https://github.com/jakobhellermann/bevy-inspector-egui/pull/185 --- .github/workflows/rust.yml | 2 +- CHANGELOG.md | 4 ++++ Cargo.toml | 11 +++++------ README.md | 20 ++++++++++++-------- examples/3d_columns.rs | 23 +++++++++++++---------- examples/a_star.rs | 23 +++++++++++++---------- examples/chunks.rs | 17 ++++++++++------- examples/field_of_movement.rs | 23 +++++++++++++---------- examples/field_of_view.rs | 23 +++++++++++++---------- examples/hex_grid.rs | 29 ++++++++++++++++------------- examples/merged_columns.rs | 27 +++++++++++++-------------- examples/mesh_builder.rs | 21 ++++++++++++--------- examples/scroll_map.rs | 17 ++++++++++------- examples/sprite_sheet.rs | 31 ++++++++++++++----------------- examples/wrap_map.rs | 19 +++++++++++-------- src/hex/mod.rs | 2 +- src/lib.rs | 20 ++++++++++++-------- 17 files changed, 173 insertions(+), 139 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e9121b8..c87edf3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,7 +66,7 @@ jobs: matrix: version: - stable - - 1.72.1 # MSRV + # - 1.74.1 # MSRV runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index c35fcb1..175c21c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +* Bumped `bevy`, `bevy_egui` and `bevy_inspector_egui` dev dependencies +* Bumped `glam` to 0.25 +* Dropped MSRV + ## 0.14.0 * Defined MSRV to be 1.72.1 (#145) diff --git a/Cargo.toml b/Cargo.toml index 0344572..b724c36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ categories = ["game-development", "mathematics"] repository = "https://github.com/ManevilleF/hexx" exclude = [".github"] resolver = "2" -rust-version = "1.72.1" [features] default = ["algorithms", "mesh"] @@ -28,7 +27,7 @@ ser_de = ["serde"] bevy_reflect = ["dep:bevy_reflect"] [dependencies] -glam = "0.24" +glam = "0.25" [dependencies.serde] version = "1" @@ -37,14 +36,14 @@ features = ["derive"] optional = true [dependencies.bevy_reflect] -version = "0.12" +version = "0.13" default-features = false features = ["glam"] optional = true # For lib.rs doctests and examples [dev-dependencies.bevy] -version = "0.12" +version = "0.13" features = [ "bevy_asset", "bevy_winit", @@ -69,8 +68,8 @@ features = ["html_reports"] [dev-dependencies] rand = "0.8" -bevy-inspector-egui = "0.22" -bevy_egui = "0.24" +bevy-inspector-egui = "0.23" +bevy_egui = "0.25" [[example]] name = "hex_grid" diff --git a/README.md b/README.md index 33bbf16..a053bd2 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ ## Installation - > Minimum supported rust version (MSRV) is `1.72.1` - Run `cargo add hexx` in your project or add the following line to your `Cargo.toml`: @@ -207,16 +205,22 @@ ```rust use bevy::{ prelude::Mesh, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{ + mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology, + }, }; use hexx::MeshInfo; pub fn hexagonal_plane(mesh_info: MeshInfo) -> Mesh { - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + // Means you won't edit the mesh afterwards, check bevy docs for more information + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } ``` diff --git a/examples/3d_columns.rs b/examples/3d_columns.rs index f927184..85bebdc 100644 --- a/examples/3d_columns.rs +++ b/examples/3d_columns.rs @@ -1,6 +1,6 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, time::common_conditions::on_timer, }; use hexx::{shapes, *}; @@ -18,7 +18,7 @@ const TIME_STEP: Duration = Duration::from_millis(100); pub fn main() { App::new() .insert_resource(AmbientLight { - brightness: 0.1, + brightness: 200.0, ..default() }) .add_plugins(DefaultPlugins) @@ -47,6 +47,7 @@ fn setup_camera(mut commands: Commands) { transform, ..default() }); + let transform = Transform::from_xyz(60.0, 60.0, 00.0).looking_at(Vec3::ZERO, Vec3::Y); commands.spawn(DirectionalLightBundle { transform, ..default() @@ -64,8 +65,8 @@ fn setup_grid( ..default() }; // materials - let default_material = materials.add(Color::WHITE.into()); - let highlighted_material = materials.add(Color::YELLOW.into()); + let default_material = materials.add(Color::WHITE); + let highlighted_material = materials.add(Color::YELLOW); // mesh let mesh = hexagonal_column(&layout); let mesh_handle = meshes.add(mesh); @@ -123,12 +124,14 @@ fn animate_rings( fn hexagonal_column(hex_layout: &HexLayout) -> Mesh { let mesh_info = ColumnMeshBuilder::new(hex_layout, COLUMN_HEIGHT) .without_bottom_face() - .with_scale(Vec3::splat(0.9)) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/a_star.rs b/examples/a_star.rs index 61ec4cc..be9bcef 100644 --- a/examples/a_star.rs +++ b/examples/a_star.rs @@ -1,7 +1,7 @@ use bevy::{ log, prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, utils::{HashMap, HashSet}, window::PrimaryWindow, }; @@ -51,9 +51,9 @@ fn setup_grid( ..default() }; let mesh = meshes.add(hexagonal_plane(&layout)); - let default_mat = materials.add(Color::WHITE.into()); - let blocked_mat = materials.add(Color::BLACK.into()); - let path_mat = materials.add(Color::CYAN.into()); + let default_mat = materials.add(Color::WHITE); + let blocked_mat = materials.add(Color::BLACK); + let path_mat = materials.add(Color::CYAN); let mut blocked_coords = HashSet::new(); let entities = Hex::ZERO .spiral_range(0..=MAP_RADIUS) @@ -92,7 +92,7 @@ fn setup_grid( /// Input interaction fn handle_input( mut commands: Commands, - buttons: Res>, + buttons: Res>, windows: Query<&Window, With>, cameras: Query<(&Camera, &GlobalTransform)>, mut current: Local, @@ -156,9 +156,12 @@ fn hexagonal_plane(hex_layout: &HexLayout) -> Mesh { .with_scale(Vec3::splat(0.9)) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/chunks.rs b/examples/chunks.rs index 141c109..75a09dc 100644 --- a/examples/chunks.rs +++ b/examples/chunks.rs @@ -1,6 +1,6 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, }; use hexx::{shapes, *}; @@ -38,7 +38,7 @@ fn setup_grid( ..default() }; // materials - let materials = COLORS.map(|c| materials.add(c.into())); + let materials = COLORS.map(|c| materials.add(c)); // mesh let mesh = hexagonal_plane(&layout); let mesh_handle = meshes.add(mesh); @@ -63,9 +63,12 @@ fn hexagonal_plane(hex_layout: &HexLayout) -> Mesh { .facing(Vec3::Z) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/field_of_movement.rs b/examples/field_of_movement.rs index 09f5298..c50e0a2 100644 --- a/examples/field_of_movement.rs +++ b/examples/field_of_movement.rs @@ -1,6 +1,6 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, utils::{HashMap, HashSet}, window::PrimaryWindow, }; @@ -90,10 +90,10 @@ fn setup_grid( ..default() }; let mesh = meshes.add(hexagonal_plane(&layout)); - let plains_mat = materials.add(Color::WHITE.into()); - let forest_mat = materials.add(Color::GREEN.into()); - let desert_mat = materials.add(Color::YELLOW.into()); - let wall_mat = materials.add(Color::DARK_GRAY.into()); + let plains_mat = materials.add(Color::WHITE); + let forest_mat = materials.add(Color::GREEN); + let desert_mat = materials.add(Color::YELLOW); + let wall_mat = materials.add(Color::DARK_GRAY); let mut rng = rand::thread_rng(); @@ -139,9 +139,12 @@ fn hexagonal_plane(hex_layout: &HexLayout) -> Mesh { .facing(Vec3::Z) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/field_of_view.rs b/examples/field_of_view.rs index 392cfb1..e768397 100644 --- a/examples/field_of_view.rs +++ b/examples/field_of_view.rs @@ -1,6 +1,6 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, utils::{HashMap, HashSet}, window::PrimaryWindow, }; @@ -51,9 +51,9 @@ fn setup_grid( ..default() }; let mesh = meshes.add(hexagonal_plane(&layout)); - let default_mat = materials.add(Color::WHITE.into()); - let blocked_mat = materials.add(Color::BLACK.into()); - let visible_mat = materials.add(Color::CYAN.into()); + let default_mat = materials.add(Color::WHITE); + let blocked_mat = materials.add(Color::BLACK); + let visible_mat = materials.add(Color::CYAN); let mut blocked_coords = HashSet::new(); let entities = Hex::ZERO .spiral_range(0..=MAP_RADIUS) @@ -91,7 +91,7 @@ fn setup_grid( /// Input interaction fn handle_input( mut commands: Commands, - buttons: Res>, + buttons: Res>, windows: Query<&Window, With>, cameras: Query<(&Camera, &GlobalTransform)>, mut current: Local, @@ -146,9 +146,12 @@ fn hexagonal_plane(hex_layout: &HexLayout) -> Mesh { .with_scale(Vec3::splat(0.9)) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/hex_grid.rs b/examples/hex_grid.rs index f4e91a0..dd6a15a 100644 --- a/examples/hex_grid.rs +++ b/examples/hex_grid.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, window::PrimaryWindow, }; use hexx::{shapes, *}; @@ -65,13 +65,13 @@ fn setup_grid( ..default() }; // materials - let selected_material = materials.add(Color::RED.into()); - let ring_material = materials.add(Color::YELLOW.into()); - let wedge_material = materials.add(Color::CYAN.into()); - let dir_wedge_material = materials.add(Color::VIOLET.into()); - let line_material = materials.add(Color::ORANGE.into()); - let half_ring_material = materials.add(Color::LIME_GREEN.into()); - let default_material = materials.add(Color::WHITE.into()); + let selected_material = materials.add(Color::RED); + let ring_material = materials.add(Color::YELLOW); + let wedge_material = materials.add(Color::CYAN); + let dir_wedge_material = materials.add(Color::VIOLET); + let line_material = materials.add(Color::ORANGE); + let half_ring_material = materials.add(Color::LIME_GREEN); + let default_material = materials.add(Color::WHITE); // mesh let mesh = hexagonal_plane(&layout); let mesh_handle = meshes.add(mesh); @@ -204,9 +204,12 @@ fn hexagonal_plane(hex_layout: &HexLayout) -> Mesh { .with_scale(Vec3::splat(0.95)) .center_aligned() .build(); - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } diff --git a/examples/merged_columns.rs b/examples/merged_columns.rs index cc14263..1730082 100644 --- a/examples/merged_columns.rs +++ b/examples/merged_columns.rs @@ -2,12 +2,9 @@ use std::ops::Range; use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, -}; -use bevy_inspector_egui::{ - quick::{ResourceInspectorPlugin, WorldInspectorPlugin}, - InspectorOptions, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, }; +use bevy_inspector_egui::{quick::ResourceInspectorPlugin, InspectorOptions}; use hexx::*; use rand::{thread_rng, Rng}; @@ -20,12 +17,11 @@ pub fn main() { .register_type::>() .init_resource::() .insert_resource(AmbientLight { - brightness: 1., + brightness: 500., ..default() }) .add_plugins(DefaultPlugins) .add_plugins(ResourceInspectorPlugin::::default()) - .add_plugins(WorldInspectorPlugin::default()) .add_systems(Startup, setup_camera) .add_systems(Update, setup_grid) .run(); @@ -45,7 +41,7 @@ struct MapSettings { #[derive(Debug, Resource)] struct Map(pub Entity); -/// 3D Orthogrpahic camera setup +/// 3D camera setup fn setup_camera(mut commands: Commands) { let transform = Transform::from_xyz(0.0, 60.0, 60.0).looking_at(Vec3::ZERO, Vec3::Y); commands.spawn(Camera3dBundle { @@ -75,7 +71,7 @@ fn setup_grid( }; // Materials shouldn't be added to assets every time, this is just to keep the // example simple - let materials = COLORS.map(|c| materials.add(c.into())); + let materials = COLORS.map(|c| materials.add(c)); let map_entity = commands .spawn((SpatialBundle::default(), Name::new("Chunks"))) @@ -125,11 +121,14 @@ fn setup_grid( /// Compute a bevy mesh from a hexx mesh fn hex_mesh(mesh_info: MeshInfo) -> Mesh { - Mesh::new(PrimitiveTopology::TriangleList) - .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) - .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) - .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) - .with_indices(Some(Indices::U16(mesh_info.indices))) + Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::RENDER_WORLD, + ) + .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices) + .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals) + .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs) + .with_inserted_indices(Indices::U16(mesh_info.indices)) } impl Default for MapSettings { diff --git a/examples/mesh_builder.rs b/examples/mesh_builder.rs index f17b3db..fa65d09 100644 --- a/examples/mesh_builder.rs +++ b/examples/mesh_builder.rs @@ -2,7 +2,7 @@ use bevy::{ input::mouse::MouseMotion, pbr::wireframe::{Wireframe, WireframePlugin}, prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, }; use bevy_egui::{egui, EguiContext, EguiPlugin}; use bevy_inspector_egui::bevy_inspector; @@ -47,7 +47,7 @@ pub fn main() { App::new() .init_resource::() .insert_resource(AmbientLight { - brightness: 0.3, + brightness: 500.0, ..default() }) .add_plugins(DefaultPlugins) @@ -140,7 +140,7 @@ fn setup( .with_offset(Vec3::NEG_Y * params.height / 2.0) .build(); let mesh_handle = meshes.add(compute_mesh(mesh)); - let material = materials.add(texture.into()); + let material = materials.add(texture); let mesh_entity = commands .spawn(( PbrBundle { @@ -162,7 +162,7 @@ fn animate( info: Res, mut transforms: Query<&mut Transform>, mut motion_evr: EventReader, - buttons: Res>, + buttons: Res>, time: Res