3 #include <core/Assertions.h>
4 #include <render/shader/UBO.h>
5 #include "component/TagComponents.h"
6 #include "component/TransformComponent.h"
12 : handle(this->getRegistry().create()) {
20 Scene::Scene(
const std::string& name)
22 this->getRegistry().emplace<
NameComponent>(this->handle, name);
26 this->getRegistry().clear();
32 Entity* Scene::addEntity() {
33 auto uuid = UUIDGenerator::getNewUUID();
34 return this->addEntity(uuid);
37 Entity* Scene::addEntity(
const std::string& name) {
38 auto* entity = this->addEntity();
43 Entity* Scene::addEntity(uuids::uuid uuid) {
44 runtime_assert(!this->entities.contains(uuid),
"Entity UUID is already present!");
45 this->entities[uuid] = std::unique_ptr<Entity>{
new Entity{
this}};
46 auto& entity = this->entities.at(uuid);
51 Entity* Scene::addEntity(uuids::uuid uuid,
const std::string& name) {
52 auto* entity = this->addEntity(uuid);
57 Entity* Scene::getEntity(uuids::uuid entityID) {
58 if (!this->hasEntity(entityID)) {
61 return this->entities.at(entityID).get();
64 bool Scene::hasEntity(uuids::uuid entityID) {
65 return this->entities.contains(entityID);
68 void Scene::removeEntity(uuids::uuid entityID) {
69 runtime_assert(this->hasEntity(entityID),
"Trying to remove an entity with a UUID that doesn't exist!");
70 this->getRegistry().destroy(this->getEntity(entityID)->getRawHandle());
71 this->entities.erase(entityID);
76 for (
auto [entity, cameraComponent] : cameraView.each()) {
77 if (cameraComponent.active) {
78 return &cameraComponent;
84 void Scene::setupForRender(glm::vec2i size) {
85 const auto* camera = this->getCamera();
90 PerspectiveViewUBO::get().update(
91 camera->getProjection(size),
93 transform->getPosition(),
94 transform->getFrontVector());
97 entt::registry& Scene::getRegistry() {
98 return this->registry;
101 const entt::registry& Scene::getRegistry()
const {
102 return this->registry;