feat: Add component ID to root component object

This commit is contained in:
David Markowitz
2025-10-02 01:32:50 -07:00
parent 670cb124c0
commit dbb6e3e0b8
106 changed files with 263 additions and 259 deletions

View File

@@ -19,7 +19,7 @@ class Entity;
*/
class Component {
public:
Component(Entity* parent) : m_Parent{ parent } {}
Component(Entity* parent, const int32_t componentID) : m_Parent{ parent }, m_ComponentID{componentID} {}
virtual ~Component() = default;
/**
@@ -28,6 +28,8 @@ public:
*/
Entity* GetParent() const { return m_Parent; }
[[nodiscard]] int32_t GetComponentID() const noexcept { return m_ComponentID; }
/**
* Updates the component in the game loop
* @param deltaTime time passed since last update
@@ -70,4 +72,11 @@ protected:
* The entity that owns this component
*/
Entity* m_Parent;
// The component ID, this should never be changed after initialization
// This is used in various different ways
// 1. To identify which entry this component is in its corresponding table
// 2. To mark that an Entity should have the component with no database entry (it will be 0 in this case)
// 3. The component exists implicitly due to design (CollectibleComponent always has a DestructibleComponent accompanying it). In this case the ID will be -1.
const int32_t m_ComponentID;
};