Expose archetype infos from scene contents

This commit is contained in:
hodasemi 2024-08-28 13:10:23 +02:00
parent 4d2abde5ca
commit fab7f14298
2 changed files with 53 additions and 23 deletions

View file

@ -275,6 +275,7 @@ impl Scene {
&mut self.entities, &mut self.entities,
&self.map, &self.map,
(&mut self.renderer, &mut self.particle_system_vulkan_objects), (&mut self.renderer, &mut self.particle_system_vulkan_objects),
&self.archetypes,
&mut self.events, &mut self.events,
&mut self.resources, &mut self.resources,
) )
@ -291,6 +292,7 @@ impl Scene {
&mut self.entities, &mut self.entities,
&self.map, &self.map,
(&mut self.renderer, &mut self.particle_system_vulkan_objects), (&mut self.renderer, &mut self.particle_system_vulkan_objects),
&self.archetypes,
&mut temp_events, &mut temp_events,
&mut self.resources, &mut self.resources,
); );
@ -343,6 +345,7 @@ impl Scene {
&mut self.entities, &mut self.entities,
&self.map, &self.map,
(&mut self.renderer, &mut self.particle_system_vulkan_objects), (&mut self.renderer, &mut self.particle_system_vulkan_objects),
&self.archetypes,
&mut self.events, &mut self.events,
&mut self.resources, &mut self.resources,
); );
@ -352,28 +355,6 @@ impl Scene {
scene_content.entity_changes().commit(self) scene_content.entity_changes().commit(self)
} }
pub fn archetype_info(&self, name: impl ToString) -> Result<ArchetypeInfo> {
let name = name.to_string();
let archetype = self
.archetypes
.get(&name)
.ok_or_else(|| Error::msg(format!("requested archetype ({}) not found", name)))?;
let mut entities = Vec::new();
for entity in archetype.entities().keys() {
#[cfg(debug_assertions)]
let debug_name = self.entity(*entity)?.debug_name.clone();
#[cfg(not(debug_assertions))]
let debug_name = None;
entities.push((*entity, debug_name));
}
Ok(ArchetypeInfo::new(entities))
}
} }
impl Scene { impl Scene {
@ -722,6 +703,28 @@ impl SceneEntities for Scene {
Ok(e) Ok(e)
} }
fn archetype_info(&self, name: impl ToString) -> Result<ArchetypeInfo> {
let name = name.to_string();
let archetype = self
.archetypes
.get(&name)
.ok_or_else(|| Error::msg(format!("requested archetype ({}) not found", name)))?;
let mut entities = Vec::new();
for entity in archetype.entities().keys() {
#[cfg(debug_assertions)]
let debug_name = self.entity(*entity)?.debug_name.clone();
#[cfg(not(debug_assertions))]
let debug_name = None;
entities.push((*entity, debug_name));
}
Ok(ArchetypeInfo::new(entities))
}
fn insert_component<T: EntityComponent + ComponentDebug>( fn insert_component<T: EntityComponent + ComponentDebug>(
&mut self, &mut self,
entity: Entity, entity: Entity,
@ -817,6 +820,7 @@ impl SceneEntities for Scene {
&mut self.entities, &mut self.entities,
&self.map, &self.map,
(&mut self.renderer, &mut self.particle_system_vulkan_objects), (&mut self.renderer, &mut self.particle_system_vulkan_objects),
&self.archetypes,
&mut self.events, &mut self.events,
&mut self.resources, &mut self.resources,
); );

View file

@ -7,7 +7,7 @@ use std::{
use utilities::prelude::cgmath::Vector3; use utilities::prelude::cgmath::Vector3;
use anyhow::{bail, Result}; use anyhow::{bail, Error, Result};
use indexmap::IndexMap; use indexmap::IndexMap;
use crate::scene::{content::events::Events, rendering::RenderingFrontEnd}; use crate::scene::{content::events::Events, rendering::RenderingFrontEnd};
@ -43,6 +43,7 @@ pub trait SceneEntities {
) -> std::result::Result<&mut EntityObject, EntityNotFoundError>; ) -> std::result::Result<&mut EntityObject, EntityNotFoundError>;
fn entities_multi_mut(&mut self) -> EntityMultiMut<'_>; fn entities_multi_mut(&mut self) -> EntityMultiMut<'_>;
fn add_entity(&mut self, entity_object: EntityObject) -> Result<Entity>; fn add_entity(&mut self, entity_object: EntityObject) -> Result<Entity>;
fn archetype_info(&self, name: impl ToString) -> Result<ArchetypeInfo>;
fn insert_component<T: EntityComponent + ComponentDebug>( fn insert_component<T: EntityComponent + ComponentDebug>(
&mut self, &mut self,
@ -102,6 +103,7 @@ pub struct SceneContents<'a> {
particle_system_vulkan_objects: &'a mut ParticleSystemVulkanObjects, particle_system_vulkan_objects: &'a mut ParticleSystemVulkanObjects,
archetypes: &'a Archetypes,
pub events: ContentEvents<'a>, pub events: ContentEvents<'a>,
pub entities: Entities<'a>, pub entities: Entities<'a>,
pub resources: &'a mut Resources, pub resources: &'a mut Resources,
@ -119,6 +121,7 @@ impl<'a> SceneContents<'a> {
&'a mut Box<dyn RenderingFrontEnd + Send + Sync>, &'a mut Box<dyn RenderingFrontEnd + Send + Sync>,
&'a mut ParticleSystemVulkanObjects, &'a mut ParticleSystemVulkanObjects,
), ),
archetypes: &'a Archetypes,
events: &'a mut Events, events: &'a mut Events,
resources: &'a mut Resources, resources: &'a mut Resources,
) -> Self { ) -> Self {
@ -133,6 +136,7 @@ impl<'a> SceneContents<'a> {
particle_system_vulkan_objects, particle_system_vulkan_objects,
archetypes,
events: ContentEvents { events }, events: ContentEvents { events },
entities: Entities { entities: Entities {
entities, entities,
@ -354,6 +358,28 @@ impl<'a> SceneEntities for SceneContents<'a> {
self.entities.add_entity(entity_object) self.entities.add_entity(entity_object)
} }
fn archetype_info(&self, name: impl ToString) -> Result<ArchetypeInfo> {
let name = name.to_string();
let archetype = self
.archetypes
.get(&name)
.ok_or_else(|| Error::msg(format!("requested archetype ({}) not found", name)))?;
let mut entities = Vec::new();
for entity in archetype.entities().keys() {
#[cfg(debug_assertions)]
let debug_name = self.entity(*entity)?.debug_name.clone();
#[cfg(not(debug_assertions))]
let debug_name = None;
entities.push((*entity, debug_name));
}
Ok(ArchetypeInfo::new(entities))
}
fn insert_component<T: EntityComponent + ComponentDebug>( fn insert_component<T: EntityComponent + ComponentDebug>(
&mut self, &mut self,
entity: Entity, entity: Entity,