CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::EntityScript Class Reference

#include <CeresEngine/Scripting/EntityScript.hpp>

Public Member Functions

virtual ~EntityScript ()=default
 
virtual void onCreate ()
 A function called by the runtime whenever the script is first created.
 
virtual void update (double dt)
 A function called by the runtime every update iteration.
 
virtual void onDestroy ()
 A function called by the runtime whenever the script is destroyed.
 
template<CComponent C, typename... Args>
Cadd (Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Adds a new component.
 
template<CComponent C, typename Block , typename... Args>
CaddWith (Block &&block, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Adds a new component and calls block with the added component.
 
template<CComponent C, typename... Args>
Cset (Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Sets a component.
 
template<CComponent C>
void remove () noexcept(std::is_nothrow_destructible_v< C >)
 Removes a component of type C from the entity.
 
template<CComponent C>
Cget () noexcept
 Gets a component of type C.
 
template<CComponent C>
const Cget () const noexcept
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > get () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 &, const C1 &, const Cs &... > get () const noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C>
CgetOr () noexcept(std::is_nothrow_constructible_v< C >)
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > getOr () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C>
CgetIf () noexcept
 Gets a component of type C.
 
template<CComponent C>
const CgetIf () const noexcept
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 *, C1 *, Cs *... > getIf () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 *, const C1 *, const Cs *... > getIf () const noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C, CComponent... Cs>
bool has () const noexcept
 Checks if the entity has all components of types Cs.
 

Protected Attributes

Entity mEntity
 The entity associated with this script instance.
 

Friends

class ScriptingSystem
 

Constructor & Destructor Documentation

◆ ~EntityScript()

virtual CeresEngine::EntityScript::~EntityScript ( )
virtualdefault

Member Function Documentation

◆ add()

template<CComponent C, typename... Args>
C & CeresEngine::EntityScript::add ( Args &&...  args)
inlinenoexcept

Adds a new component.

If a component of type C is already present, this method throws.

Template Parameters
Cthe component type to be added
Argsthe component constructor argument types
Parameters
argsThe component constructor arguments
Returns
A reference to the newly added component

◆ addWith()

template<CComponent C, typename Block , typename... Args>
C & CeresEngine::EntityScript::addWith ( Block &&  block,
Args &&...  args 
)
inlinenoexcept

Adds a new component and calls block with the added component.

If a component of type C is already present, this method throws.

Template Parameters
Cthe component type to be added
Blockthe block type
Argsthe component constructor argument types
Parameters
blockThe block to be called
argsThe component constructor arguments
Returns
A reference to the newly added component

◆ get() [1/4]

template<CComponent C>
const C & CeresEngine::EntityScript::get ( ) const
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, this method throws.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ get() [2/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 &, const C1 &, const Cs &... > CeresEngine::EntityScript::get ( ) const
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, this method throws.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ get() [3/4]

template<CComponent C>
C & CeresEngine::EntityScript::get ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, this method throws.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ get() [4/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > CeresEngine::EntityScript::get ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, this method throws.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing component

◆ getIf() [1/4]

template<CComponent C>
const C * CeresEngine::EntityScript::getIf ( ) const
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, nullptr is returned

Template Parameters
Cthe component type to be retrieved
Returns
A pointer to the existing component

◆ getIf() [2/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 *, const C1 *, const Cs *... > CeresEngine::EntityScript::getIf ( ) const
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, nullptr is returned.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getIf() [3/4]

template<CComponent C>
C * CeresEngine::EntityScript::getIf ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, nullptr is returned

Template Parameters
Cthe component type to be retrieved
Returns
A pointer to the existing component

◆ getIf() [4/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 *, C1 *, Cs *... > CeresEngine::EntityScript::getIf ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, nullptr is returned.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getOr() [1/2]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > CeresEngine::EntityScript::getOr ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, a new component is created.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getOr() [2/2]

template<CComponent C>
C & CeresEngine::EntityScript::getOr ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, a new component is created.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ has()

template<CComponent C, CComponent... Cs>
bool CeresEngine::EntityScript::has ( ) const
inlinenoexcept

Checks if the entity has all components of types Cs.

Template Parameters
Csthe component types to be checked
Returns
True if the components are present, false otherwise

◆ onCreate()

virtual void CeresEngine::EntityScript::onCreate ( )
inlinevirtual

A function called by the runtime whenever the script is first created.

◆ onDestroy()

virtual void CeresEngine::EntityScript::onDestroy ( )
inlinevirtual

A function called by the runtime whenever the script is destroyed.

◆ remove()

template<CComponent C>
void CeresEngine::EntityScript::remove ( )
inlinenoexcept

Removes a component of type C from the entity.

Template Parameters
Cthe component type to be removed

◆ set()

template<CComponent C, typename... Args>
C & CeresEngine::EntityScript::set ( Args &&...  args)
inlinenoexcept

Sets a component.

If a component of type C is already present, a new component is created and added. If the component already exists, its contents are replaced.

Template Parameters
Cthe component type to be set
Argsthe component constructor argument types
Parameters
argsthe component constructor arguments
Returns
A reference to the newly added or replaced component

◆ update()

virtual void CeresEngine::EntityScript::update ( double  dt)
inlinevirtual

A function called by the runtime every update iteration.

Parameters
dtThe number of seconds elapsed since the last call.

Friends And Related Symbol Documentation

◆ ScriptingSystem

Member Data Documentation

◆ mEntity

Entity CeresEngine::EntityScript::mEntity
protected

The entity associated with this script instance.


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