summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs69
1 files changed, 38 insertions, 31 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index 2c88eef..962c542 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -12,7 +12,11 @@ use hashbrown::HashMap;
use crate::actions::Action;
use crate::component::storage::archetype::EntityComponent as ArchetypeEntityComponent;
use crate::component::storage::Storage as ComponentStorage;
-use crate::component::{Component, Sequence as ComponentSequence};
+use crate::component::{
+ Component,
+ Parts as ComponentParts,
+ Sequence as ComponentSequence,
+};
use crate::entity::CREATE_STATIC_ENTITIES;
use crate::extension::{Collector as ExtensionCollector, Extension};
use crate::lock::{Lock, WriteGuard};
@@ -116,14 +120,16 @@ impl World
Self::add_entity_components(
entity_uid,
- components.into_array(),
+ components.into_parts_array(),
&mut component_storage_lock,
);
}
- for added_event_id in Comps::added_event_ids() {
- self.emit_event_by_id(added_event_id);
- }
+ // TODO: Emit component added events here
+
+ // for added_event_id in Comps::added_event_ids() {
+ // self.emit_event_by_id(added_event_id);
+ // }
}
/// Adds a globally shared singleton value.
@@ -368,7 +374,7 @@ impl World
for action in active_action_queue.drain(..) {
match action {
- Action::Spawn(components, component_added_event_ids) => {
+ Action::Spawn(components) => {
{
let mut component_storage_lock = self.lock_component_storage_rw();
@@ -392,18 +398,16 @@ impl World
self.swap_event_queue(&mut has_swapped_active_queue);
}
- for comp_added_event_id in component_added_event_ids.ids {
- self.emit_event_by_id(comp_added_event_id);
- }
+ // TODO: Emit component added events here
+
+ // for comp_added_event_id in component_added_event_ids.ids {
+ // self.emit_event_by_id(comp_added_event_id);
+ // }
}
Action::Despawn(entity_uid) => {
self.despawn_entity(entity_uid, &mut has_swapped_active_queue);
}
- Action::AddComponents(
- entity_uid,
- components,
- component_added_event_ids,
- ) => {
+ Action::AddComponents(entity_uid, components) => {
{
let mut component_storage_lock = self.lock_component_storage_rw();
@@ -418,26 +422,22 @@ impl World
self.swap_event_queue(&mut has_swapped_active_queue);
}
+ // TODO: Emit component added events here
+
// TODO: Fix that events are emitted for components that haven't been
// added because a error occurred (for example, the entity already has
// the component)
- for comp_added_event_id in component_added_event_ids.ids {
- self.emit_event_by_id(comp_added_event_id);
- }
+ // for comp_added_event_id in component_added_event_ids.ids {
+ // self.emit_event_by_id(comp_added_event_id);
+ // }
}
- Action::RemoveComponents(
- entity_uid,
- components_metadata,
- component_removed_event_ids,
- ) => {
+ Action::RemoveComponents(entity_uid, component_ids) => {
{
let mut component_storage_lock = self.lock_component_storage_rw();
Self::remove_entity_components(
entity_uid,
- components_metadata
- .iter()
- .map(|comp_metadata| comp_metadata.id),
+ component_ids,
&mut component_storage_lock,
);
}
@@ -446,12 +446,14 @@ impl World
self.swap_event_queue(&mut has_swapped_active_queue);
}
+ // TODO: Emit component removed events here
+
// TODO: Fix that events are emitted for components that haven't been
// removed because a error occurred (for example, the entity does not
// have the component)
- for comp_removed_event_id in component_removed_event_ids.ids {
- self.emit_event_by_id(comp_removed_event_id);
- }
+ // for comp_removed_event_id in component_removed_event_ids.ids {
+ // self.emit_event_by_id(comp_removed_event_id);
+ // }
}
Action::Stop => {
self.stop.store(true, Ordering::Relaxed);
@@ -488,14 +490,18 @@ impl World
fn add_entity_components(
entity_uid: Uid,
- components: impl IntoIterator<Item = (Uid, Box<dyn Component>)>,
+ components: impl IntoIterator<Item = ComponentParts>,
component_storage: &mut ComponentStorage,
)
{
- for (component_id, component) in components {
+ for component_parts in components {
if let Err(err) = component_storage.add_entity_component(
entity_uid,
- (component_id, component.name(), component),
+ (
+ component_parts.id(),
+ component_parts.name(),
+ component_parts.into_data(),
+ ),
) {
tracing::error!("Failed to add component to entity: {err}");
}
@@ -517,6 +523,7 @@ impl World
}
}
+ #[allow(dead_code)]
fn emit_event_by_id(&self, event_id: Uid)
{
let query = self.flexible_query(