Files
sophia/engine/src/scene/scene.cpp
T
2026-09-26 01:49:45 -07:00

45 lines
1.1 KiB
C++

#include <sophia/components.hpp>
#include <sophia/entity.hpp>
#include <sophia/scene.hpp>
#include <sophia/util/logger.hpp>
namespace sophia {
Scene::Scene() {}
Scene::~Scene() { log::trace("destroying sophia::Scene"); }
Entity Scene::createEntity(const std::string& name) {
Entity entity{this->registry.create(), this};
entity.addComponent<TagComponent>(name.empty() ? "Entity" : name);
entity.addComponent<TransformComponent>();
return entity;
}
Entity Scene::createCamera(const std::string& name) {
Entity camera = createEntity(name);
camera.addComponent<CameraComponent>();
if (this->activeCamera == entt::null) {
this->activeCamera = camera;
}
return camera;
}
Entity Scene::getActiveCamera() {
if (this->activeCamera == entt::null) {
return {};
}
return {this->activeCamera, this};
}
void Scene::setActiveCamera(Entity camera) { this->activeCamera = camera; }
void Scene::destroyEntity(Entity entity) {
if (this->activeCamera == entity) {
this->activeCamera = entt::null;
}
this->registry.destroy(entity);
}
} // namespace sophia