---
source: froql_macro/src/generator.rs
expression: result
---
{
let world: &World = &world;
let bk = &world.bookkeeping;
let components_0 = [
world.get_component_id::<Unit>(),
world.get_component_id::<Health>(),
bk.get_component_id_unchecked(::std::any::TypeId::of::<::froql::relation::Relation<Attack>>()).flip_target(),
];
let components_1 = [
world.get_component_id::<Unit>(),
bk.get_component_id_unchecked(::std::any::TypeId::of::<::froql::relation::Relation<Attack>>()),
];
let archetype_id_sets = [
bk.matching_archetypes(&components_0, &[]),
bk.matching_archetypes(&components_1, &[]),
];
// result set
const VAR_COUNT: usize = 2;
let mut a_refs = [&bk.archetypes[0]; VAR_COUNT];
let mut a_rows = [::froql::archetype::ArchetypeRow(u32::MAX); VAR_COUNT];
// general context for statemachine
let mut current_step = 0;
let mut a_max_rows = [0; VAR_COUNT];
let mut a_next_indexes = [usize::MAX; VAR_COUNT];
let mut col_indexes = [usize::MAX; 5];
let mut rel_helper_0 = ::froql::query_helper::RelationHelper::new
(components_0[2]);
::std::iter::from_fn(move || { loop { match current_step {
0 => {
const CURRENT_VAR: usize = 0;
const CURRENT_VAR_COMPONENTS: ::std::ops::Range<usize> = 0..3;
let next_index = &mut a_next_indexes[CURRENT_VAR];
let archetype_ids = &archetype_id_sets[CURRENT_VAR];
*next_index = next_index.wrapping_add(1);
if *next_index >= archetype_ids.len() {
return None;
}
let next_id = archetype_ids[*next_index];
// gets rolled over to 0 by wrapping_add
a_rows[CURRENT_VAR] = ::froql::archetype::ArchetypeRow(u32::MAX);
let a_ref = &mut a_refs[CURRENT_VAR];
*a_ref = &bk.archetypes[next_id.as_index()];
a_ref.find_multiple_columns(
&components_0,
&mut col_indexes[CURRENT_VAR_COMPONENTS],
);
a_max_rows[CURRENT_VAR] = a_ref.entities.len() as u32;
rel_helper_0.set_col(&a_ref.columns[col_indexes[2]]);
current_step += 1;
}
// next row in archetype
1 => {
const CURRENT_VAR: usize = 0;
let row_counter = &mut a_rows[CURRENT_VAR].0;
let max_row = a_max_rows[CURRENT_VAR];
// rolls over to 0 for u32::MAX, which is our start value
*row_counter = row_counter.wrapping_add(1);
if *row_counter >= max_row {
current_step -= 1;
} else {
rel_helper_0.set_row(bk, a_rows[0].0);
current_step += 1;
}
}
// follow relation
2 => {
const REL_VAR: usize = 1;
const REL_VAR_COMPONENTS: ::std::ops::Range<usize> = 3..5;
if let Some(id) = rel_helper_0.next_related() {
// get aid/row for entity in relation
let (aid, arow) = bk.entities.get_archetype_unchecked(id);
// if in target archetype set => go to next step
if archetype_id_sets[REL_VAR].contains(&aid) {
let a_ref = &mut a_refs[REL_VAR];
*a_ref = &bk.archetypes[aid.as_index()];
a_ref.find_multiple_columns(
&components_1,
&mut col_indexes[REL_VAR_COMPONENTS],
);
a_rows[REL_VAR] = arow;
current_step += 1;
}
} else {
current_step -= 1;
}
}
// yield row
3 => {
current_step -= 1;
return Some(unsafe {
(
::froql::entity_view_deferred::EntityViewDeferred::from_id_unchecked(world,
a_refs[0].entities[a_rows[0].0 as usize]),
::froql::query_helper::coerce_cast::<Unit>(
world,
a_refs[0].columns[col_indexes[0]].get(a_rows[0].0)
).borrow(),
::froql::query_helper::coerce_cast::<Unit>(
world,
a_refs[1].columns[col_indexes[3]].get(a_rows[1].0)
).borrow(),
::froql::query_helper::coerce_cast::<Health>(
world,
a_refs[0].columns[col_indexes[1]].get(a_rows[0].0)
).borrow_mut(),
)
});
}
_ => unreachable!(),
}}})
}