From 0ae9eb4a96cdb8ccbf86a62696c5b66359be2a76 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 18 Dec 2024 02:45:56 -0600 Subject: [PATCH] remove unneeded Component.cpp, forward declare dependencies, and make Component definition header-only (#1688) --- dGame/dComponents/CMakeLists.txt | 1 - dGame/dComponents/Component.cpp | 34 -------------------------------- dGame/dComponents/Component.h | 24 +++++++++++++--------- 3 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 dGame/dComponents/Component.cpp diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index c6e72f29..e1116895 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -7,7 +7,6 @@ set(DGAME_DCOMPONENTS_SOURCES "BuildBorderComponent.cpp" "CharacterComponent.cpp" "CollectibleComponent.cpp" - "Component.cpp" "ControllablePhysicsComponent.cpp" "DestroyableComponent.cpp" "DonationVendorComponent.cpp" diff --git a/dGame/dComponents/Component.cpp b/dGame/dComponents/Component.cpp deleted file mode 100644 index 8f38fb61..00000000 --- a/dGame/dComponents/Component.cpp +++ /dev/null @@ -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) { - -} diff --git a/dGame/dComponents/Component.h b/dGame/dComponents/Component.h index 160565fb..e7fd6028 100644 --- a/dGame/dComponents/Component.h +++ b/dGame/dComponents/Component.h @@ -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: