VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
GameObject.cpp
1// GameObject.cpp
6#include "../../../thirdparty/uuid/UUID.hpp"
7
8namespace vex {
9
10 GameObject::GameObject(Engine& engine, const std::string& name)
11 : m_engine(engine), m_entity(m_engine.getRegistry().create()), m_isValid(true)
12 {
13 m_engine.getRegistry().add_or_replace<NameComponent>(m_entity, name);
14 auto* scene = m_engine.getSceneManager()->GetScene(m_engine.getSceneManager()->getLastSceneName());
15 if(scene){
16 scene->RegisterGameObject(this);
17 }
18 }
19
21 if (!m_isValid) return;
22
23 log("[GameObject] Destroying entity ID: %d", (int)m_entity);
24
25 if (m_engine.getRegistry().has<TransformComponent>(m_entity)) {
26 vex::View<TransformComponent> view(m_engine.getRegistry());
27 view.each([this](vex::Entity entity, TransformComponent& transform) {
28 if (transform.getParent() == m_entity) {
29 transform.setParent(vex::NULL_ENTITY);
30 }
31 });
32 m_engine.getRegistry().destroy(m_entity);
33 }
34
35 m_entity = vex::NULL_ENTITY;
36 m_isValid = false;
37 }
38
42}
Contains basic components like transform, camera, name components..
This file defines the GameObject class.
This file defines SceneManager class.
This file defines SceneManager class.
Class for interaction with engine systems.
Definition Engine.hpp:47
void Destroy()
Destroys the GameObject and removes it from the engine's registry.
GameObject(Engine &engine, const std::string &name)
Default constructor for GameObject.
virtual ~GameObject()
Destructor.
Provides iteration over entities that have all specified component types.
Definition View.hpp:17
void each(Func func)
Iterates over all entities with the specified component types.
Definition View.hpp:40
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
constexpr Entity NULL_ENTITY
Special entity value indicating an invalid or null entity.
Definition Types.hpp:15
Struct containing transform data and methods.
void setParent(vex::Entity newParent)
Set the parent entity.
vex::Entity getParent() const
Get the parent entity.