DarkflameServer/dGame/dComponents/Component.h

60 lines
1.3 KiB
C
Raw Normal View History

#pragma once
namespace tinyxml2 {
class XMLDocument;
}
namespace RakNet {
class BitStream;
}
class Entity;
/**
* Component base class, provides methods for game loop updates, usage events and loading and saving to XML.
*/
class Component {
public:
Component(Entity* parent) : m_Parent{ parent } {}
virtual ~Component() = default;
2022-07-28 13:39:57 +00:00
/**
* Gets the owner of this component
* @return the owner of this component
*/
Entity* GetParent() const { return m_Parent; }
2022-07-28 13:39:57 +00:00
/**
* Updates the component in the game loop
* @param deltaTime time passed since last update
*/
virtual void Update(float deltaTime) {}
2022-07-28 13:39:57 +00:00
/**
* Event called when this component is being used, e.g. when some entity interacted with it
* @param originator
*/
virtual void OnUse(Entity* originator) {}
2022-07-28 13:39:57 +00:00
/**
* Save data from this componennt to character XML
* @param doc the document to write data to
*/
virtual void UpdateXml(tinyxml2::XMLDocument& doc) {}
2022-07-28 13:39:57 +00:00
/**
* Load base data for this component from character XML
* @param doc the document to read data from
*/
virtual void LoadFromXml(const tinyxml2::XMLDocument& doc) {}
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {}
protected:
2022-07-28 13:39:57 +00:00
/**
* The entity that owns this component
*/
Entity* m_Parent;
};