Splitup component classes and structs

This commit is contained in:
2024-07-07 17:08:35 -04:00
parent 2ad82cfa5d
commit 2d4d213b34
5 changed files with 94 additions and 42 deletions

View File

@@ -8,6 +8,7 @@
#include <unordered_map>
#include <vector>
#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:

View File

@@ -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;
};
}

View File

@@ -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

View File

@@ -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;
};
}

View File

@@ -0,0 +1,25 @@
//
// Created by kj16609 on 7/7/24.
//
#pragma once
#include <memory>
#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