16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 19:09:20 +02:00

New Components/ Prepare to new scene loading system

This commit is contained in:
2026-06-16 21:33:29 +02:00
parent 2c599cb419
commit cb739365b4
15 changed files with 712 additions and 57 deletions

View File

@@ -12,15 +12,24 @@ entt::entity ECWorld::CreateEntity()
void ECWorld::DestroyEntity(entt::entity entity)
{
if (m_registry.valid(entity))
if (m_registry.valid(entity)) {
if (auto *id = m_registry.try_get<ECSComponent::Identification>(entity))
m_nameIndex.erase(id->Name.ToString());
m_registry.destroy(entity);
}
}
void ECWorld::Clear()
{
m_nameIndex.clear();
m_registry.clear();
}
void ECWorld::UpdateNameIndex(entt::entity entity, const std::string &name)
{
m_nameIndex[name] = entity;
}
bool ECWorld::IsAlive(entt::entity entity) const
{
return m_registry.valid(entity);
@@ -29,18 +38,8 @@ bool ECWorld::IsAlive(entt::entity entity) const
entt::entity ECWorld::FindEntityByName(const std::string& name) const
{
auto view = m_registry.view<ECSComponent::Identification>();
for (auto entity : view)
{
const auto& id = view.get<ECSComponent::Identification>(entity);
if (id.Name.ToString() == name)
{
return entity;
}
}
return entt::null;
auto it = m_nameIndex.find(name);
return (it != m_nameIndex.end()) ? it->second : entt::null;
}
entt::registry& ECWorld::Registry()