summaryrefslogtreecommitdiff
path: root/engine-ecs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src/lib.rs')
-rw-r--r--engine-ecs/src/lib.rs51
1 files changed, 27 insertions, 24 deletions
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index aef374c..9ea03f0 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -1,4 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]
+#![allow(clippy::needless_pass_by_value)]
use std::any::Any;
use std::borrow::Cow;
@@ -175,7 +176,7 @@ impl World
self.create_ent(
entity_uid,
components_parts,
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
@@ -197,10 +198,14 @@ impl World
self.create_ent(
entity_uid,
components_parts.chain([EntityName { name: name.into() }.into_parts()]),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
+ /// Adds a component to an entity.
+ ///
+ /// # Panics
+ /// This function will panic if the component is a [`Sole`].
pub fn add_component(&mut self, entity_id: Uid, component_parts: ComponentParts)
{
assert!(
@@ -214,7 +219,7 @@ impl World
[component_parts],
&mut self.data.component_storage,
&EventSubmitter::new(&self.data.new_events),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
@@ -248,7 +253,7 @@ impl World
sole.into_parts(),
EntityName { name: name.into() }.into_parts(),
],
- ComponentAddingFlags { allow_soles: true },
+ &ComponentAddingFlags { allow_soles: true },
);
Ok(())
@@ -271,7 +276,7 @@ impl World
.into_iter()
.map(IntoComponentParts::into_parts),
),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
system_callbacks.on_created(self, SystemMetadata { ent_id });
@@ -455,7 +460,7 @@ impl World
&mut self,
entity_uid: Uid,
components: impl IntoIterator<Item = ComponentParts>,
- flags: ComponentAddingFlags,
+ flags: &ComponentAddingFlags,
)
{
debug_assert!(!entity_uid.is_pair());
@@ -503,11 +508,11 @@ impl World
(self.error_handler)(
self,
err,
- ErrorMetadata {
+ &ErrorMetadata {
source_name: system.system.name(),
source_kind: ErrorSourceKind::System,
},
- )
+ );
}
}
}
@@ -588,7 +593,7 @@ impl World
.queue
.write_nonblock()
.unwrap_or_else(|err| {
- panic!("Failed to take read-write action queue lock: {err}",);
+ panic!("Failed to take read-write action queue lock: {err}");
});
for action in action_queue_lock.drain(..) {
@@ -609,7 +614,7 @@ impl World
components,
&mut self.data.component_storage,
&EventSubmitter::new(&self.data.new_events),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
Action::Despawn(entity_id) => {
@@ -627,7 +632,7 @@ impl World
components,
&mut self.data.component_storage,
&EventSubmitter::new(&self.data.new_events),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
Action::RemoveComponents(entity_uid, component_ids) => {
@@ -646,7 +651,7 @@ impl World
"Cannot set pair of a non-existant entity"
);
continue;
- };
+ }
let _ = self
.data
@@ -658,7 +663,7 @@ impl World
[new_pair],
&mut self.data.component_storage,
&EventSubmitter::new(&self.data.new_events),
- ComponentAddingFlags { allow_soles: false },
+ &ComponentAddingFlags { allow_soles: false },
);
}
Action::Stop => {
@@ -673,7 +678,7 @@ impl World
components: impl IntoIterator<Item = ComponentParts>,
component_storage: &mut ComponentStorage,
event_submitter: &EventSubmitter<'_>,
- flags: ComponentAddingFlags,
+ flags: &ComponentAddingFlags,
)
{
let component_iter = components.into_iter();
@@ -687,7 +692,7 @@ impl World
let comp_id = component_parts.id;
let comp_name = component_parts.name;
- let comp_type_id = (&*component_parts.data).type_id();
+ let comp_type_id = (*component_parts.data).type_id();
if let Err(err) = component_storage.add_entity_component(
entity_uid,
@@ -774,12 +779,10 @@ impl World
if comp_ent_archetype.contains_component_with_exact_id(ComponentInfo::id()) {
return;
}
- } else {
- if let Err(EntityAlreadyExistsError) =
- component_storage.create_entity(comp_id)
- {
- unreachable!();
- }
+ } else if let Err(EntityAlreadyExistsError) =
+ component_storage.create_entity(comp_id)
+ {
+ unreachable!();
}
let comp_info_parts = comp_info.into_parts();
@@ -805,7 +808,7 @@ impl World
// This error is never returned by add_entity_component
unreachable!();
}
- };
+ }
}
fn remove_entity_components(
@@ -891,11 +894,11 @@ impl World
(self.error_handler)(
self,
err,
- ErrorMetadata {
+ &ErrorMetadata {
source_name: observer.system.name(),
source_kind: ErrorSourceKind::Observer,
},
- )
+ );
}
}
}