Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to Bevy 0.14 #4

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bevy_examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ exclude = ["assets/"]
[dependencies]
# ----- Internal dependencies
bevy_ghx_proc_gen = { path = "../bevy_ghx_proc_gen", default-features = true }
bevy_ghx_utils = { version = "0.3.0", default-features = true }
bevy_ghx_utils = { version = "0.4", default-features = true }

# ----- External dependencies
tracing-subscriber = "0.3.18"
rand = "0.8.5"
bevy = { version = "0.13.0", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
# Default features:

"multi-threaded", # Run with multithreading
"multi_threaded", # Run with multithreading
"bevy_asset", # Assets management
"bevy_scene", # Scenes management
"bevy_render", # Rendering framework core
Expand All @@ -43,7 +43,7 @@ bevy = { version = "0.13.0", default-features = false, features = [
# Development/Debug features:
"dynamic_linking", # Dynamic linking for faster compile-times
] }
bevy_mod_picking = { version = "0.18.0", default-features = false, features = [
bevy_mod_picking = { version = "0.20.0", default-features = false, features = [
"backend_raycast",
"backend_bevy_ui",
"backend_sprite",
Expand Down
45 changes: 28 additions & 17 deletions bevy_examples/canyon/canyon.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use std::f32::consts::PI;

use bevy::{log::LogPlugin, pbr::DirectionalLightShadowMap, prelude::*};
use bevy::{
color::palettes::css::{GRAY, ORANGE_RED},
log::LogPlugin,
pbr::DirectionalLightShadowMap,
prelude::*,
};

use bevy_examples::{
anim::SpawningScaleAnimation, plugin::ProcGenExamplesPlugin, utils::load_assets,
};
use bevy_ghx_proc_gen::{
bevy_ghx_grid::{
debug_plugin::{view::DebugGridView, DebugGridView3dBundle},
ghx_grid::{coordinate_system::Cartesian3D, grid::GridDefinition},
ghx_grid::{cartesian::{coordinates::Cartesian3D, grid::CartesianGrid}, grid::GridData},
},
gen::{
assets::AssetSpawner,
Expand All @@ -20,7 +25,7 @@ use bevy_ghx_proc_gen::{
},
GeneratorBundle,
};
use bevy_ghx_utils::camera::{update_pan_orbit_camera, PanOrbitCamera};
use bevy_ghx_utils::camera::{update_pan_orbit_camera, PanOrbitCameraBundle, PanOrbitState};

use rand::Rng;
use rules::{CustomComponents, RotationRandomizer, ScaleRandomizer, WindRotation};
Expand Down Expand Up @@ -56,28 +61,29 @@ fn setup_scene(mut commands: Commands) {
let camera_position = Vec3::new(0., 1.5 * GRID_HEIGHT as f32, 1.5 * GRID_Z as f32 / 2.);
let look_target = Vec3::new(0., -10., 0.);
let radius = (look_target - camera_position).length();
commands.spawn((
Camera3dBundle {
commands.spawn((PanOrbitCameraBundle {
camera: Camera3dBundle {
transform: Transform::from_translation(camera_position)
.looking_at(look_target, Vec3::Y),
..default()
},
PanOrbitCamera {
state: PanOrbitState {
radius,
..Default::default()
..default()
},
));
..Default::default()
},));

// Scene lights
commands.insert_resource(AmbientLight {
color: Color::ORANGE_RED,
color: ORANGE_RED.into(),
brightness: 0.05,
});
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: true,
illuminance: 4000.,
color: Color::rgb(1.0, 0.85, 0.65),
color: Color::srgb(1.0, 0.85, 0.65).into(),
..default()
},
transform: Transform {
Expand All @@ -91,7 +97,7 @@ fn setup_scene(mut commands: Commands) {
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 2000.,
color: Color::ORANGE_RED,
color: ORANGE_RED.into(),
..default()
},
transform: Transform {
Expand All @@ -118,9 +124,13 @@ fn setup_generator(mut commands: Commands, asset_server: Res<AssetServer>) {
let rules = RulesBuilder::new_cartesian_3d(models, socket_collection)
.build()
.unwrap();
let grid = GridDefinition::new_cartesian_3d(GRID_X, GRID_HEIGHT, GRID_Z, false, false, false);
let grid = CartesianGrid::new_cartesian_3d(GRID_X, GRID_HEIGHT, GRID_Z, false, false, false);

let grid_size = (grid.size_xy() * grid.size_z()) as usize;

let mut initial_constraints = grid.new_grid_data(None);

//let mut initial_constraints = grid.new_grid_data(None);
let mut initial_constraints: GridData<Cartesian3D, _, CartesianGrid<Cartesian3D>> = GridData::new(grid.clone(), vec![None; grid_size]);
// Force void nodes on the upmost layer
let void_ref = Some(void_instance);
initial_constraints.set_all_y(GRID_HEIGHT - 1, void_ref);
Expand All @@ -137,17 +147,18 @@ fn setup_generator(mut commands: Commands, asset_server: Res<AssetServer>) {
initial_constraints.set_all_yz(0, GRID_Z - 1, sand_ref);
// Let's force a small lake at the center
let water_ref = Some(water_instance);
for x in 2 * GRID_X / 5..3 * GRID_X / 5 {
// TODO! Fix this code
/*for x in 2 * GRID_X / 5..3 * GRID_X / 5 {
for z in 2 * GRID_Z / 5..3 * GRID_Z / 5 {
initial_constraints.set((x, 0, z), water_ref);
initial_constraints.set((x as usize, 0 as usize, z as usize), water_ref);
}
}
// We could hope for a water bridge, or force one !
initial_constraints.set(
(GRID_X / 2, GRID_HEIGHT / 2, GRID_Z / 2),
Some(bridge_instance),
);

*/
let mut gen_builder = GeneratorBuilder::new()
.with_rules(rules)
.with_grid(grid.clone())
Expand Down Expand Up @@ -187,7 +198,7 @@ fn setup_generator(mut commands: Commands, asset_server: Res<AssetServer>) {
},
observer,
DebugGridView3dBundle {
view: DebugGridView::new(false, true, Color::GRAY, NODE_SIZE),
view: DebugGridView::new(false, true, GRAY.into(), NODE_SIZE),
..default()
},
));
Expand Down
2 changes: 1 addition & 1 deletion bevy_examples/canyon/rules.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{ecs::component::Component, math::Vec3};
use bevy_examples::utils::AssetDef;
use bevy_ghx_proc_gen::{
bevy_ghx_grid::ghx_grid::{coordinate_system::Cartesian3D, direction::GridDelta},
bevy_ghx_grid::ghx_grid::cartesian::coordinates::{Cartesian3D, GridDelta},
gen::assets::ComponentSpawner,
proc_gen::generator::{
model::{ModelCollection, ModelInstance, ModelRotation},
Expand Down
10 changes: 4 additions & 6 deletions bevy_examples/chessboard/chessboard.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use bevy::prelude::*;

use bevy_ghx_proc_gen::{
bevy_ghx_grid::ghx_grid::{
coordinate_system::Cartesian2D,
grid::{GridDefinition, GridPosition},
},
bevy_ghx_grid::ghx_grid::cartesian::{coordinates::Cartesian2D, grid::CartesianGrid},
gen::{
assets::{AssetSpawner, RulesModelsAssets},
default_bundles::PbrMesh,
Expand Down Expand Up @@ -65,14 +62,15 @@ fn setup_generator(
.unwrap();

// Like a chess board, let's do an 8x8 2d grid
let grid = GridDefinition::new_cartesian_2d(8, 8, false, false);
let grid = CartesianGrid::new_cartesian_2d(8, 8, false, false);
let initial_nodes = vec![(grid.index_from_coords(0, 0, 0), black_model)];

// There many more parameters you can tweak on a Generator before building it, explore the API.
let generator = GeneratorBuilder::new()
.with_rules(rules)
.with_grid(grid.clone())
// Let's ensure that we make a chessboard, with a black square bottom-left
.with_initial_nodes(vec![(GridPosition::new_xy(0, 0), black_model)])
.with_initial_nodes(initial_nodes)
.unwrap()
.build()
.unwrap();
Expand Down
40 changes: 24 additions & 16 deletions bevy_examples/pillars/pillars.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use std::{f32::consts::PI, sync::Arc};

use bevy::{log::LogPlugin, pbr::DirectionalLightShadowMap, prelude::*};
use bevy::{
color::palettes::{basic::GRAY, css::ORANGE_RED},
log::LogPlugin,
pbr::DirectionalLightShadowMap,
prelude::*,
};

use bevy_examples::{plugin::ProcGenExamplesPlugin, utils::load_assets};

use bevy_ghx_proc_gen::{
bevy_ghx_grid::{
debug_plugin::{view::DebugGridView, DebugGridView3dBundle},
ghx_grid::{coordinate_system::Cartesian3D, grid::GridDefinition},
ghx_grid::cartesian::{coordinates::Cartesian3D, grid::CartesianGrid},
},
gen::{
assets::{AssetSpawner, RulesModelsAssets},
Expand All @@ -16,7 +21,7 @@ use bevy_ghx_proc_gen::{
proc_gen::generator::{builder::GeneratorBuilder, rules::RulesBuilder},
GeneratorBundle,
};
use bevy_ghx_utils::camera::{update_pan_orbit_camera, PanOrbitCamera};
use bevy_ghx_utils::camera::{update_pan_orbit_camera, PanOrbitCameraBundle, PanOrbitState};

use crate::rules::rules_and_assets;

Expand Down Expand Up @@ -48,16 +53,19 @@ fn setup_scene(
let camera_position = Vec3::new(0., 3. * GRID_HEIGHT as f32, 0.75 * GRID_Z as f32);
let radius = camera_position.length();
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(camera_position).looking_at(Vec3::ZERO, Vec3::Y),
PanOrbitCameraBundle {
camera: Camera3dBundle {
transform: Transform::from_translation(camera_position).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
state: PanOrbitState {
radius,
..default()
},
..default()
},
PanOrbitCamera {
radius,
..Default::default()
},
FogSettings {
color: Color::rgba(0.2, 0.15, 0.1, 1.0),
color: Color::srgba(0.2, 0.15, 0.1, 1.0).into(),
falloff: FogFalloff::Linear {
start: 55.0,
end: 145.0,
Expand All @@ -69,7 +77,7 @@ fn setup_scene(
PbrBundle {
mesh: meshes.add(Mesh::from(Plane3d::default())),
material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(),
base_color: Color::srgb_u8(136, 136, 136).into(),
..default()
}),
transform: Transform::from_scale(Vec3::splat(10000.0)).with_translation(Vec3::new(
Expand All @@ -84,14 +92,14 @@ fn setup_scene(

// Scene lights
commands.insert_resource(AmbientLight {
color: Color::ORANGE_RED,
color: ORANGE_RED.into(),
brightness: 0.05,
});
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: true,
illuminance: 3000.,
color: Color::rgb(1.0, 0.85, 0.65),
color: Color::srgb(1.0, 0.85, 0.65).into(),
..default()
},
transform: Transform {
Expand All @@ -105,7 +113,7 @@ fn setup_scene(
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 1250.,
color: Color::rgb(1.0, 0.85, 0.65),
color: Color::srgb(1.0, 0.85, 0.65).into(),
..default()
},
transform: Transform {
Expand All @@ -126,7 +134,7 @@ fn setup_generator(mut commands: Commands, asset_server: Res<AssetServer>) {
.build()
.unwrap(),
);
let grid = GridDefinition::new_cartesian_3d(GRID_X, GRID_HEIGHT, GRID_Z, false, false, false);
let grid = CartesianGrid::new_cartesian_3d(GRID_X, GRID_HEIGHT, GRID_Z, false, false, false);
let gen_builder = GeneratorBuilder::new()
// We share the Rules between all the generators
.with_shared_rules(rules.clone())
Expand Down Expand Up @@ -160,7 +168,7 @@ fn setup_generator(mut commands: Commands, asset_server: Res<AssetServer>) {
},
observer,
DebugGridView3dBundle {
view: DebugGridView::new(false, true, Color::GRAY, NODE_SIZE),
view: DebugGridView::new(false, true, GRAY.into(), NODE_SIZE),
..default()
},
Name::new(format!("Grid_{}", i)),
Expand Down
2 changes: 1 addition & 1 deletion bevy_examples/pillars/rules.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_examples::utils::AssetDef;
use bevy_ghx_proc_gen::{
bevy_ghx_grid::ghx_grid::coordinate_system::Cartesian3D,
bevy_ghx_grid::ghx_grid::cartesian::coordinates::Cartesian3D,
proc_gen::generator::{
model::ModelCollection,
socket::{SocketCollection, SocketsCartesian3D},
Expand Down
23 changes: 14 additions & 9 deletions bevy_examples/src/fps.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use bevy::{
app::{App, Plugin, Startup, Update},
color::{
palettes::basic::{BLACK, WHITE},
Color,
},
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
ecs::{
component::Component,
query::With,
system::{Commands, Query, Res},
},
hierarchy::BuildChildren,
render::{color::Color, view::Visibility},
prelude::Alpha,
render::view::Visibility,
text::{Text, TextSection, TextStyle},
ui::{
node_bundles::{NodeBundle, TextBundle},
Expand Down Expand Up @@ -45,7 +50,7 @@ pub fn setup_fps_counter(mut commands: Commands) {
FpsRoot,
NodeBundle {
// give it a dark background for readability
background_color: BackgroundColor(Color::BLACK.with_a(0.5)),
background_color: BackgroundColor(BLACK.with_alpha(0.5).into()),
// make it "always on top" by setting the Z index to maximum
// we want it to be displayed over all other UI
z_index: ZIndex::Global(i32::MAX),
Expand Down Expand Up @@ -79,7 +84,7 @@ pub fn setup_fps_counter(mut commands: Commands) {
value: "FPS: ".into(),
style: TextStyle {
font_size: DEFAULT_EXAMPLES_FONT_SIZE,
color: Color::WHITE,
color: WHITE.into(),
// if you want to use your game's font asset,
// uncomment this and provide the handle:
// font: my_font_handle
Expand All @@ -90,7 +95,7 @@ pub fn setup_fps_counter(mut commands: Commands) {
value: " N/A".into(),
style: TextStyle {
font_size: DEFAULT_EXAMPLES_FONT_SIZE,
color: Color::WHITE,
color: WHITE.into(),
// if you want to use your game's font asset,
// uncomment this and provide the handle:
// font: my_font_handle
Expand Down Expand Up @@ -124,22 +129,22 @@ pub fn fps_text_update_system(
// text according to the FPS value:
text.sections[1].style.color = if value >= 120.0 {
// Above 120 FPS, use green color
Color::rgb(0.0, 1.0, 0.0)
Color::srgb(0.0, 1.0, 0.0)
} else if value >= 60.0 {
// Between 60-120 FPS, gradually transition from yellow to green
Color::rgb((1.0 - (value - 60.0) / (120.0 - 60.0)) as f32, 1.0, 0.0)
Color::srgb((1.0 - (value - 60.0) / (120.0 - 60.0)) as f32, 1.0, 0.0)
} else if value >= 30.0 {
// Between 30-60 FPS, gradually transition from red to yellow
Color::rgb(1.0, ((value - 30.0) / (60.0 - 30.0)) as f32, 0.0)
Color::srgb(1.0, ((value - 30.0) / (60.0 - 30.0)) as f32, 0.0)
} else {
// Below 30 FPS, use red color
Color::rgb(1.0, 0.0, 0.0)
Color::srgb(1.0, 0.0, 0.0)
}
} else {
// display "N/A" if we can't get a FPS measurement
// add an extra space to preserve alignment
text.sections[1].value = " N/A".into();
text.sections[1].style.color = Color::WHITE;
text.sections[1].style.color = WHITE.into();
}
}
}
Loading