Skip to content

Commit f49cbcb

Browse files
committed
Fixed Queries not returning results if only tags are used.
* Fixed entities improperly storing their slots in the entity storage, overriding previous values in large operations. * Fixed entities not clearing slot information on destruction. * Fixed entities being moved to the wrong locations after a hole was created during destruction. * Fixed some bugs in x64 and webasm test apps.
1 parent 775b790 commit f49cbcb

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

source/code/example/webasm/private/example_webasm.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct TestTrait : public ice::Trait
113113
ice::Timer timer;
114114

115115
using TestArchetype = ice::ecs::ArchetypeDefinition<C1, C2>;
116-
static constexpr ice::ecs::ArchetypeDefinition Archetype_TestArchetype = TestArchetype{};
116+
static constexpr ice::ecs::ArchetypeDefinition Archetype_TestArchetype = TestArchetype{ "test-arch" };
117117

118118
ice::ecs::EntityOperations* _ops;
119119
ice::ecs::Entity _my_entity[10000];
@@ -123,8 +123,7 @@ struct TestTrait : public ice::Trait
123123

124124
update.engine.entity_index().create_many(_my_entity);
125125
_ops = ice::addressof(update.world.entity_operations());
126-
127-
ice::ecs::queue_set_archetype(*_ops, _my_entity, Archetype_TestArchetype);
126+
_ops->set("test-arch", _my_entity);
128127

129128
ICE_LOG(LogSeverity::Retail, LogTag::Game, "Test Activated!");
130129
timer = ice::timer::create_timer(update.clock, 100_Tms);
@@ -138,7 +137,7 @@ struct TestTrait : public ice::Trait
138137
query<ice::ecs::Entity>().tags<C1, C2>().for_each_block(
139138
[&](ice::ucount count, ice::ecs::Entity const* entities) noexcept
140139
{
141-
ice::ecs::queue_batch_remove_entities(*_ops, { entities, count });
140+
_ops->destroy({ entities, count });
142141
}
143142
);
144143

@@ -187,9 +186,7 @@ struct TestTrait : public ice::Trait
187186
ICE_LOG(LogSeverity::Info, LogTag::Game, "TestTrait::logic {}", x.load());
188187
}
189188

190-
ICE_LOG(LogSeverity::Debug, LogTag::Game, "{}", std::hash<std::thread::id>{}(std::this_thread::get_id()));
191189
co_await ice::await_scheduled_on(tasks, update.thread.tasks, update.thread.main);
192-
ICE_LOG(LogSeverity::Debug, LogTag::Game, "{}", std::hash<std::thread::id>{}(std::this_thread::get_id()));
193190
co_return;
194191
}
195192

source/code/iceshard/engine/private/ecs/ecs_archetype_index.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ namespace ice::ecs
2828
return base_offset;
2929
}
3030

31-
auto contains_required_components(
31+
bool contains_required_components(
3232
ice::Span<ice::ecs::detail::QueryTypeInfo const> in_conditions,
3333
ice::Span<ice::StringID const> in_required_tags,
3434
ice::Span<ice::StringID const> checked_identifiers
35-
) noexcept -> ice::u32
35+
) noexcept
3636
{
3737
using QueryTypeInfo = ice::ecs::detail::QueryTypeInfo;
3838

@@ -93,7 +93,7 @@ namespace ice::ecs
9393
matched_components += (identifier_hash == condition_hash);
9494
}
9595

96-
return result ? matched_components : 0;
96+
return result;
9797
}
9898

9999
} // namespace detail
@@ -367,15 +367,15 @@ namespace ice::ecs
367367
continue;
368368
}
369369

370-
ice::u32 const matched_components = ice::ecs::detail::contains_required_components(
370+
bool const was_matched = ice::ecs::detail::contains_required_components(
371371
query_info,
372372
query_tags,
373373
archetype_info.component_identifiers
374374
);
375375

376376
// If we don't match any component in a full optional query, we still skip this archetype.
377377
// #todo: we should probably also check for the existance of the EntityHandle in the query. Then the check should be `> 1`
378-
if (matched_components > 0)
378+
if (was_matched)
379379
{
380380
ice::array::push_back(out_archetypes, entry->archetype_identifier);
381381
}

source/code/iceshard/engine/private/ecs/ecs_entity_storage.cxx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ namespace ice::ecs
317317
void batch_remove_entities(
318318
ice::ecs::ArchetypeIndex const& archetypes,
319319
ice::HashMap<ice::ecs::detail::EntityDestructor> const& destructors,
320+
ice::Span<ice::ecs::EntityDataSlot> dst_data_slots,
320321
ice::Span<ice::ecs::Entity const> entities_to_remove,
321322
ice::Span<ice::ecs::detail::DataBlock*> data_blocks,
322323
ice::Span<ice::ecs::EntityDataSlot> data_slots
@@ -481,15 +482,23 @@ namespace ice::ecs
481482
first_slot_info, // The initially removed slot
482483
component_info,
483484
component_info,
484-
del_data_details, /* src data block */
485-
dst_data_details /* dst data block */
485+
dst_data_details, /* src data block */
486+
del_data_details /* dst data block */
486487
);
487488
}
488489

489490
// Remove entity count from the block we moved from (we can just forget the data existed)
490491
archetype_block->block_entity_count -= span_size;
491492

492493
} while(it != end);
494+
495+
// Clear all references
496+
// TODO: We might not need this later once we extend Operations with a "type" flag.
497+
for (ice::ecs::Entity entity : entities_to_remove)
498+
{
499+
ice::ecs::EntityInfo const ei = ice::ecs::entity_info(entity);
500+
dst_data_slots[ei.index] = {}; // Reset the slot info!
501+
}
493502
}
494503

495504
auto default_filter(void const*, void const*) noexcept
@@ -755,10 +764,10 @@ namespace ice::ecs
755764
}
756765
}
757766

758-
// #todo allow different archetypes maybe?
759-
ICE_ASSERT(
767+
ICE_LOG_IF(
760768
same_archetype == true,
761-
"Entities in operation have different archetypes, operation is illformed!"
769+
LogSeverity::Warning, LogTag::Engine,
770+
"Entities in operation have different archetypes, not all operations can handle this yet! Check for possible bugs!"
762771
);
763772
}
764773

@@ -976,6 +985,7 @@ namespace ice::ecs
976985
}
977986

978987
// Update the remianing count
988+
processed_count += entities_stored;
979989
remaining_count -= entities_stored;
980990
data_block_it->block_entity_count += entities_stored;
981991
}
@@ -1063,6 +1073,7 @@ namespace ice::ecs
10631073
ice::ecs::detail::batch_remove_entities(
10641074
_archetype_index,
10651075
_destructors,
1076+
_data_slots,
10661077
entities,
10671078
_data_blocks,
10681079
_data_slots

source/code/test/private/game.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ struct TestTrait : public ice::Trait
135135
ice::Allocator& _alloc;
136136
ice::Timer timer;
137137

138-
ice::ecs::Archetype _arch_test;
139-
140138
ice::ecs::EntityOperations* _ops;
141139
ice::ecs::Entity _my_entity[10000];
142140

@@ -145,7 +143,7 @@ struct TestTrait : public ice::Trait
145143

146144
update.engine.entity_index().create_many(_my_entity);
147145
_ops = ice::addressof(update.world.entity_operations());
148-
_ops->set(_arch_test, _my_entity);
146+
_ops->set("test-arch", _my_entity);
149147

150148
ICE_LOG(LogSeverity::Retail, LogTag::Game, "Test Activated!");
151149
timer = ice::timer::create_timer(update.clock, 100_Tms);

0 commit comments

Comments
 (0)