remove unneeded Component.cpp, forward declare dependencies, and make Component definition header-only (#1688)

This commit is contained in:
jadebenn 2024-12-18 02:45:56 -06:00 committed by GitHub
parent fced6d753a
commit 0ae9eb4a96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 44 deletions

View File

@ -7,7 +7,6 @@ set(DGAME_DCOMPONENTS_SOURCES
"BuildBorderComponent.cpp"
"CharacterComponent.cpp"
"CollectibleComponent.cpp"
"Component.cpp"
"ControllablePhysicsComponent.cpp"
"DestroyableComponent.cpp"
"DonationVendorComponent.cpp"

View File

@ -1,34 +0,0 @@
#include "Component.h"
Component::Component(Entity* parent) {
m_Parent = parent;
}
Component::~Component() {
}
Entity* Component::GetParent() const {
return m_Parent;
}
void Component::Update(float deltaTime) {
}
void Component::OnUse(Entity* originator) {
}
void Component::UpdateXml(tinyxml2::XMLDocument& doc) {
}
void Component::LoadFromXml(const tinyxml2::XMLDocument& doc) {
}
void Component::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
}

View File

@ -1,6 +1,12 @@
#pragma once
#include "tinyxml2.h"
namespace tinyxml2 {
class XMLDocument;
}
namespace RakNet {
class BitStream;
}
class Entity;
@ -9,40 +15,40 @@ class Entity;
*/
class Component {
public:
Component(Entity* parent);
virtual ~Component();
Component(Entity* parent) : m_Parent{ parent } {}
virtual ~Component() = default;
/**
* Gets the owner of this component
* @return the owner of this component
*/
Entity* GetParent() const;
Entity* GetParent() const { return m_Parent; }
/**
* Updates the component in the game loop
* @param deltaTime time passed since last update
*/
virtual void Update(float deltaTime);
virtual void Update(float deltaTime) {}
/**
* Event called when this component is being used, e.g. when some entity interacted with it
* @param originator
*/
virtual void OnUse(Entity* 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);
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(const tinyxml2::XMLDocument& doc);
virtual void LoadFromXml(const tinyxml2::XMLDocument& doc) {}
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {}
protected: