Nui Engine
A game engine framework
Loading...
Searching...
No Matches
Component.h
1#pragma once
2#include "Core/Engine/ECS/Common.h"
3
4namespace Nui::ECS
5{
6 namespace Internal
7 {
12 {
16 virtual ~ComponentContainerBase() = default;
17
22 virtual void OnRemove(Entity* entity) = 0;
23 };
24
29 template <typename T>
31 {
32 T m_data;
33
34 ComponentContainer() = default;
35 ComponentContainer(const T& data) : m_data(data) {}
36
37 protected:
42 virtual void OnRemove(Entity* entity) override;
43 };
44 }
45
50 template <typename T>
52 {
53 public:
54 ComponentHandle() : m_component(nullptr) {}
55 ComponentHandle(T* component) : m_component(component) {}
56
61 bool IsValid() const noexcept { return m_component != nullptr; }
62
67 T& Get() const noexcept { return *m_component; }
68
73 T* operator->() const { return m_component; }
74
78 operator bool() const { return IsValid(); }
79
80 private:
84 T* m_component;
85 };
86}
This class provides a handle to a component.
Definition Component.h:52
T * operator->() const
Get the component.
Definition Component.h:73
T & Get() const noexcept
Get the component.
Definition Component.h:67
bool IsValid() const noexcept
Checks if the component is valid.
Definition Component.h:61
Class to represent an entity in an ECS Context.
Definition Entity.h:10
Abstract base class for component containers.
Definition Component.h:12
virtual void OnRemove(Entity *entity)=0
Pure virtual method called when an entity is removed.
virtual ~ComponentContainerBase()=default
Virtual destructor.
Template class for component containers (concrete implementation of ComponentContainerBase)
Definition Component.h:31
virtual void OnRemove(Entity *entity) override
Method called when an entity is removed.
Definition ECS.h:142