#pragma once #include "DeerCore/Tools/Memory.h" #include "DeerCore/Tools/SmallVector.h" #define GLM_ENABLE_EXPERIMENTAL #include #include #include #include #include "DeerCore/Log.h" #include "glm/glm.hpp" #include "glm/gtc/quaternion.hpp" #define ENTITY_BUFFER_CHILDREN 8 // Here we define the core components of the ECS namespace Deer { class ComponentScriptInstance; struct TagComponent { std::string tag; uint32_t entityUID; TagComponent() = default; TagComponent(const TagComponent&) = default; TagComponent(std::string name, uint32_t _id = 0) : tag(name), entityUID(_id) {} }; struct RelationshipComponent { u_int32_t parent_id = 0; // Use p-ranav's small_vector for children storage // Inline capacity ENTITY_MAX_CHILDREN, fallback to heap if exceeded ankerl::svector children; inline u_int32_t getChildId(size_t i) const { DEER_CORE_ASSERT(i < children.size() && children[i] != 0, "Invalid child request {0}", i); return children[i]; } inline void addChildId(u_int32_t childId) { // Prevent duplicates for (auto id : children) if (id == childId) return; children.push_back(childId); } inline bool removeChild(u_int32_t childId) { for (size_t i = 0; i < children.size(); ++i) { if (children[i] == childId) { // Swap-remove for O(1) std::swap(children[i], children.back()); children.pop_back(); return true; } } return false; } inline size_t getChildCount() const { return children.size(); } RelationshipComponent() = default; RelationshipComponent(const RelationshipComponent&) = default; RelationshipComponent(u_int32_t _parent) : parent_id(_parent) {} }; struct TransformComponent { glm::vec3 position = glm::vec3(0.0f); glm::vec3 scale = glm::vec3(1.0f); glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f); TransformComponent() = default; TransformComponent(glm::vec3 _position) : position(_position) {} TransformComponent(const TransformComponent&) = default; inline const glm::vec3 getEulerAngles() { return glm::degrees(glm::eulerAngles(rotation)); } inline void setEulerAngles(const glm::vec3& eulerAngles) { rotation = glm::quat(glm::radians(eulerAngles)); } glm::mat4 getMatrix() const; }; } // namespace Deer