2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-07 01:59:53 +00:00
|
|
|
#include "tinyxml2.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
class Entity;
|
|
|
|
|
2023-06-07 03:48:30 +00:00
|
|
|
namespace RakNet {
|
|
|
|
class BitStream;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Component base class, provides methods for game loop updates, usage events and loading and saving to XML.
|
|
|
|
*/
|
2023-06-07 01:59:53 +00:00
|
|
|
class Component {
|
2021-12-05 17:54:36 +00:00
|
|
|
public:
|
2023-06-07 01:59:53 +00:00
|
|
|
Component(Entity* owningEntity);
|
2022-07-28 13:39:57 +00:00
|
|
|
virtual ~Component();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the owner of this component
|
|
|
|
* @return the owner of this component
|
|
|
|
*/
|
2023-06-09 08:28:01 +00:00
|
|
|
Entity* GetParentEntity() const { return m_OwningEntity; };
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save data from this componennt to character XML
|
|
|
|
* @param doc the document to write data to
|
|
|
|
*/
|
|
|
|
virtual void UpdateXml(tinyxml2::XMLDocument* doc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load base data for this component from character XML
|
|
|
|
* @param doc the document to read data from
|
|
|
|
*/
|
|
|
|
virtual void LoadFromXml(tinyxml2::XMLDocument* doc);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-07 01:59:53 +00:00
|
|
|
/**
|
|
|
|
* Call after you have newed the component to initialize it
|
|
|
|
*/
|
|
|
|
virtual void Startup();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the component in the game loop
|
|
|
|
* @param deltaTime time passed since last update
|
|
|
|
*/
|
|
|
|
virtual void Update(float deltaTime);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the data of this component from the luz/lvl configuration
|
|
|
|
*/
|
|
|
|
virtual void LoadConfigData();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the data of this component from the cdclient database
|
|
|
|
*/
|
|
|
|
virtual void LoadTemplateData();
|
2023-06-07 03:48:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Serializes the component for delivery to the client(s)
|
|
|
|
*/
|
|
|
|
virtual void Serialize(RakNet::BitStream* bitStream, bool isConstruction = false);
|
2021-12-05 17:54:36 +00:00
|
|
|
protected:
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The entity that owns this component
|
|
|
|
*/
|
2023-06-07 01:59:53 +00:00
|
|
|
Entity* m_OwningEntity;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|