5 #include <unordered_map>
6 #include <entt/entt.hpp>
7 #include <math/Types.h>
8 #include "component/CameraComponent.h"
9 #include "component/NameComponent.h"
10 #include "component/UUIDComponent.h"
22 explicit Scene(
const std::string& name);
29 Entity* addEntity(
const std::string& name);
31 Entity* addEntity(uuids::uuid uuid);
33 Entity* addEntity(uuids::uuid uuid,
const std::string& name);
35 [[nodiscard]]
Entity* getEntity(uuids::uuid entityID);
37 template<
typename... T>
38 auto getEntities()
const {
39 return this->getRegistry().view<T...>();
42 template<
typename... T>
43 auto getEntities(
auto&& exclude)
const {
44 return this->getRegistry().view<T...>(exclude);
47 [[nodiscard]]
const auto& getEntities()
const {
48 return this->entities;
51 [[nodiscard]]
bool hasEntity(uuids::uuid entityID);
53 void removeEntity(uuids::uuid entityID);
55 template<
typename T,
typename... Args>
56 T& addComponent(Args&& ...args) {
57 static_assert(!CComponentHasTransform<T>,
"Adding components to a scene that require a transform will break horribly!");
58 runtime_assert(!this->hasComponent<T>(),
"Scene already has this component!");
59 return this->getRegistry().emplace<T>(this->handle, std::forward<Args>(args)...);
63 void addTagComponent() {
64 runtime_assert(!this->hasComponent<T>(),
"Scene already has this component!");
65 this->getRegistry().emplace<T>(this->handle);
69 [[nodiscard]] T& getComponent() {
70 runtime_assert(this->hasComponent<T>(),
"Scene doesn't have this component!");
71 return this->getRegistry().get<T>(this->handle);
75 [[nodiscard]]
const T& getComponent()
const {
76 runtime_assert(this->hasComponent<T>(),
"Scene doesn't have this component!");
77 return this->getRegistry().get<T>(this->handle);
81 [[nodiscard]] T* tryGetComponent() {
82 return this->getRegistry().try_get<T>(this->handle);
86 [[nodiscard]]
const T* tryGetComponent()
const {
87 return this->getRegistry().try_get<T>(this->handle);
91 [[nodiscard]]
bool hasComponent()
const {
92 return this->getRegistry().all_of<T>(this->handle);
96 void tryRemoveComponent() {
97 this->getRegistry().remove<T>(this->handle);
101 void removeComponent() {
102 runtime_assert(this->hasComponent<T>(),
"Scene doesn't have this component!");
103 this->getRegistry().erase<T>(this->handle);
108 void setupForRender(glm::vec2i size);
110 [[nodiscard]] entt::registry& getRegistry();
112 [[nodiscard]]
const entt::registry& getRegistry()
const;
114 [[nodiscard]] std::string getName()
const {
115 if (
auto nameComponent = this->getRegistry().try_get<NameComponent>(this->handle)) {
116 return nameComponent->name;
118 return uuids::to_string(this->getRegistry().get<UUIDComponent>(this->handle).uuid);
121 [[nodiscard]] uuids::uuid getUUID()
const {
122 return this->getRegistry().get<
UUIDComponent>(this->handle).uuid;
125 [[nodiscard]] entt::entity getRawHandle()
const {
129 bool operator==(
const Scene& other)
const {
130 return this->handle == other.handle;
133 bool operator!=(
const Scene& other)
const {
134 return !(*
this == other);
138 std::unordered_map<uuids::uuid, std::unique_ptr<Entity>> entities;
139 entt::registry registry;