51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: Dora "cat" <cat@thenight.club>
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
* obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <Systems/ECS.hpp>
|
|
#include <Systems/ECS/BuiltinComponents.hpp>
|
|
#include <Systems/Random.hpp>
|
|
#include <optional>
|
|
|
|
using namespace Tourmaline::Systems;
|
|
using namespace ECS;
|
|
|
|
Entity World::CreateEntity() {
|
|
auto newEntity = Random::GenerateUUID();
|
|
|
|
// Default components
|
|
entityComponentMap.insert(newEntity, typeid(Components::Position),
|
|
Components::Position());
|
|
entityComponentMap.insert(newEntity, typeid(Components::Enabled),
|
|
Components::Enabled(this));
|
|
|
|
return newEntity;
|
|
}
|
|
|
|
const Components::Enabled &World::EntityEnable(const Entity &entity) noexcept {
|
|
return this->GetComponent<Components::Enabled>(entity);
|
|
}
|
|
|
|
bool World::EntityExists(const Entity &entity) noexcept {
|
|
bool exists = false;
|
|
entityComponentMap.scan(
|
|
[&exists, entity](const Tourmaline::Type::UUID ¤tEntity,
|
|
const std::type_index &, std::any &) -> bool {
|
|
if (currentEntity == entity) {
|
|
exists = true;
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
return exists;
|
|
}
|
|
|
|
bool World::DestroyEntity(Entity entity) {
|
|
return entityComponentMap.remove(entity, std::nullopt);
|
|
}
|