Skip to content

Commit

Permalink
Adding functions to zip slice structures with itertools's izip (which…
Browse files Browse the repository at this point in the history
… is reexported)
  • Loading branch information
recatek committed Jul 20, 2024
1 parent a3cc947 commit 14f55be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions macros/src/generate/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,22 @@ fn section_archetype(archetype_data: &DataArchetype) -> TokenStream {
}
}

impl<'a> #ArchetypeSlices<'a> {
#[inline(always)]
pub fn zipped(
&'a self,
) -> impl Iterator<Item = (&'a Entity<#Archetype>, #(&'a #Component),*)> {
::gecs::__internal::izip!(self.entity.iter(), #(self.#component.iter()),*)
}

#[inline(always)]
pub fn zipped_mut(
&'a mut self,
) -> impl Iterator<Item = (&'a Entity<#Archetype>, #(&'a mut #Component),*)> {
::gecs::__internal::izip!(self.entity.iter(), #(self.#component.iter_mut()),*)
}
}

impl<'a> ArchetypeCanResolve<'a, #ArchetypeView<'a>, Entity<#Archetype>> for #Archetype {
#[inline(always)]
fn resolve_for(&self, key: Entity<#Archetype>) -> Option<usize> {
Expand Down
6 changes: 3 additions & 3 deletions src/archetype/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::entity::Entity;
use crate::traits::Archetype;

macro_rules! declare_slices_n {
($slices:ident, $slices_mut:ident, $n:literal) => {
($slices:ident, $n:literal) => {
seq!(I in 0..$n {
pub trait $slices<'a, A: Archetype, #(T~I,)*> {
fn new(entities: &'a [Entity<A>], #(s~I: &'a mut [T~I],)*) -> Self;
Expand All @@ -15,11 +15,11 @@ macro_rules! declare_slices_n {

// Declare slices for up to 16 components.
seq!(N in 1..=16 {
declare_slices_n!(Slices~N, SlicesMut~N, N);
declare_slices_n!(Slices~N, N);
});

// Declare additional slices for up to 32 components.
#[cfg(feature = "32_components")]
seq!(N in 17..=32 {
declare_slices_n!(Slices~N, SlicesMut~N, N);
declare_slices_n!(Slices~N, N);
});
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,7 @@ pub mod __internal {
pub use traits::{World, WorldHas};
pub use traits::{Archetype, ArchetypeHas};
pub use traits::{View, ViewHas};


pub use itertools::izip as izip;
}

0 comments on commit 14f55be

Please sign in to comment.