Tracked down the bug that was caused by picking up an item but not removing its Position in the world, so when you go to another level it gets brought back to life causing a dupe.

This commit is contained in:
Zed A. Shaw 2025-06-22 12:50:09 -04:00
parent 2c6565c40a
commit e0588847fa
7 changed files with 62 additions and 5 deletions

View file

@ -36,17 +36,22 @@ namespace DinkyECS
std::unordered_map<std::type_index, std::any> $facts;
std::unordered_map<std::type_index, EventQueue> $events;
std::unordered_map<std::type_index, std::any> $component_storages;
std::vector<Entity> $constants;
std::unordered_map<Entity, bool> $constants;
Entity entity() { return ++entity_count; }
void clone_into(DinkyECS::World &to_world) {
to_world.$constants = $constants;
to_world.$facts = $facts;
// BUG*10: entity IDs should be a global counter, not per world
to_world.entity_count = entity_count;
to_world.$component_storages = $component_storages;
for(auto eid : $constants) {
for(auto [eid, is_set] : $constants) {
dbc::check(is_set == true, "is_set was not true? WHAT?!");
dbc::check(eid <= entity_count, fmt::format(
"eid {} is not less than entity_count {}", eid, entity_count));
for(const auto &[tid, eid_map] : $components) {
auto &their_map = to_world.$components[tid];
if(eid_map.contains(eid)) {
@ -57,7 +62,13 @@ namespace DinkyECS
}
void make_constant(DinkyECS::Entity entity) {
$constants.push_back(entity);
fmt::println(">>> Entity {} is now constant", entity);
$constants.try_emplace(entity, true);
}
void not_constant(DinkyECS::Entity entity) {
fmt::println("<<< Entity {} is NOT constant", entity);
$constants.erase(entity);
}
template <typename Comp>