VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::GameObject Class Reference

Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it. More...

#include <GameObject.hpp>

Inheritance diagram for vex::GameObject:
vex::BasicCamera vex::CameraObject vex::FogObject vex::LightObject vex::ModelObject EditorCameraObject

Public Member Functions

 GameObject (Engine &engine, const std::string &name)
 Default constructor for GameObject.
void Destroy ()
 Destroys the GameObject and removes it from the engine's registry.
virtual ~GameObject ()
 Destructor.
 GameObject (const GameObject &)=delete
GameObjectoperator= (const GameObject &)=delete
 GameObject (GameObject &&other) noexcept
virtual void BeginPlay ()
 virtual void function you override to implement custom behavior when the game starts.
virtual void Update (float deltaTime)
 virtual void function you override to implement custom behavior when the game updates (eg. every frame).
vex::Entity GetEntity () const
 Function that returns entity object, which is the entity associated with this GameObject. Its mostly needed for parenting and other engine internal usage.
EngineGetEngine ()
 Function that returns engine reference allowing your custom Object to use engine provided methods.
template<typename T>
T & GetComponent ()
 Function that returns reference to a requested component.
template<typename T>
void AddComponent (const T &comp)
 Function that adds a component to the GameObject.
template<typename T>
bool HasComponent () const
 Function that checks if the GameObject has a component.
bool isValid () const
void ParentTo (vex::Entity entity)
 Function that parent this Object to another GameObject. You need to pass another GameObject's entity.
void setObjectType (const std::string &type)
 Function that sets the type of the GameObject.
const std::string & getObjectType () const
 Function that returns the type of the GameObject.

Protected Attributes

Enginem_engine
vex::Entity m_entity
bool m_isValid
std::string objectType

Detailed Description

Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it.

Example:

class Player : public GameObject {
public:
Player(Engine& engine, const std::string& name)
: GameObject(engine, name) {
// Initialize player-specific components
}
};
Class for interaction with engine systems.
Definition Engine.hpp:47
GameObject(Engine &engine, const std::string &name)
Default constructor for GameObject.

This class serves as the foundation for all game objects within the engine. It provides essential functionalities such as entity management, name registration, and basic component initialization.

Definition at line 31 of file GameObject.hpp.

Constructor & Destructor Documentation

◆ GameObject() [1/2]

vex::GameObject::GameObject ( Engine & engine,
const std::string & name )

Default constructor for GameObject.

  1. Initializes the engine reference and marks object as valid.
  2. Creates a new vex::Entity in the registry.
  3. Adds a NameComponent.
  4. Automatically registers the object with the current scene via SceneManager::GetScene(lastSceneName).
    Parameters
    Engine&engine - Reference to the engine instance.
    conststd::string& name - Unique name for the game object.

Definition at line 10 of file GameObject.cpp.

◆ ~GameObject()

vex::GameObject::~GameObject ( )
virtual

Destructor.

Calls Destroy() to ensure cleanup.

Definition at line 39 of file GameObject.cpp.

◆ GameObject() [2/2]

vex::GameObject::GameObject ( GameObject && other)
inlinenoexcept

Definition at line 57 of file GameObject.hpp.

Member Function Documentation

◆ AddComponent()

template<typename T>
void vex::GameObject::AddComponent ( const T & comp)
inline

Function that adds a component to the GameObject.

Definition at line 80 of file GameObject.hpp.

◆ BeginPlay()

virtual void vex::GameObject::BeginPlay ( )
inlinevirtual

virtual void function you override to implement custom behavior when the game starts.

Reimplemented in vex::BasicCamera.

Definition at line 64 of file GameObject.hpp.

◆ Destroy()

void vex::GameObject::Destroy ( )

Destroys the GameObject and removes it from the engine's registry.

  1. Checks validity to prevent double deletion.
  2. Iterates TransformComponents to find children and unparents them (sets parent to vex::NULL_ENTITY).
  3. Destroys the entity in the registry and marks this object as invalid.

Definition at line 20 of file GameObject.cpp.

◆ GetComponent()

template<typename T>
T & vex::GameObject::GetComponent ( )
inline

Function that returns reference to a requested component.

Returns
Requested component reference eg. InputComponent.

Definition at line 78 of file GameObject.hpp.

◆ GetEngine()

Engine & vex::GameObject::GetEngine ( )
inline

Function that returns engine reference allowing your custom Object to use engine provided methods.

Example usage:

void setResolutionMode(ResolutionMode mode)
Sets the resolution mode and updates the resolution manager.
Definition Engine.cpp:238
Engine & GetEngine()
Function that returns engine reference allowing your custom Object to use engine provided methods.
@ PS1_SHARP
Integer-scaled resolution closest to PS1.

You could technically just use m_engine but its highly discarded as it can lead to confusion and potential bugs.

Definition at line 75 of file GameObject.hpp.

◆ GetEntity()

vex::Entity vex::GameObject::GetEntity ( ) const
inline

Function that returns entity object, which is the entity associated with this GameObject. Its mostly needed for parenting and other engine internal usage.

Definition at line 68 of file GameObject.hpp.

◆ getObjectType()

const std::string & vex::GameObject::getObjectType ( ) const
inline

Function that returns the type of the GameObject.

Returns
Type of the GameObject.

Definition at line 106 of file GameObject.hpp.

◆ HasComponent()

template<typename T>
bool vex::GameObject::HasComponent ( ) const
inline

Function that checks if the GameObject has a component.

Returns
True if the GameObject has the component, false otherwise.

Definition at line 83 of file GameObject.hpp.

◆ isValid()

bool vex::GameObject::isValid ( ) const
inline

Definition at line 84 of file GameObject.hpp.

◆ ParentTo()

void vex::GameObject::ParentTo ( vex::Entity entity)
inline

Function that parent this Object to another GameObject. You need to pass another GameObject's entity.

Parameters
vex::Entityentity - Entity of GameObject we want to parent to.

Helper function that retrieves the TransformComponent of this object and calls setParent with the provided entity ID.

GameObject* parent = new GameObject();
GameObject* child = new GameObject();
child->ParentTo(parent->GetEntity());
vex::Entity GetEntity() const
Function that returns entity object, which is the entity associated with this GameObject....
void ParentTo(vex::Entity entity)
Function that parent this Object to another GameObject. You need to pass another GameObject's entity.

Definition at line 94 of file GameObject.hpp.

◆ setObjectType()

void vex::GameObject::setObjectType ( const std::string & type)
inline

Function that sets the type of the GameObject.

Parameters
type- Type of the GameObject.

Definition at line 100 of file GameObject.hpp.

◆ Update()

virtual void vex::GameObject::Update ( float deltaTime)
inlinevirtual

virtual void function you override to implement custom behavior when the game updates (eg. every frame).

Reimplemented in EditorCameraObject, and vex::BasicCamera.

Definition at line 66 of file GameObject.hpp.

Member Data Documentation

◆ m_engine

Engine& vex::GameObject::m_engine
protected

Definition at line 109 of file GameObject.hpp.

◆ m_entity

vex::Entity vex::GameObject::m_entity
protected

Definition at line 110 of file GameObject.hpp.

◆ m_isValid

bool vex::GameObject::m_isValid
protected

Definition at line 111 of file GameObject.hpp.

◆ objectType

std::string vex::GameObject::objectType
protected

Definition at line 112 of file GameObject.hpp.


The documentation for this class was generated from the following files: