From 792672c2ef0a4d8b31c554b6f07ef49a0f4fd754 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Tue, 13 Aug 2024 02:03:40 +0200 Subject: [PATCH] chore(Bevy side): making clippy happy + started cleaning up demo code (non functional at this point) --- crates/blenvy/src/blueprints/animation.rs | 2 +- crates/blenvy/src/blueprints/assets.rs | 11 +- crates/blenvy/src/blueprints/hot_reload.rs | 47 ++++---- crates/blenvy/src/blueprints/materials.rs | 20 ++-- crates/blenvy/src/blueprints/mod.rs | 8 +- .../src/blueprints/spawn_from_blueprints.rs | 5 +- .../components/blender_settings/lighting.rs | 2 - crates/blenvy/src/save_load/loading.rs | 2 +- crates/blenvy/src/save_load/mod.rs | 4 +- crates/blenvy/src/save_load/saving.rs | 2 +- examples/animation/src/main.rs | 20 ++-- examples/demo/Cargo.toml | 4 +- examples/demo/src/game/in_game.rs | 83 -------------- examples/demo/src/game/in_main_menu.rs | 107 ----------------- examples/demo/src/game/level_transitions.rs | 4 - examples/demo/src/game/mod.rs | 19 +-- examples/demo/src/main.rs | 62 +++++++++- examples/demo/src/test_components.rs | 4 +- examples/save_load/src/main.rs | 6 +- testing/bevy_example/src/game/animation.rs | 108 +++--------------- testing/bevy_example/src/game/in_game.rs | 22 +--- testing/bevy_example/src/game/mod.rs | 19 ++- testing/bevy_example/src/hierarchy_debug.rs | 48 ++++---- testing/bevy_example/src/state.rs | 4 +- 24 files changed, 174 insertions(+), 439 deletions(-) delete mode 100644 examples/demo/src/game/in_game.rs delete mode 100644 examples/demo/src/game/in_main_menu.rs diff --git a/crates/blenvy/src/blueprints/animation.rs b/crates/blenvy/src/blueprints/animation.rs index 2e1d2e4..bf10a8c 100644 --- a/crates/blenvy/src/blueprints/animation.rs +++ b/crates/blenvy/src/blueprints/animation.rs @@ -191,7 +191,7 @@ pub fn trigger_instance_animation_markers_events( animations.named_animations.get(animation_name) { if let Some(__animation_clip) = animation_clips.get(animation_clip_handle) { - println!("helooo") + println!("found the animation clip"); } } } diff --git a/crates/blenvy/src/blueprints/assets.rs b/crates/blenvy/src/blueprints/assets.rs index 7f5ec3f..193b053 100644 --- a/crates/blenvy/src/blueprints/assets.rs +++ b/crates/blenvy/src/blueprints/assets.rs @@ -59,21 +59,12 @@ pub struct AssetLoadTracker { } /// helper component, for tracking loaded assets -#[derive(Component, Debug)] +#[derive(Component, Default, Debug)] pub(crate) struct BlueprintAssetsLoadState { pub all_loaded: bool, pub asset_infos: Vec, pub progress: f32, } -impl Default for BlueprintAssetsLoadState { - fn default() -> Self { - Self { - all_loaded: Default::default(), - asset_infos: Default::default(), - progress: Default::default(), - } - } -} // for preloading asset files #[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)] diff --git a/crates/blenvy/src/blueprints/hot_reload.rs b/crates/blenvy/src/blueprints/hot_reload.rs index 737eec8..550a3f9 100644 --- a/crates/blenvy/src/blueprints/hot_reload.rs +++ b/crates/blenvy/src/blueprints/hot_reload.rs @@ -14,6 +14,7 @@ pub(crate) struct AssetToBlueprintInstancesMapper { pub(crate) untyped_id_to_blueprint_entity_ids: HashMap>, } +#[allow(clippy::too_many_arguments)] pub(crate) fn react_to_asset_changes( mut gltf_events: EventReader>, // FIXME: Problem: we need to react to any asset change, not just gltf files ! // mut untyped_events: EventReader>, @@ -30,34 +31,32 @@ pub(crate) fn react_to_asset_changes( for event in gltf_events.read() { // LoadedUntypedAsset - match event { - AssetEvent::Modified { id } => { - // React to the gltf file being modified - // println!("Modified gltf {:?}", asset_server.get_path(*id)); - if let Some(asset_path) = asset_server.get_path(*id) { - // let untyped = asset_server.get_handle_untyped(asset_path.clone()); - // println!("matching untyped handle {:?}", untyped); - // let bla = untyped.unwrap().id(); - // asset_server.get - // in order to avoid respawn both a parent & a child , which would crash Bevy, we do things in two steps - if let Some(entities) = assets_to_blueprint_instances - .untyped_id_to_blueprint_entity_ids - .get(&asset_path.to_string()) - { - for entity in entities.iter() { - // println!("matching blueprint instance {}", entity); - // disregard entities that are already (re) spawning - if !respawn_candidates.contains(&entity) - && blueprint_assets.get(*entity).is_ok() - && spawning_blueprints.get(*entity).is_err() - { - respawn_candidates.push(entity); - } + + if let AssetEvent::Modified { id } = event { + // React to the gltf file being modified + // println!("Modified gltf {:?}", asset_server.get_path(*id)); + if let Some(asset_path) = asset_server.get_path(*id) { + // let untyped = asset_server.get_handle_untyped(asset_path.clone()); + // println!("matching untyped handle {:?}", untyped); + // let bla = untyped.unwrap().id(); + // asset_server.get + // in order to avoid respawn both a parent & a child , which would crash Bevy, we do things in two steps + if let Some(entities) = assets_to_blueprint_instances + .untyped_id_to_blueprint_entity_ids + .get(&asset_path.to_string()) + { + for entity in entities.iter() { + // println!("matching blueprint instance {}", entity); + // disregard entities that are already (re) spawning + if !respawn_candidates.contains(&entity) + && blueprint_assets.get(*entity).is_ok() + && spawning_blueprints.get(*entity).is_err() + { + respawn_candidates.push(entity); } } } } - _ => {} } } // we process all candidates here to deal with the case where multiple assets have changed in a single frame, which could cause respawn chaos diff --git a/crates/blenvy/src/blueprints/materials.rs b/crates/blenvy/src/blueprints/materials.rs index b2950c9..3117cfe 100644 --- a/crates/blenvy/src/blueprints/materials.rs +++ b/crates/blenvy/src/blueprints/materials.rs @@ -11,13 +11,13 @@ pub struct MaterialInfo { #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] -/// component containing the full list of MaterialInfos for a given entity/object +/// component containing the full list of `MaterialInfos` for a given entity/object pub struct MaterialInfos(Vec); #[derive(Component, Default, Debug)] pub struct MaterialProcessed; -/// system that injects / replaces materials from material library +/// system that injects / replaces materials from materials library pub(crate) fn inject_materials( mut blenvy_config: ResMut, material_infos_query: Query< @@ -88,16 +88,14 @@ pub(crate) fn inject_materials( if let Some(material) = material_found { info!("Step 6: injecting/replacing materials"); for (child_index, child) in children.iter().enumerate() { - if child_index == material_index { - if with_materials_and_meshes.contains(*child) { - info!( - "injecting material {}, path: {:?}", - material_info.name, - material_info.path.clone() - ); + if child_index == material_index && with_materials_and_meshes.contains(*child) { + info!( + "injecting material {}, path: {:?}", + material_info.name, + material_info.path.clone() + ); - commands.entity(*child).insert(material.clone()); - } + commands.entity(*child).insert(material.clone()); } } } diff --git a/crates/blenvy/src/blueprints/mod.rs b/crates/blenvy/src/blueprints/mod.rs index 56f4190..23e5c7d 100644 --- a/crates/blenvy/src/blueprints/mod.rs +++ b/crates/blenvy/src/blueprints/mod.rs @@ -48,16 +48,10 @@ impl Default for BluePrintBundle { } } -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] /// Plugin for gltf blueprints pub struct BlueprintsPlugin {} -impl Default for BlueprintsPlugin { - fn default() -> Self { - Self {} - } -} - fn hot_reload(watching_for_changes: Res) -> bool { // println!("hot reload ? {}", watching_for_changes.0); watching_for_changes.0 diff --git a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs index 5d92496..fdaa411 100644 --- a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs +++ b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs @@ -226,7 +226,7 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading( let mut failed = false; if let bevy::asset::LoadState::Failed(_) = asset_server.load_state(asset_id) { - failed = true + failed = true; } tracker.loaded = loaded || failed; if loaded || failed { @@ -408,7 +408,7 @@ pub(crate) fn blueprints_check_assets_loading( let mut failed = false; if let bevy::asset::LoadState::Failed(_) = asset_server.load_state(asset_id) { warn!("FAILED TO LOAD {}", tracker.path.clone()); - failed = true + failed = true; } tracker.loaded = loaded || failed; if loaded || failed { @@ -660,6 +660,7 @@ pub struct BlueprintReadyForPostProcess; /// - it copies the blueprint's root components to the entity it was spawned on (original entity) /// - it copies the children of the blueprint scene into the original entity /// - it adds an `AnimationLink` component containing the entity that has the `AnimationPlayer` so that animations can be controlled from the original entity +#[allow(clippy::too_many_arguments)] pub(crate) fn blueprints_cleanup_spawned_scene( blueprint_scenes: Query< ( diff --git a/crates/blenvy/src/components/blender_settings/lighting.rs b/crates/blenvy/src/components/blender_settings/lighting.rs index 4f3bc7f..7f1a2ce 100644 --- a/crates/blenvy/src/components/blender_settings/lighting.rs +++ b/crates/blenvy/src/components/blender_settings/lighting.rs @@ -173,8 +173,6 @@ fn process_colorgrading( gamma: blender_colorgrading.gamma, ..Default::default() }, - - ..Default::default() }); commands.entity(scene_id).remove::(); } diff --git a/crates/blenvy/src/save_load/loading.rs b/crates/blenvy/src/save_load/loading.rs index cd0da69..9f9211a 100644 --- a/crates/blenvy/src/save_load/loading.rs +++ b/crates/blenvy/src/save_load/loading.rs @@ -45,7 +45,7 @@ pub fn process_load_requests( } pub fn should_load(loading_requests: Option>) -> bool { - return resource_exists::(loading_requests); + resource_exists::(loading_requests) } // TODO: replace with generic despawner ? diff --git a/crates/blenvy/src/save_load/mod.rs b/crates/blenvy/src/save_load/mod.rs index 521740f..9217e47 100644 --- a/crates/blenvy/src/save_load/mod.rs +++ b/crates/blenvy/src/save_load/mod.rs @@ -45,10 +45,10 @@ pub struct BlueprintWorld { impl BlueprintWorld { pub fn from_path(path: &str) -> BlueprintWorld { // let p = Path::new(&path); - return BlueprintWorld { + BlueprintWorld { // name: p.file_stem().unwrap().to_os_string().into_string().unwrap(), // seriously ? , also unwraps !! path: path.into(), - }; + } } } diff --git a/crates/blenvy/src/save_load/saving.rs b/crates/blenvy/src/save_load/saving.rs index da183d7..826b5a1 100644 --- a/crates/blenvy/src/save_load/saving.rs +++ b/crates/blenvy/src/save_load/saving.rs @@ -38,7 +38,7 @@ pub fn process_save_requests( } pub fn should_save(saving_requests: Option>) -> bool { - return resource_exists::(saving_requests); + resource_exists::(saving_requests) } // any child of dynamic/ saveable entities that is not saveable itself should be removed from the list of children diff --git a/examples/animation/src/main.rs b/examples/animation/src/main.rs index 2f63ce0..3736036 100644 --- a/examples/animation/src/main.rs +++ b/examples/animation/src/main.rs @@ -73,11 +73,10 @@ pub fn animation_control( animation_transitions .play( &mut animation_player, - animations + *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(), + .expect("animation name should be in the list"), Duration::from_secs(5), ) .repeat(); @@ -94,11 +93,10 @@ pub fn animation_control( animation_transitions .play( &mut animation_player, - animations + *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(), + .expect("animation name should be in the list"), Duration::from_secs(5), ) .repeat(); @@ -114,11 +112,10 @@ pub fn animation_control( animation_transitions .play( &mut animation_player, - animations + *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(), + .expect("animation name should be in the list"), Duration::from_secs(5), ) .repeat(); @@ -134,11 +131,10 @@ pub fn animation_control( animation_transitions .play( &mut animation_player, - animations + *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(), + .expect("animation name should be in the list"), Duration::from_secs(5), ) .repeat(); diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index dff55db..afa31b5 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -7,5 +7,5 @@ license = "MIT OR Apache-2.0" [dependencies] bevy = { version = "0.14", features = ["dynamic_linking"] } blenvy = { path = "../../crates/blenvy" } -bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] } -rand = "0.8.5" \ No newline at end of file +rand = "0.8.5" +avian3d = "0.1.2" \ No newline at end of file diff --git a/examples/demo/src/game/in_game.rs b/examples/demo/src/game/in_game.rs deleted file mode 100644 index ee284a7..0000000 --- a/examples/demo/src/game/in_game.rs +++ /dev/null @@ -1,83 +0,0 @@ -use bevy::prelude::*; -use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning}; -use blenvy::{BluePrintBundle, BlueprintName, GameWorldTag}; - -use bevy_rapier3d::prelude::Velocity; -use rand::Rng; - -pub fn setup_game( - mut commands: Commands, - game_assets: Res, - models: Res>, - mut next_game_state: ResMut>, -) { - commands.insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 0.2, - }); - // here we actually spawn our game world/level - - commands.spawn(( - SceneBundle { - // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene - scene: models - .get(game_assets.world.clone().unwrap().id()) - .expect("main level should have been loaded") - .scenes[0] - .clone(), - ..default() - }, - bevy::prelude::Name::from("world"), - GameWorldTag, - InAppRunning, - )); - - next_game_state.set(GameState::InGame) -} - -#[derive(Component, Reflect, Default, Debug)] -#[reflect(Component)] -struct UnregisteredComponent; - -pub fn spawn_test( - keycode: Res>, - mut commands: Commands, - - mut game_world: Query<(Entity, &Children), With>, -) { - if keycode.just_pressed(KeyCode::KeyT) { - let world = game_world.single_mut(); - let world = world.1[0]; - - let mut rng = rand::thread_rng(); - let range = 5.5; - let x: f32 = rng.gen_range(-range..range); - let y: f32 = rng.gen_range(-range..range); - - let mut rng = rand::thread_rng(); - let range = 0.8; - let vel_x: f32 = rng.gen_range(-range..range); - let vel_y: f32 = rng.gen_range(2.0..2.5); - let vel_z: f32 = rng.gen_range(-range..range); - - let name_index: u64 = rng.gen(); - - let new_entity = commands - .spawn(( - BluePrintBundle { - blueprint: BlueprintName("Health_Pickup".to_string()), - ..Default::default() - }, - bevy::prelude::Name::from(format!("test{}", name_index)), - // BlueprintName("Health_Pickup".to_string()), - // SpawnHere, - TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), - Velocity { - linvel: Vec3::new(vel_x, vel_y, vel_z), - angvel: Vec3::new(0.0, 0.0, 0.0), - }, - )) - .id(); - commands.entity(world).add_child(new_entity); - } -} diff --git a/examples/demo/src/game/in_main_menu.rs b/examples/demo/src/game/in_main_menu.rs deleted file mode 100644 index 2b72d42..0000000 --- a/examples/demo/src/game/in_main_menu.rs +++ /dev/null @@ -1,107 +0,0 @@ -use bevy::prelude::*; -use bevy_gltf_worlflow_examples_common_rapier::{AppState, InMainMenu}; - -pub fn setup_main_menu(mut commands: Commands) { - commands.spawn(( - Camera2dBundle { - camera: Camera { - order: 102, // needed because of this: https://github.com/jakobhellermann/bevy_editor_pls/blob/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs#L213C9-L213C28 - ..default() - }, - ..Default::default() - }, - InMainMenu, - )); - - commands.spawn(( - TextBundle::from_section( - "SOME GAME TITLE !!", - TextStyle { - //font: asset_server.load("fonts/FiraMono-Medium.ttf"), - font_size: 18.0, - color: Color::WHITE, - ..Default::default() - }, - ) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(100.0), - left: Val::Px(200.0), - ..default() - }), - InMainMenu, - )); - - commands.spawn(( - TextBundle::from_section( - "New Game (press Enter to start, press T once the game is started for demo spawning)", - TextStyle { - //font: asset_server.load("fonts/FiraMono-Medium.ttf"), - font_size: 18.0, - color: Color::WHITE, - ..Default::default() - }, - ) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(200.0), - left: Val::Px(200.0), - ..default() - }), - InMainMenu, - )); - - /* - commands.spawn(( - TextBundle::from_section( - "Load Game", - TextStyle { - //font: asset_server.load("fonts/FiraMono-Medium.ttf"), - font_size: 18.0, - color: Color::WHITE, - ..Default::default() - }, - ) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(250.0), - left: Val::Px(200.0), - ..default() - }), - InMainMenu - )); - - commands.spawn(( - TextBundle::from_section( - "Exit Game", - TextStyle { - //font: asset_server.load("fonts/FiraMono-Medium.ttf"), - font_size: 18.0, - color: Color::WHITE, - ..Default::default() - }, - ) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(300.0), - left: Val::Px(200.0), - ..default() - }), - InMainMenu - ));*/ -} - -pub fn teardown_main_menu(bla: Query>, mut commands: Commands) { - for bli in bla.iter() { - commands.entity(bli).despawn_recursive(); - } -} - -pub fn main_menu( - keycode: Res>, - mut next_app_state: ResMut>, -) { - if keycode.just_pressed(KeyCode::Enter) { - next_app_state.set(AppState::AppLoading); - } -} diff --git a/examples/demo/src/game/level_transitions.rs b/examples/demo/src/game/level_transitions.rs index 03ed955..f5547f3 100644 --- a/examples/demo/src/game/level_transitions.rs +++ b/examples/demo/src/game/level_transitions.rs @@ -1,8 +1,4 @@ use bevy::{gltf::Gltf, prelude::*}; -use bevy_gltf_worlflow_examples_common_rapier::{ - assets::GameAssets, GameState, InAppRunning, Player, -}; -use bevy_rapier3d::prelude::*; use blenvy::GameWorldTag; #[derive(Component, Reflect, Default, Debug)] diff --git a/examples/demo/src/game/mod.rs b/examples/demo/src/game/mod.rs index fd9516e..420ef95 100644 --- a/examples/demo/src/game/mod.rs +++ b/examples/demo/src/game/mod.rs @@ -1,22 +1,11 @@ -pub mod in_game; -pub use in_game::*; - -pub mod in_main_menu; -pub use in_main_menu::*; - -pub mod level_transitions; -pub use level_transitions::*; +// pub mod level_transitions; +// pub use level_transitions::*; use bevy::prelude::*; pub struct GamePlugin; impl Plugin for GamePlugin { - fn build(&self, app: &mut App) { - app.add_plugins(LevelsPlugin) - .add_systems(Update, (spawn_test).run_if(in_state(GameState::InGame))) - .add_systems(OnEnter(AppState::MenuRunning), setup_main_menu) - .add_systems(OnExit(AppState::MenuRunning), teardown_main_menu) - .add_systems(Update, main_menu.run_if(in_state(AppState::MenuRunning))) - .add_systems(OnEnter(AppState::AppRunning), setup_game); + fn build(&self, __app: &mut App) { + //app.add_plugins(LevelsPlugin); } } diff --git a/examples/demo/src/main.rs b/examples/demo/src/main.rs index c84cd07..9a47e8c 100644 --- a/examples/demo/src/main.rs +++ b/examples/demo/src/main.rs @@ -1,12 +1,15 @@ +use avian3d::prelude::*; use bevy::prelude::*; - -mod core; -use crate::core::*; +use blenvy::{ + AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag, + HideUntilReady, SpawnBlueprint, +}; mod game; use game::*; mod test_components; +use rand::Rng; use test_components::*; fn main() { @@ -14,9 +17,56 @@ fn main() { .add_plugins(( DefaultPlugins.set(AssetPlugin::default()), // our custom plugins - CorePlugin, // reusable plugins - GamePlugin, // specific to our game - ComponentsTestPlugin, // Showcases different type of components /structs + ComponentsExamplesPlugin, // Showcases different type of components /structs + BlenvyPlugin::default(), + GamePlugin, )) + .add_systems(Startup, setup_game) + .add_systems(Update, spawn_blueprint_instance) .run(); } + +// this is how you setup & spawn a level from a blueprint +fn setup_game(mut commands: Commands) { + // here we actually spawn our game world/level + commands.spawn(( + BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info... + SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now + HideUntilReady, // only reveal the level once it is ready + GameWorldTag, + )); +} + +// you can also spawn blueprint instances at runtime +pub fn spawn_blueprint_instance(keycode: Res>, mut commands: Commands) { + if keycode.just_pressed(KeyCode::KeyS) { + let mut rng = rand::thread_rng(); + let range = 5.5; + let x: f32 = rng.gen_range(-range..range); + let y: f32 = rng.gen_range(-range..range); + + let mut rng = rand::thread_rng(); + let range = 0.8; + let vel_x: f32 = rng.gen_range(-range..range); + let vel_y: f32 = rng.gen_range(2.0..2.5); + let vel_z: f32 = rng.gen_range(-range..range); + + let name_index: u64 = rng.gen(); + + let __new_entity = commands + .spawn(( + BluePrintBundle { + blueprint: BlueprintInfo::from_path("blueprints/Health_Pickup.glb"), + ..Default::default() + }, + Dynamic, + bevy::prelude::Name::from(format!("test{}", name_index)), + HideUntilReady, + AddToGameWorld, + TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), + LinearVelocity(Vec3::new(vel_x, vel_y, vel_z)), + )) + .id(); + // commands.entity(world).add_child(new_entity); + } +} diff --git a/examples/demo/src/test_components.rs b/examples/demo/src/test_components.rs index b5384e2..e5d7cef 100644 --- a/examples/demo/src/test_components.rs +++ b/examples/demo/src/test_components.rs @@ -60,8 +60,8 @@ pub enum EnumTest { None, } -pub struct ComponentsTestPlugin; -impl Plugin for ComponentsTestPlugin { +pub struct ComponentsExamplesPlugin; +impl Plugin for ComponentsExamplesPlugin { fn build(&self, app: &mut App) { app.register_type::() .register_type::() diff --git a/examples/save_load/src/main.rs b/examples/save_load/src/main.rs index 6160d83..b71e6cb 100644 --- a/examples/save_load/src/main.rs +++ b/examples/save_load/src/main.rs @@ -2,8 +2,8 @@ use std::any::TypeId; use bevy::{prelude::*, utils::hashbrown::HashSet}; use blenvy::{ - AddToGameWorld, BlenvyPlugin, BlueprintInfo, BlueprintWorld, Dynamic, GameWorldTag, - HideUntilReady, LoadingRequest, SavingRequest, SpawnBlueprint, + AddToGameWorld, BlenvyPlugin, BlueprintInfo, BlueprintWorld, Dynamic, HideUntilReady, + LoadingRequest, SavingRequest, SpawnBlueprint, }; use rand::Rng; @@ -82,7 +82,7 @@ fn spawn_blueprint_instance(keycode: Res>, mut commands: Co } } -fn move_movers(mut movers: Query<(&mut Transform), With>) { +fn move_movers(mut movers: Query<&mut Transform, With>) { for mut transform in movers.iter_mut() { // println!("moving dynamic entity"); transform.translation.x += 0.005; diff --git a/testing/bevy_example/src/game/animation.rs b/testing/bevy_example/src/game/animation.rs index 478c285..642e6a0 100644 --- a/testing/bevy_example/src/game/animation.rs +++ b/testing/bevy_example/src/game/animation.rs @@ -5,11 +5,11 @@ use std::time::Duration; InstanceAnimationPlayerLink, InstanceAnimations, };*/ -use bevy::{animation::RepeatAnimation, gltf::Gltf, prelude::*}; +use bevy::prelude::*; use blenvy::{ AnimationInfos, AnimationMarkerReached, BlueprintAnimationPlayerLink, BlueprintAnimations, - BlueprintInstanceDisabled, InstanceAnimationPlayerLink, InstanceAnimations, + InstanceAnimationPlayerLink, InstanceAnimations, }; #[derive(Component, Reflect, Default, Debug)] @@ -79,68 +79,6 @@ pub fn animations( } }*/ -pub fn check_animations( - // (&BlueprintAnimationPlayerLink, &BlueprintAnimations) - foxes: Query< - ( - Entity, - Option<&BlueprintAnimationPlayerLink>, - Option<&InstanceAnimationPlayerLink>, - ), - (With, Without), - >, - - foo: Query< - ( - Entity, - Option<&BlueprintAnimationPlayerLink>, - Option<&InstanceAnimationPlayerLink>, - ), - (With, Without), - >, - bar: Query< - ( - Entity, - Option<&BlueprintAnimationPlayerLink>, - Option<&InstanceAnimationPlayerLink>, - ), - (With, Without), - >, - baz: Query< - ( - Entity, - Option<&BlueprintAnimationPlayerLink>, - Option<&InstanceAnimationPlayerLink>, - ), - (With, Without), - >, - - bli: Query<(Entity, &AnimationInfos)>, - anim_players: Query<(Entity, &AnimationPlayer)>, - all_names: Query<&Name>, -) { - /*for bla in foxes.iter() { - println!("MarkerAllFoxes {:?} {:?} {:?}", all_names.get(bla.0), bla.1, bla.2) - } - for bla in foo.iter() { - println!("Marker1 {:?} {:?} {:?}", all_names.get(bla.0), bla.1, bla.2) - } - - for bla in bar.iter() { - println!("Marker2 {:?} {:?} {:?}", all_names.get(bla.0), bla.1, bla.2) - } - for bla in baz.iter() { - println!("Marker3 {:?} {:?} {:?}", all_names.get(bla.0), bla.1, bla.2) - } - println!(""); */ - /*for blo in bli.iter() { - println!("YOOOOO {:?}", all_names.get(blo.0)) - } - for anim in anim_players.iter() { - println!("Players {:?}", all_names.get(anim.0)) - }*/ -} - #[allow(clippy::type_complexity)] pub fn play_animations( animated_foxes: Query< @@ -183,11 +121,10 @@ pub fn play_animations( let (mut animation_player, mut animation_transitions) = animation_players.get_mut(link.0).unwrap(); let anim_name = "Survey"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -204,23 +141,19 @@ pub fn play_animations( println!("Playing animation {:?}", playing_animation); playing_animation.set_repeat(RepeatAnimation::Forever);*/ } - println!(""); } if keycode.just_pressed(KeyCode::KeyP) { println!("playing fox blueprint animation requested"); for (link, animations) in animated_foxes.iter() { - println!("FOO"); - // println!("animations {:?}", animations.named_animations); let (mut animation_player, mut animation_transitions) = animation_players.get_mut(link.0).unwrap(); let anim_name = "Run"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -237,7 +170,7 @@ pub fn play_animations( println!("Playing animation {:?}", playing_animation); playing_animation.set_repeat(RepeatAnimation::Forever);*/ } - println!(""); + println!(" "); } if keycode.just_pressed(KeyCode::KeyO) { @@ -248,11 +181,10 @@ pub fn play_animations( let (mut animation_player, mut animation_transitions) = animation_players.get_mut(link.0).unwrap(); let anim_name = "Walk"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -271,11 +203,10 @@ pub fn play_animations( let (mut animation_player, mut animation_transitions) = animation_players.get_mut(link.0).unwrap(); let anim_name = "Blueprint8_move"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -294,11 +225,10 @@ pub fn play_animations( animation_players.get_mut(link.0).unwrap(); let anim_name = "Blueprint1_move"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -316,11 +246,10 @@ pub fn play_animations( animation_players.get_mut(link.0).unwrap(); let anim_name = "Blueprint1_jump"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -338,11 +267,10 @@ pub fn play_animations( animation_players.get_mut(link.0).unwrap(); let anim_name = "Blueprint1_move"; - let animation_index = animations + let animation_index = *animations .named_indices .get(anim_name) - .expect("animation name should be in the list") - .clone(); + .expect("animation name should be in the list"); animation_transitions .play( @@ -355,7 +283,7 @@ pub fn play_animations( } } -pub fn react_to_animation_markers( +pub fn __react_to_animation_markers( mut animation_marker_events: EventReader, ) { for event in animation_marker_events.read() { diff --git a/testing/bevy_example/src/game/in_game.rs b/testing/bevy_example/src/game/in_game.rs index 3c69d34..733002a 100644 --- a/testing/bevy_example/src/game/in_game.rs +++ b/testing/bevy_example/src/game/in_game.rs @@ -8,11 +8,7 @@ use blenvy::{ //use bevy_rapier3d::prelude::Velocity; use rand::Rng; -pub fn setup_game( - mut commands: Commands, - asset_server: Res, - mut next_game_state: ResMut>, -) { +pub fn setup_game(mut commands: Commands, mut next_game_state: ResMut>) { // here we actually spawn our game world/level commands.spawn(( BlueprintInfo::from_path("levels/World.glb"), @@ -29,30 +25,22 @@ pub fn setup_game( #[reflect(Component)] struct UnregisteredComponent; -pub fn spawn_test( - keycode: Res>, - mut commands: Commands, - - mut game_world: Query<(Entity, &Children), With>, -) { +pub fn spawn_test(keycode: Res>, mut commands: Commands) { if keycode.just_pressed(KeyCode::KeyS) { - let world = game_world.single_mut(); - let world = world.1[0]; - let mut rng = rand::thread_rng(); let range = 5.5; let x: f32 = rng.gen_range(-range..range); let y: f32 = rng.gen_range(-range..range); - let mut rng = rand::thread_rng(); + /*let mut rng = rand::thread_rng(); let range = 0.8; let vel_x: f32 = rng.gen_range(-range..range); let vel_y: f32 = rng.gen_range(2.0..2.5); - let vel_z: f32 = rng.gen_range(-range..range); + let vel_z: f32 = rng.gen_range(-range..range);*/ let name_index: u64 = rng.gen(); - let new_entity = commands + let __new_entity = commands .spawn(( BluePrintBundle { blueprint: BlueprintInfo { diff --git a/testing/bevy_example/src/game/mod.rs b/testing/bevy_example/src/game/mod.rs index a93ae19..23320d3 100644 --- a/testing/bevy_example/src/game/mod.rs +++ b/testing/bevy_example/src/game/mod.rs @@ -8,7 +8,7 @@ use std::{collections::HashMap, fs, time::Duration}; use blenvy::{ BlueprintAnimationPlayerLink, BlueprintAssets, BlueprintEvent, BlueprintInfo, - GltfBlueprintsSet, InstanceAnimations, + InstanceAnimations, }; use crate::{AppState, GameState}; @@ -136,8 +136,8 @@ fn check_for_gltf_events( match event { BlueprintEvent::InstanceReady { entity, - blueprint_name, - blueprint_path, + blueprint_name: _, + blueprint_path: _, } => { info!( "BLUEPRINT EVENT: {:?} for {:?}", @@ -147,8 +147,8 @@ fn check_for_gltf_events( } BlueprintEvent::AssetsLoaded { entity, - blueprint_name, - blueprint_path, + blueprint_name: _, + blueprint_path: _, } => { info!( "BLUEPRINT EVENT: {:?} for {:?}", @@ -156,9 +156,6 @@ fn check_for_gltf_events( all_names.get(*entity) ); } - _ => { - info!("BLUEPRINT EVENT: {:?}", event); - } } } } @@ -183,14 +180,14 @@ impl Plugin for GamePlugin { .run_if(in_state(AppState::AppRunning)) .after(GltfBlueprintsSet::AfterSpawn) )*/ - .add_systems(Update, (play_animations, check_animations)) + .add_systems(Update, play_animations) // check_animations //.add_systems(Update, react_to_animation_markers) - /*.add_systems(Update, generate_screenshot.run_if(on_timer(Duration::from_secs_f32(0.2)))) // TODO: run once + .add_systems(Update, generate_screenshot.run_if(on_timer(Duration::from_secs_f32(0.2)))) // TODO: run once .add_systems( Update, exit_game.run_if(on_timer(Duration::from_secs_f32(0.5))), - ) // shut down the app after this time*/ + ) // shut down the app after this time ; } } diff --git a/testing/bevy_example/src/hierarchy_debug.rs b/testing/bevy_example/src/hierarchy_debug.rs index 7699c26..9e83f02 100644 --- a/testing/bevy_example/src/hierarchy_debug.rs +++ b/testing/bevy_example/src/hierarchy_debug.rs @@ -2,14 +2,13 @@ use bevy::{ gltf::{GltfMaterialExtras, GltfMeshExtras, GltfSceneExtras}, prelude::*, }; -use blenvy::{BlueprintAssets, BlueprintInstanceReady}; -use crate::{BasicTest, EnumComplex, EnumTest, RedirectPropHitImpulse}; +use crate::{EnumTest, RedirectPropHitImpulse}; #[derive(Component)] pub struct HiearchyDebugTag; -pub fn setup_hierarchy_debug(mut commands: Commands, asset_server: Res) { +pub fn setup_hierarchy_debug(mut commands: Commands) { // a place to display the extras on screen commands.spawn(( TextBundle::from_section( @@ -40,25 +39,25 @@ pub fn get_descendants( all_children: &Query<&Children>, all_names: &Query<&Name>, root: &Entity, - all_transforms: &Query<&Transform>, - all_global_transforms: &Query<&GlobalTransform>, + __all_transforms: &Query<&Transform>, + __all_global_transforms: &Query<&GlobalTransform>, nesting: usize, to_check: &Query<&EnumTest>, //&Query<(&BlueprintInstanceReady, &BlueprintAssets)>, ) -> String { let mut hierarchy_display: Vec = vec![]; let root_name = all_names.get(*root); let name; - if root_name.is_ok() { - name = root_name.unwrap().to_string(); + if let Ok(root_name) = root_name { + name = root_name.to_string(); } else { - name = "no_name".to_string() + name = "no_name".to_string(); } let mut component_display: String = "".into(); - let components_to_check = to_check.get(*root); + let __components_to_check = to_check.get(*root); if let Ok(compo) = to_check.get(*root) { - component_display = format!("{:?}", compo).clone(); + component_display = format!("{:?}", compo); } hierarchy_display.push(format!( @@ -72,22 +71,22 @@ pub fn get_descendants( if let Ok(children) = all_children.get(*root) { for child in children.iter() { let child_descendants_display = get_descendants( - &all_children, - &all_names, - &child, - &all_transforms, - &all_global_transforms, + all_children, + all_names, + child, + __all_transforms, + __all_global_transforms, nesting + 4, - &to_check, + to_check, ); hierarchy_display.push(child_descendants_display); } } - return hierarchy_display.join("\n"); + hierarchy_display.join("\n") } pub fn draw_hierarchy_debug( - root: Query<(Entity, Option<&Name>, &Children), (Without)>, + root: Query>, all_children: Query<&Children>, all_names: Query<&Name>, all_transforms: Query<&Transform>, @@ -98,7 +97,7 @@ pub fn draw_hierarchy_debug( ) { let mut hierarchy_display: Vec = vec![]; - for (root_entity, name, children) in root.iter() { + for root_entity in root.iter() { // hierarchy_display.push( format!("Hierarchy root{:?}", name) ); hierarchy_display.push(get_descendants( @@ -124,7 +123,8 @@ pub fn draw_hierarchy_debug( } ////////:just some testing for gltf extras -fn check_for_gltf_extras( +#[allow(clippy::type_complexity)] +fn __check_for_gltf_extras( gltf_extras_per_entity: Query<( Entity, Option<&Name>, @@ -137,7 +137,7 @@ fn check_for_gltf_extras( ) { let mut gltf_extra_infos_lines: Vec = vec![]; - for (id, name, scene_extras, extras, mesh_extras, material_extras) in + for (id, name, scene_extras, __extras, mesh_extras, material_extras) in gltf_extras_per_entity.iter() { if scene_extras.is_some() @@ -165,12 +165,12 @@ fn check_for_gltf_extras( } } -fn check_for_component( - foo: Query<(Entity, Option<&Name>, &RedirectPropHitImpulse)>, +fn __check_for_component( + specific_components: Query<(Entity, Option<&Name>, &RedirectPropHitImpulse)>, mut display: Query<&mut Text, With>, ) { let mut info_lines: Vec = vec![]; - for (entiity, name, enum_complex) in foo.iter() { + for (__entiity, name, enum_complex) in specific_components.iter() { let data = format!( " We have a matching component: {:?} (on {:?})", enum_complex, name diff --git a/testing/bevy_example/src/state.rs b/testing/bevy_example/src/state.rs index 197ecc8..205a60e 100644 --- a/testing/bevy_example/src/state.rs +++ b/testing/bevy_example/src/state.rs @@ -1,5 +1,6 @@ use bevy::prelude::*; +#[allow(dead_code)] #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, States)] pub enum AppState { CoreLoading, @@ -10,6 +11,7 @@ pub enum AppState { AppEnding, } +#[allow(dead_code)] #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, States)] pub enum GameState { #[default] @@ -25,8 +27,6 @@ pub enum GameState { } // tag components for all entities within a certain state (for despawning them if needed) , FIXME: seems kinda hack-ish -#[derive(Component)] -pub struct InCoreLoading; #[derive(Component, Default)] pub struct InMenuRunning; #[derive(Component)]