Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Node Class Reference

#include <node.hpp>

Inheritance diagram for Node:

Public Member Functions

 Node (const std::string &name="Node")
 
virtual ~Node ()
 
void free ()
 
NodegetOwner ()
 
std::shared_ptr< WindowgetWindow ()
 
void setWindow (std::shared_ptr< Window > window)
 
void addChild (std::shared_ptr< Node > child)
 
void removeChild (std::shared_ptr< Node > child)
 
std::shared_ptr< NodegetChild (std::string name)
 
std::shared_ptr< NodegetChildByIndex (int index)
 
void addComponent (std::shared_ptr< Component > component)
 
void removeComponent (std::shared_ptr< Component > component)
 
template<typename T >
std::shared_ptr< TgetComponent ()
 
std::shared_ptr< ComponentgetComponentByIndex (int index)
 
virtual void render (Graphics &graphics, Engine *engine, std::shared_ptr< Window > window) const
 
virtual void update (float deltaTime)
 
virtual void physicsUpdate () const
 
virtual void initialize ()
 
virtual void postLoad ()
 
virtual void input (InputEvent &event)
 
virtual void exit () const
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

std::string name
 
Transform transform
 
Transform globalTransform
 
Nodeparent
 
std::vector< std::shared_ptr< Node > > children
 
std::vector< std::shared_ptr< Component > > components
 

Detailed Description

Base node class

Everything in Calamity Engine is composed of nodes. An analogy would be that a node is like a GameObject in Unity. It can have components, children, and a transform. It also has a name for easy identification and lookup. The node class is responsible for updating and rendering itself and its children, as well as managing its components.

It has methods available for adding and removing children and components, as well as getting them by name/index. Here is an example of a node with a sprite component and a script component:

std::shared_ptr<Node> node = std::make_shared<Node>("My Node");
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>();
node->addComponent(sprite);
node->addComponent(std::make_shared<MyScript>());

Constructor & Destructor Documentation

◆ Node()

Node::Node ( const std::string &  name = "Node")

◆ ~Node()

Node::~Node ( )
virtual

Member Function Documentation

◆ addChild()

void Node::addChild ( std::shared_ptr< Node child)

◆ addComponent()

void Node::addComponent ( std::shared_ptr< Component component)

◆ exit()

void Node::exit ( ) const
virtual

◆ free()

void Node::free ( )

◆ getChild()

std::shared_ptr< Node > Node::getChild ( std::string  name)

◆ getChildByIndex()

std::shared_ptr< Node > Node::getChildByIndex ( int  index)

◆ getComponent()

template<typename T >
std::shared_ptr< T > Node::getComponent ( )
inline

◆ getComponentByIndex()

std::shared_ptr< Component > Node::getComponentByIndex ( int  index)

◆ getOwner()

Node * Node::getOwner ( )

◆ getWindow()

std::shared_ptr< Window > Node::getWindow ( )

◆ initialize()

void Node::initialize ( )
virtual

◆ input()

void Node::input ( InputEvent event)
virtual

◆ load()

template<class Archive >
void Node::load ( Archive &  ar)
inline

◆ physicsUpdate()

void Node::physicsUpdate ( ) const
virtual

◆ postLoad()

void Node::postLoad ( )
virtual

◆ removeChild()

void Node::removeChild ( std::shared_ptr< Node child)

◆ removeComponent()

void Node::removeComponent ( std::shared_ptr< Component component)

◆ render()

void Node::render ( Graphics graphics,
Engine engine,
std::shared_ptr< Window window 
) const
virtual

◆ save()

template<class Archive >
void Node::save ( Archive &  ar) const
inline

◆ setWindow()

void Node::setWindow ( std::shared_ptr< Window window)

◆ update()

void Node::update ( float  deltaTime)
virtual

Member Data Documentation

◆ children

std::vector<std::shared_ptr<Node> > Node::children

◆ components

std::vector<std::shared_ptr<Component> > Node::components

◆ globalTransform

Transform Node::globalTransform

◆ name

std::string Node::name

◆ parent

Node* Node::parent

◆ transform

Transform Node::transform

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