summaryrefslogtreecommitdiff
path: root/ecs/src/component
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-05 23:22:49 +0200
committerHampusM <hampus@hampusmat.com>2024-08-05 23:22:49 +0200
commita2eb0a235b738864a107eb9d859878c68f7d5bbf (patch)
tree893f2d0818b597d85b992746d54c81a233ac07c0 /ecs/src/component
parenta83164950aedb40ab3f213d50a757ed07eabd7cc (diff)
fix(ecs): always sort components & component metadata
Diffstat (limited to 'ecs/src/component')
-rw-r--r--ecs/src/component/storage.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index e909395..9c149ed 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -12,6 +12,7 @@ use crate::component::{
use crate::entity::Uid as EntityUid;
use crate::lock::Lock;
use crate::type_name::TypeName;
+use crate::util::Sortable;
use crate::EntityComponent;
#[derive(Debug, Default)]
@@ -26,9 +27,12 @@ impl Storage
{
pub fn find_entities(
&self,
- components_metadata: impl IntoIterator<Item = ComponentMetadata>,
+ mut components_metadata: impl IntoIterator<Item = ComponentMetadata>
+ + Sortable<Item = ComponentMetadata>,
) -> ArchetypeRefIter<'_>
{
+ components_metadata.sort_by_key_b(|component_metadata| component_metadata.id);
+
self.archetype_lookup
.get(&ArchetypeId::from_components_metadata(components_metadata))
.map_or_else(ArchetypeRefIter::new_empty, |archetypes_indices| {
@@ -114,9 +118,12 @@ impl Storage
pub fn add_archetype_lookup_entry(
&mut self,
- components_metadata: impl IntoIterator<Item = ComponentMetadata>,
+ mut components_metadata: impl IntoIterator<Item = ComponentMetadata>
+ + Sortable<Item = ComponentMetadata>,
)
{
+ components_metadata.sort_by_key_b(|component_metadata| component_metadata.id);
+
self.pending_archetype_lookup_entries
.push(components_metadata.into_iter().collect());
}