DarkflameServer/dGame/dComponents/Component.h

75 lines
1.6 KiB
C
Raw Normal View History

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