Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Component Class Referenceabstract

Base Class for all components. More...

#include <component.h>

Inheritance diagram for Component:
Events::Subject Events::Observer Game::SpriteMovement Graphics::Camera Graphics::Light Graphics::Renderable Graphics::TileAnimator< StateType > Graphics::UI::Text Physics::CollisionData Sound::SoundInstance

Public Member Functions

 Component ()
 Component constructor. More...
 
virtual void onStart ()=0
 Called when the engine starts and when a new scene is loaded. More...
 
virtual bool onUpdate (const double delta)=0
 Called every engine loop. More...
 
virtual void onDestroy ()=0
 Called when the engine is shutting down. More...
 
void setTransform (std::shared_ptr< Transform > transform)
 Sets the transform. More...
 
std::shared_ptr< TransformgetTransform () const noexcept
 Gets the transform. More...
 
void setActive (const bool active) noexcept
 Sets the component active or inactive. More...
 
bool isActive () const noexcept
 Determines if active. More...
 
unsigned int getId () const noexcept
 Gets the identifier. More...
 
virtual std::string to_string () const noexcept
 Returns a string representation of the object. More...
 
virtual std::string className () const noexcept
 Returns a string representing the class name. More...
 
virtual unsigned long long getValueForSorting () const =0
 Gets the value for sorting. More...
 
bool operator< (Component &other) noexcept
 Operator < using getValueForSorting. More...
 
virtual void onNotifyNow (std::shared_ptr< Events::Event > event) override
 When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure the object is notified before another engine loop. This is pure virtual and is implemented on a case by case basis in derived classes. More...
 
virtual void handleQueuedEvent (std::shared_ptr< Events::Event > event) override
 HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received. More...
 
virtual void log (el::base::type::ostream_t &os) const override
 
virtual ~Component ()
 Destroys the object. More...
 
- Public Member Functions inherited from Events::Subject
virtual ~Subject ()=default
 
virtual void notify (std::shared_ptr< Event > event)
 notify is used to tell observers of an event. More...
 
virtual void notifyNow (std::shared_ptr< Event > event)
 notifyNow is used to tell observers of an event as an interrupt. More...
 
virtual void addObserver (std::shared_ptr< Observer > observer)
 Adds an observer. More...
 
virtual void removeObserver (std::shared_ptr< Observer > observer)
 Removes an observer. More...
 
- Public Member Functions inherited from Events::Observer
virtual ~Observer ()
 
void onNotify (std::shared_ptr< Event > event)
 When receiving an event that is non-immediate, onNotify is used. The event is added to the event queue that is processed when processEventQueue is called. More...
 
void processEventQueue ()
 This should be called once ever loop for every Observer to properly use queued events. More...
 

Protected Attributes

std::weak_ptr< Entityentity
 
std::shared_ptr< Transformtransform
 
bool active
 
unsigned int id
 

Static Protected Attributes

static unsigned int next_id = 0
 

Friends

class ComponentManager
 
class Entity
 

Additional Inherited Members

- Protected Member Functions inherited from Events::Observer
std::shared_ptr< EventgetEvent ()
 
bool eventsWaiting () const noexcept
 

Detailed Description

Base Class for all components.

Constructor & Destructor Documentation

Component::Component ( )

Component constructor.

References next_id, and transform.

virtual Component::~Component ( )
inlinevirtual

Destroys the object.

Member Function Documentation

virtual unsigned long long Component::getValueForSorting ( ) const
pure virtual
bool Component::isActive ( ) const
noexcept
void Component::onNotifyNow ( std::shared_ptr< Events::Event event)
overridevirtual

When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure the object is notified before another engine loop. This is pure virtual and is implemented on a case by case basis in derived classes.

Parameters
[in]eventThe event

Implements Events::Observer.

Reimplemented in Game::SpriteMovement, Graphics::Renderable, Graphics::TileAnimator< StateType >, Graphics::Camera, Graphics::UI::Element, Graphics::UI::Text, Graphics::UI::WrappableText, Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Area, Graphics::UI::Button, and Sound::SoundInstance.

References handleQueuedEvent().

virtual bool Component::onUpdate ( const double  delta)
pure virtual
bool Component::operator< ( Component other)
noexcept

Operator < using getValueForSorting.

Parameters
otherThe other
Returns
true if this shoule be sorted before other
void Component::setActive ( const bool  active)
noexcept

Sets the component active or inactive.

Parameters
[in]activeTrue if active

Referenced by generated::getComponentModule(), handleQueuedEvent(), and Graphics::UI::TextField::onKeyDown().

void Component::setTransform ( std::shared_ptr< Transform transform)

Sets the transform.

Parameters
[in]transformThe transform

References transform.

Referenced by generated::getComponentModule().

Friends And Related Function Documentation

friend class ComponentManager
friend
friend class Entity
friend

Member Data Documentation

std::weak_ptr<Entity> Component::entity
protected

Referenced by handleQueuedEvent().

unsigned int Component::id
protected

Referenced by getId().

unsigned int Component::next_id = 0
staticprotected

Referenced by Component().

std::shared_ptr<Transform> Component::transform
protected

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