2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-12-18 08:45:56 +00:00
|
|
|
namespace tinyxml2 {
|
|
|
|
class XMLDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace RakNet {
|
|
|
|
class BitStream;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
class Entity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component base class, provides methods for game loop updates, usage events and loading and saving to XML.
|
|
|
|
*/
|
2024-01-24 05:13:23 +00:00
|
|
|
class Component {
|
2021-12-05 17:54:36 +00:00
|
|
|
public:
|
2024-12-18 08:45:56 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-12-18 08:45:56 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-12-18 08:45:56 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-12-18 08:45:56 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-12-18 08:45:56 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-12-18 08:45:56 +00:00
|
|
|
virtual void LoadFromXml(const tinyxml2::XMLDocument& doc) {}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-18 08:45:56 +00:00
|
|
|
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {}
|
2023-08-10 21:33:15 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
protected:
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The entity that owns this component
|
|
|
|
*/
|
|
|
|
Entity* m_Parent;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|