Splitup component classes and structs
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
29
src/engine/gameobjects/components/GameObjectComponent.hpp
Normal file
29
src/engine/gameobjects/components/GameObjectComponent.hpp
Normal 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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
25
src/engine/gameobjects/components/ModelComponent.hpp
Normal file
25
src/engine/gameobjects/components/ModelComponent.hpp
Normal 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
|
||||
Reference in New Issue
Block a user