Expose archetype infos from scene contents
This commit is contained in:
parent
4d2abde5ca
commit
fab7f14298
2 changed files with 53 additions and 23 deletions
|
@ -275,6 +275,7 @@ impl Scene {
|
|||
&mut self.entities,
|
||||
&self.map,
|
||||
(&mut self.renderer, &mut self.particle_system_vulkan_objects),
|
||||
&self.archetypes,
|
||||
&mut self.events,
|
||||
&mut self.resources,
|
||||
)
|
||||
|
@ -291,6 +292,7 @@ impl Scene {
|
|||
&mut self.entities,
|
||||
&self.map,
|
||||
(&mut self.renderer, &mut self.particle_system_vulkan_objects),
|
||||
&self.archetypes,
|
||||
&mut temp_events,
|
||||
&mut self.resources,
|
||||
);
|
||||
|
@ -343,6 +345,7 @@ impl Scene {
|
|||
&mut self.entities,
|
||||
&self.map,
|
||||
(&mut self.renderer, &mut self.particle_system_vulkan_objects),
|
||||
&self.archetypes,
|
||||
&mut self.events,
|
||||
&mut self.resources,
|
||||
);
|
||||
|
@ -352,28 +355,6 @@ impl Scene {
|
|||
|
||||
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 {
|
||||
|
@ -722,6 +703,28 @@ impl SceneEntities for Scene {
|
|||
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>(
|
||||
&mut self,
|
||||
entity: Entity,
|
||||
|
@ -817,6 +820,7 @@ impl SceneEntities for Scene {
|
|||
&mut self.entities,
|
||||
&self.map,
|
||||
(&mut self.renderer, &mut self.particle_system_vulkan_objects),
|
||||
&self.archetypes,
|
||||
&mut self.events,
|
||||
&mut self.resources,
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
|
||||
use utilities::prelude::cgmath::Vector3;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::{bail, Error, Result};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::scene::{content::events::Events, rendering::RenderingFrontEnd};
|
||||
|
@ -43,6 +43,7 @@ pub trait SceneEntities {
|
|||
) -> std::result::Result<&mut EntityObject, EntityNotFoundError>;
|
||||
fn entities_multi_mut(&mut self) -> EntityMultiMut<'_>;
|
||||
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>(
|
||||
&mut self,
|
||||
|
@ -102,6 +103,7 @@ pub struct SceneContents<'a> {
|
|||
|
||||
particle_system_vulkan_objects: &'a mut ParticleSystemVulkanObjects,
|
||||
|
||||
archetypes: &'a Archetypes,
|
||||
pub events: ContentEvents<'a>,
|
||||
pub entities: Entities<'a>,
|
||||
pub resources: &'a mut Resources,
|
||||
|
@ -119,6 +121,7 @@ impl<'a> SceneContents<'a> {
|
|||
&'a mut Box<dyn RenderingFrontEnd + Send + Sync>,
|
||||
&'a mut ParticleSystemVulkanObjects,
|
||||
),
|
||||
archetypes: &'a Archetypes,
|
||||
events: &'a mut Events,
|
||||
resources: &'a mut Resources,
|
||||
) -> Self {
|
||||
|
@ -133,6 +136,7 @@ impl<'a> SceneContents<'a> {
|
|||
|
||||
particle_system_vulkan_objects,
|
||||
|
||||
archetypes,
|
||||
events: ContentEvents { events },
|
||||
entities: Entities {
|
||||
entities,
|
||||
|
@ -354,6 +358,28 @@ impl<'a> SceneEntities for SceneContents<'a> {
|
|||
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>(
|
||||
&mut self,
|
||||
entity: Entity,
|
||||
|
|
Loading…
Reference in a new issue