summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-05-02 17:30:03 +0200
committerHampusM <hampus@hampusmat.com>2026-05-02 17:30:03 +0200
commite698922e86c217a261db114ce0392060503f0013 (patch)
tree9c879601a1fccf5d6126d62fd4e05fd3965cad93 /ecs/src/lib.rs
parentaa02cdecfbfc2b2513e37ef72c720477d30a310c (diff)
feat(ecs): allow creation of already existing entities
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index f6fba64..7a2178e 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -1,17 +1,17 @@
#![deny(clippy::all, clippy::pedantic)]
-use std::any::{type_name, Any, TypeId};
+use std::any::{Any, TypeId, type_name};
use std::fmt::Debug;
use std::mem::ManuallyDrop;
use std::rc::Rc;
-use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
+use std::sync::atomic::{AtomicBool, Ordering};
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::storage::{EntityAlreadyExistsError, Storage as ComponentStorage};
use crate::component::{
Component,
IntoParts as IntoComponentParts,
@@ -25,19 +25,19 @@ use crate::extension::{Collector as ExtensionCollector, Extension};
use crate::lock::Lock;
use crate::pair::{ChildOf, DependsOn, Pair};
use crate::phase::{
- Phase,
POST_UPDATE as POST_UPDATE_PHASE,
PRE_UPDATE as PRE_UPDATE_PHASE,
+ Phase,
START as START_PHASE,
UPDATE as UPDATE_PHASE,
};
use crate::query::flexible::Query as FlexibleQuery;
use crate::query::{
+ MAX_TERM_CNT as QUERY_MAX_TERM_CNT,
TermWithFieldTuple as QueryTermWithFieldTuple,
TermWithoutFieldTuple as QueryTermWithoutFieldTuple,
Terms as QueryTerms,
TermsBuilderInterface,
- MAX_TERM_CNT as QUERY_MAX_TERM_CNT,
};
use crate::sole::{Single, Sole};
use crate::stats::Stats;
@@ -332,9 +332,10 @@ impl World
{
debug_assert_eq!(entity_uid.kind(), UidKind::Entity);
- if let Err(err) = self.data.component_storage.create_entity(entity_uid) {
- tracing::warn!("Failed to create entity: {err}");
- return;
+ if let Err(EntityAlreadyExistsError) =
+ self.data.component_storage.create_entity(entity_uid)
+ {
+ // This is fine
}
Self::add_entity_components(
@@ -625,7 +626,7 @@ impl<'a> EntityComponentRef<'a>
}
fn new(component_id: Uid, comp: &'a ArchetypeEntityComponent, entity_id: Uid)
- -> Self
+ -> Self
{
Self {
component_id,