Files
maszyna/entitysystem/ecs.cpp
2026-03-15 00:00:54 +01:00

61 lines
1.2 KiB
C++

//
// Created by Hirek on 3/14/2026.
//
#include "ecs.h"
void ECS::ClearWorld()
{
world_.clear();
}
entt::entity ECS::CreateObject()
{
const auto e = world_.create();
world_.emplace<ECSComponent::Transform>(e);
world_.emplace<ECSComponent::Identification>(e);
return e;
}
void ECS::DestroyObject(entt::entity Entity)
{
if (Entity == entt::null) // check if Entity is not null
return;
if (!world_.valid(Entity)) // check if exist
return;
world_.destroy(Entity);
}
bool ECS::ValidObject(entt::entity entity) const
{
return entity != entt::null && world_.valid(entity);
}
entt::entity ECS::FindById(std::uint64_t id)
{
auto view = world_.view<const ECSComponent::Identification>();
for (auto e : view)
{
const auto &ident = view.get<ECSComponent::Identification>(e);
if (ident.Id == id)
return e;
}
return entt::null;
}
std::vector<entt::entity> ECS::FindByName(std::string_view name)
{
std::vector<entt::entity> result;
auto view = world_.view<const ECSComponent::Identification>();
for (auto e : view)
{
const auto &ident = view.get<ECSComponent::Identification>(e);
if (ident.Name == name)
{
result.push_back(e);
}
}
return result;
}