Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Component.h File Reference

Abstract base for all GameObject components and the COMPONENT macro. More...

#include "Types.h"
#include "nlohmann/json.hpp"
+ Include dependency graph for Component.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mnd::Component
 
class  mnd::ComponentCreatorBase
 
class  mnd::ComponentCreator< T >
 
class  mnd::ComponentFactory
 

Namespaces

namespace  mnd
 

Macros

#define COMPONENT(ComponentClass)
 

Detailed Description

Abstract base for all GameObject components and the COMPONENT macro.

Entity-Component pattern

A GameObject is a named scene node with a transform. Behaviour and rendering are added by attaching Component subclasses. Each component type gets a unique numeric ID at runtime so that typed lookup via GameObject::GetComponent<T>() works in O(n) without RTTI.

Adding a new component type

  1. Subclass Component.
  2. Place the COMPONENT(MyComponent) macro at the top of the public section.
  3. Implement Update(f32 deltaTime).
  4. Attach via GameObject::AddComponent(new MyComponent(...)).
class SpinComponent : public mnd::Component {
COMPONENT(SpinComponent)
public:
void Update(mnd::f32 dt) override { m_owner->SetRotation(...); }
};
virtual void Update(f32 deltaTime)=0
#define COMPONENT(ComponentClass)
Definition Component.h:105
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40
See also
GameObject::AddComponent, GameObject::GetComponent, COMPONENT

Definition in file Component.h.

Macro Definition Documentation

◆ COMPONENT

#define COMPONENT (   ComponentClass)
Value:
public: \
static size_t TypeId() \
{ \
return mnd::Component::StaticTypeId<ComponentClass>(); \
} \
size_t GetTypeId() const override \
{ \
return TypeId(); \
} \
static void Register() \
{ \
mnd::ComponentFactory::GetInstance().RegisterComponent<ComponentClass>(std::string(#ComponentClass)); \
}

Definition at line 105 of file Component.h.