summaryrefslogtreecommitdiff
path: root/ecs/src/component.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-24 19:00:38 +0200
committerHampusM <hampus@hampusmat.com>2024-05-24 19:11:11 +0200
commitb8417d20765755cfa2cecacb11c77e3abbafd546 (patch)
tree5f62502eeb846faba66bd204f8dc028ef5f7aa5e /ecs/src/component.rs
parent36886e343781bf0ddf7458d5c6db5b5724c918e4 (diff)
fix(ecs): prevent unnecessary locking in Sequence::from_components
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r--ecs/src/component.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs
index 604f54d..9310995 100644
--- a/ecs/src/component.rs
+++ b/ecs/src/component.rs
@@ -3,9 +3,10 @@ use std::fmt::Debug;
use seq_macro::seq;
-use crate::lock::{Lock, WriteGuard};
+use crate::lock::WriteGuard;
use crate::system::{ComponentRefMut, Input as SystemInput};
use crate::type_name::TypeName;
+use crate::EntityComponent;
pub mod local;
@@ -112,7 +113,7 @@ pub trait Sequence
fn type_ids() -> Vec<(TypeId, IsOptional)>;
fn from_components<'component>(
- components: impl Iterator<Item = &'component Lock<Box<dyn Component>>>,
+ components: impl Iterator<Item = &'component EntityComponent>,
) -> Self::Refs<'component>;
}
@@ -180,7 +181,7 @@ macro_rules! inner {
}
fn from_components<'component>(
- components: impl Iterator<Item = &'component Lock<Box<dyn Component>>>,
+ components: impl Iterator<Item = &'component EntityComponent>,
) -> Self::Refs<'component>
{
#(
@@ -188,12 +189,14 @@ macro_rules! inner {
)*
for comp in components {
- let comp_ref = comp
- .write_nonblock()
- .expect("Failed to acquire read-write component lock");
-
#(
- if comp_ref.is::<Comp~I::Component>() {
+ if comp.id == TypeId::of::<Comp~I::Component>() {
+ let comp_ref = comp.component
+ .write_nonblock()
+ .expect(
+ "Failed to acquire read-write component lock"
+ );
+
comp_~I = Some(comp_ref);
continue;
}