VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
GameObject.hpp
Go to the documentation of this file.
1
6
7#pragma once
9 //#include <nlohmann/json.hpp>
10
11 #include "Engine.hpp"
12 #include "components/ErrorUtils.hpp"
13
15 #include "../../../thirdparty/uuid/UUID.hpp"
16
17 namespace vex {
18
31 class GameObject {
32 public:
41 GameObject(Engine& engine, const std::string& name);
42
48 void Destroy();
49
52 virtual ~GameObject();
53
54 GameObject(const GameObject&) = delete;
55 GameObject& operator=(const GameObject&) = delete;
56
57 GameObject(GameObject&& other) noexcept
58 : m_engine(other.m_engine), m_entity(other.m_entity), m_isValid(other.m_isValid) {
59 other.m_entity = vex::NULL_ENTITY;
60 other.m_isValid = false;
61 }
62
64 virtual void BeginPlay() {}
66 virtual void Update(float deltaTime) {}
68 vex::Entity GetEntity() const { return m_entity; }
75 Engine& GetEngine() { return m_engine; }
78 template<typename T> T& GetComponent() { return m_engine.getRegistry().get<T>(m_entity); }
80 template<typename T> void AddComponent(const T& comp) { m_engine.getRegistry().add_or_replace<T>(m_entity, comp); }
83 template<typename T> bool HasComponent() const { return m_engine.getRegistry().has<T>(m_entity); }
84 bool isValid() const { return m_isValid; }
85
94 void ParentTo(vex::Entity entity){
95 GetComponent<TransformComponent>().setParent(entity);
96 }
97
100 void setObjectType(const std::string& type) {
101 objectType = type;
102 }
103
106 const std::string& getObjectType() const { return objectType; }
107
108 protected:
109 Engine& m_engine;
110 vex::Entity m_entity;
111 bool m_isValid;
112 std::string objectType;
113 };
114 }
Contains basic components like transform, camera, name components..
Main header for the Entity Component System (ECS) framework.
Contains main Engine class.
Class for interaction with engine systems.
Definition Engine.hpp:47
bool HasComponent() const
Function that checks if the GameObject has a component.
void Destroy()
Destroys the GameObject and removes it from the engine's registry.
vex::Entity GetEntity() const
Function that returns entity object, which is the entity associated with this GameObject....
virtual void BeginPlay()
virtual void function you override to implement custom behavior when the game starts.
void ParentTo(vex::Entity entity)
Function that parent this Object to another GameObject. You need to pass another GameObject's entity.
T & GetComponent()
Function that returns reference to a requested component.
GameObject(Engine &engine, const std::string &name)
Default constructor for GameObject.
virtual ~GameObject()
Destructor.
Engine & GetEngine()
Function that returns engine reference allowing your custom Object to use engine provided methods.
void AddComponent(const T &comp)
Function that adds a component to the GameObject.
const std::string & getObjectType() const
Function that returns the type of the GameObject.
void setObjectType(const std::string &type)
Function that sets the type of the GameObject.
virtual void Update(float deltaTime)
virtual void function you override to implement custom behavior when the game updates (eg....
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11
constexpr Entity NULL_ENTITY
Special entity value indicating an invalid or null entity.
Definition Types.hpp:15