Skip to content

Commit

Permalink
Fix is_any_array_a_ref (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-j-obrien authored Apr 9, 2024
1 parent 19d8451 commit 9a9a856
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions flecs_ecs/src/core/iterable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ impl<'a, T: Iterable<'a>, const LEN: usize> ComponentPointers<'a, T>
let mut array_components = [std::ptr::null::<u8>() as *mut u8; LEN];
let mut is_ref_array_components = [false; LEN];

T::populate_array_ptrs(
let is_any_array_a_ref = T::populate_array_ptrs(
iter,
&mut array_components[..],
&mut is_ref_array_components[..],
);

let is_any_array_a_ref = is_ref_array_components[0];

Self {
array_components,
is_ref_array_components,
Expand Down Expand Up @@ -361,7 +359,7 @@ pub trait Iterable<'a>: Sized {
index: &mut usize,
);

fn populate_array_ptrs(it: &IterT, components: &mut [*mut u8], is_ref: &mut [bool]);
fn populate_array_ptrs(it: &IterT, components: &mut [*mut u8], is_ref: &mut [bool]) -> bool;

fn create_tuple(array_components: &[*mut u8], index: usize) -> Self::TupleType;

Expand Down Expand Up @@ -415,14 +413,15 @@ where
it: &IterT,
components: &mut [*mut u8],
is_ref: &mut [bool],
) {
) -> bool {
components[0] =
unsafe { ecs_field::<A::OnlyType>(it, 1) as *mut u8 };
is_ref[0] = if !it.sources.is_null() {
unsafe { *it.sources.add(0) != 0 }
} else {
false
};
is_ref[0]
}

fn create_tuple(array_components: &[*mut u8], index: usize) -> Self::TupleType {
Expand Down Expand Up @@ -627,8 +626,9 @@ macro_rules! impl_iterable {
it: &IterT,
components: &mut [*mut u8],
is_ref: &mut [bool],
) {
) -> bool {
let mut index = 0;
let mut any_ref = false;
$(
components[index as usize] =
unsafe { ecs_field::<$t::OnlyType>(it, index + 1) as *mut u8 };
Expand All @@ -637,8 +637,10 @@ macro_rules! impl_iterable {
} else {
false
};
any_ref |= is_ref[index as usize];
index += 1;
)*
any_ref
}

#[allow(unused, clippy::unused_unit)]
Expand Down

0 comments on commit 9a9a856

Please sign in to comment.