feat: allow game registering of components

This commit is contained in:
2026-08-14 02:41:59 +02:00
parent 405ef0baeb
commit 7f65a151b5
8 changed files with 111 additions and 1 deletions
+10
View File
@@ -24,6 +24,8 @@
#include <string_view>
#include "imgui.h"
#include "components/GameComponentRegistry.h"
#include "components/PrintComponent.h"
#include "destrum/Components/Physics/SphereCollider.h"
#include "destrum/Util/ModelDocUtils.h"
@@ -60,6 +62,8 @@ LightKeeper::~LightKeeper()
void LightKeeper::customInit()
{
RegisterGameComponents();
resources.init(gfxDevice);
renderer.init(gfxDevice, resources, m_params.renderSize);
@@ -426,6 +430,12 @@ void LightKeeper::customInit()
sphereMaterial = resources.materials().addSimpleColorMaterial({0.5f, 0.3f, 0.8f}, "Blue");
auto obj = scene.CreateGameObject("GameObject");
auto printComp = obj->AddComponent<PrintComponent>();
printComp->SetMessage("Testing");
}
void LightKeeper::customUpdate(float dt)
@@ -0,0 +1,20 @@
#include <components/GameComponentRegistry.h>
#include <destrum/Serialization/ComponentFactory.h>
#include <components/GameComponentList.h>
void RegisterGameComponents()
{
static bool registered = false;
if (registered) {
return;
}
registered = true;
#define LIGHTKEEPER_REGISTER_COMPONENT(ComponentType) \
ComponentFactory::Register<ComponentType>(#ComponentType);
LIGHTKEEPER_GAME_COMPONENTS(LIGHTKEEPER_REGISTER_COMPONENT)
#undef LIGHTKEEPER_REGISTER_COMPONENT
}
@@ -0,0 +1,34 @@
#include <components/PrintComponent.h>
#include "spdlog/spdlog.h"
PrintComponent::PrintComponent(GameObject& parent) : Component(parent, "PrintComponent")
{
}
void PrintComponent::Start()
{
}
void PrintComponent::Update(float dt)
{
spdlog::debug(m_message);
}
void PrintComponent::ImGuiInspector()
{
Component::ImGuiInspector();
}
nlohmann::json PrintComponent::Serialize() const
{
return {"message", m_message};
}
void PrintComponent::Deserialize(const nlohmann::json& basic_jsons)
{
if (basic_jsons.contains("message"))
{
m_message = basic_jsons.at("message").get<std::string>();
}
}