From 2d4d213b341df11d63d1e098b76a5672d7e318c9 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sun, 7 Jul 2024 17:08:35 -0400 Subject: [PATCH] Splitup component classes and structs --- src/engine/gameobjects/GameObject.hpp | 43 +------------------ .../components/ComponentImGuiInterface.hpp | 18 ++++++++ .../components/GameObjectComponent.hpp | 29 +++++++++++++ .../components/GameObjectComponentBase.hpp | 21 +++++++++ .../gameobjects/components/ModelComponent.hpp | 25 +++++++++++ 5 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 src/engine/gameobjects/components/ComponentImGuiInterface.hpp create mode 100644 src/engine/gameobjects/components/GameObjectComponent.hpp create mode 100644 src/engine/gameobjects/components/GameObjectComponentBase.hpp create mode 100644 src/engine/gameobjects/components/ModelComponent.hpp diff --git a/src/engine/gameobjects/GameObject.hpp b/src/engine/gameobjects/GameObject.hpp index d7e5317..9b4695e 100644 --- a/src/engine/gameobjects/GameObject.hpp +++ b/src/engine/gameobjects/GameObject.hpp @@ -8,6 +8,7 @@ #include #include +#include "components/GameObjectComponent.hpp" #include "engine/primitives/TransformComponent.hpp" namespace fgl::engine @@ -37,48 +38,6 @@ namespace fgl::engine TEXTURELESS = 1 << 0, }; - struct ComponentImGuiInterface - { - virtual void drawImGui() = 0; - virtual ~ComponentImGuiInterface() = default; - }; - - struct GameObjectComponentBase - { - using ComponentID = std::uint8_t; - virtual ComponentID id() const = 0; - virtual std::string_view name() const = 0; - - virtual ~GameObjectComponentBase() = default; - }; - - template < GameObjectComponentBase::ComponentID T_ID > - struct GameObjectComponent : ComponentImGuiInterface, GameObjectComponentBase - { - constexpr static ComponentID ID { T_ID }; - - virtual ComponentID id() const override final { return ID; } - }; - - template < typename T > - concept is_component = requires( T t ) { - std::is_base_of_v< T, GameObjectComponentBase >; - { - t.ID - } -> std::same_as< GameObjectComponentBase::ComponentID >; - }; - - class ModelComponent final : public GameObjectComponent< 1 > - { - std::shared_ptr< Model > m_model; - - public: - - void drawImGui() override; - std::string_view name() const override; - ~ModelComponent() override; - }; - class GameObject { public: diff --git a/src/engine/gameobjects/components/ComponentImGuiInterface.hpp b/src/engine/gameobjects/components/ComponentImGuiInterface.hpp new file mode 100644 index 0000000..6be3535 --- /dev/null +++ b/src/engine/gameobjects/components/ComponentImGuiInterface.hpp @@ -0,0 +1,18 @@ +// +// Created by kj16609 on 7/7/24. +// + +#pragma once + +namespace fgl::engine +{ + + struct ComponentImGuiInterface + { + virtual void drawImGui() = 0; + virtual ~ComponentImGuiInterface() = default; + }; + + +} + diff --git a/src/engine/gameobjects/components/GameObjectComponent.hpp b/src/engine/gameobjects/components/GameObjectComponent.hpp new file mode 100644 index 0000000..40cfe5b --- /dev/null +++ b/src/engine/gameobjects/components/GameObjectComponent.hpp @@ -0,0 +1,29 @@ +// +// Created by kj16609 on 7/7/24. +// + +#pragma once + +#include "ComponentImGuiInterface.hpp" +#include "GameObjectComponentBase.hpp" + +namespace fgl::engine +{ + + template < GameObjectComponentBase::ComponentID T_ID > + struct GameObjectComponent : ComponentImGuiInterface, GameObjectComponentBase + { + constexpr static ComponentID ID { T_ID }; + + virtual ComponentID id() const override final { return ID; } + }; + + template < typename T > + concept is_component = requires( T t ) { + std::is_base_of_v< T, GameObjectComponentBase >; + { + t.ID + } -> std::same_as< GameObjectComponentBase::ComponentID >; + }; + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/gameobjects/components/GameObjectComponentBase.hpp b/src/engine/gameobjects/components/GameObjectComponentBase.hpp new file mode 100644 index 0000000..76486ce --- /dev/null +++ b/src/engine/gameobjects/components/GameObjectComponentBase.hpp @@ -0,0 +1,21 @@ +// +// Created by kj16609 on 7/7/24. +// + +#pragma once + +namespace fgl::engine +{ + + + struct GameObjectComponentBase + { + using ComponentID = std::uint8_t; + virtual ComponentID id() const = 0; + virtual std::string_view name() const = 0; + + virtual ~GameObjectComponentBase() = default; + }; + + +} \ No newline at end of file diff --git a/src/engine/gameobjects/components/ModelComponent.hpp b/src/engine/gameobjects/components/ModelComponent.hpp new file mode 100644 index 0000000..7160969 --- /dev/null +++ b/src/engine/gameobjects/components/ModelComponent.hpp @@ -0,0 +1,25 @@ +// +// Created by kj16609 on 7/7/24. +// + +#pragma once +#include + +#include "GameObjectComponent.hpp" + +namespace fgl::engine +{ + class Model; + + class ModelComponent final : public GameObjectComponent< 1 > + { + std::shared_ptr< Model > m_model; + + public: + + void drawImGui() override; + std::string_view name() const override; + ~ModelComponent() override; + }; + +} // namespace fgl::engine