refactor(): further cleanups

This commit is contained in:
kaosat.dev 2024-03-12 23:41:05 +01:00
parent bb0975bbe8
commit ea41c3c9cb
3 changed files with 30 additions and 11 deletions

View File

@ -144,14 +144,29 @@ impl Plugin for BlueprintsPlugin {
.add_systems( .add_systems(
Update, Update,
( (
(spawn_from_blueprints, (
prepare_blueprints,
check_for_loaded, check_for_loaded,
actually_spawn_stuff, apply_deferred).chain(), spawn_from_blueprints,
apply_deferred
)
.chain(),
(
compute_scene_aabbs,
apply_deferred
)
.chain()
.run_if(aabbs_enabled),
compute_scene_aabbs.run_if(aabbs_enabled),
apply_deferred.run_if(aabbs_enabled),
apply_deferred, apply_deferred,
(materials_inject, check_for_material_loaded, materials_inject2).chain().run_if(materials_library_enabled),
(
materials_inject,
check_for_material_loaded,
materials_inject2
)
.chain()
.run_if(materials_library_enabled),
) )
.chain() .chain()
.in_set(GltfBlueprintsSet::Spawn), .in_set(GltfBlueprintsSet::Spawn),

View File

@ -46,7 +46,6 @@ pub struct AddToGameWorld;
/// helper component, just to transfer child data /// helper component, just to transfer child data
pub(crate) struct OriginalChildren(pub Vec<Entity>); pub(crate) struct OriginalChildren(pub Vec<Entity>);
#[derive(Component, Reflect, Default, Debug)] #[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)] #[reflect(Component)]
pub struct BlueprintsList(pub HashMap<String,Vec<String>>); pub struct BlueprintsList(pub HashMap<String,Vec<String>>);
@ -75,7 +74,7 @@ pub(crate) struct BlueprintAssetsNotLoaded;
/// spawning prepare function, /// spawning prepare function,
/// * also takes into account the already exisiting "override" components, ie "override components" > components from blueprint /// * also takes into account the already exisiting "override" components, ie "override components" > components from blueprint
pub(crate) fn spawn_from_blueprints( pub(crate) fn prepare_blueprints(
spawn_placeholders: Query< spawn_placeholders: Query<
( (
Entity, Entity,
@ -156,10 +155,14 @@ pub(crate) fn spawn_from_blueprints(
.insert(BlueprintAssetsLoaded); .insert(BlueprintAssetsLoaded);
} }
} }
else { // in case there are no blueprintsList
commands
.entity(entity)
.insert(BlueprintAssetsLoaded);
}
} }
} }
pub(crate) fn check_for_loaded( pub(crate) fn check_for_loaded(
mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>), With<BlueprintAssetsNotLoaded>>, mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>), With<BlueprintAssetsNotLoaded>>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
@ -192,7 +195,7 @@ pub(crate) fn check_for_loaded(
} }
} }
pub(crate) fn actually_spawn_stuff( pub(crate) fn spawn_from_blueprints(
spawn_placeholders: Query< spawn_placeholders: Query<
( (
Entity, Entity,

View File

@ -7,7 +7,7 @@ use bevy::scene::SceneInstance;
use super::{AnimationPlayerLink, Animations}; use super::{AnimationPlayerLink, Animations};
use super::{SpawnHere, Spawned}; use super::{SpawnHere, Spawned};
use crate::{AssetsToLoad, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren}; use crate::{AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren};
/// this system is in charge of doing any necessary post processing after a blueprint scene has been spawned /// this system is in charge of doing any necessary post processing after a blueprint scene has been spawned
/// - it removes one level of useless nesting /// - it removes one level of useless nesting
@ -91,6 +91,7 @@ pub(crate) fn spawned_blueprint_post_process(
commands.entity(original).remove::<Spawned>(); commands.entity(original).remove::<Spawned>();
commands.entity(original).remove::<Handle<Scene>>(); commands.entity(original).remove::<Handle<Scene>>();
commands.entity(original).remove::<AssetsToLoad<Gltf>>();// also clear the sub assets tracker to free up handles, perhaps just freeing up the handles and leave the rest would be better ? commands.entity(original).remove::<AssetsToLoad<Gltf>>();// also clear the sub assets tracker to free up handles, perhaps just freeing up the handles and leave the rest would be better ?
commands.entity(original).remove::<BlueprintAssetsLoaded>();
commands.entity(root_entity).despawn_recursive(); commands.entity(root_entity).despawn_recursive();
} }
} }