diff --git a/destrum/include/destrum/Serialization/EngineComponentList.h b/destrum/include/destrum/Serialization/EngineComponentList.h index 88eca6e..3f02a02 100644 --- a/destrum/include/destrum/Serialization/EngineComponentList.h +++ b/destrum/include/destrum/Serialization/EngineComponentList.h @@ -22,6 +22,6 @@ X(Rigidbody) \ X(BoxCollider) \ X(SphereCollider) \ - X(CapsuleCollider) + X(CapsuleCollider) \ #endif // DESTRUM_ENGINECOMPONENTLIST_H diff --git a/lightkeeper/CMakeLists.txt b/lightkeeper/CMakeLists.txt index bec0b79..60c9621 100644 --- a/lightkeeper/CMakeLists.txt +++ b/lightkeeper/CMakeLists.txt @@ -6,6 +6,9 @@ set(GAME_SRC src/main.cpp src/Lightkeeper.cpp + + src/components/GameComponentRegistry.cpp + src/components/PrintComponent.cpp ) add_executable(lightkeeper ${GAME_SRC}) diff --git a/lightkeeper/include/components/GameComponentList.h b/lightkeeper/include/components/GameComponentList.h new file mode 100644 index 0000000..22303c1 --- /dev/null +++ b/lightkeeper/include/components/GameComponentList.h @@ -0,0 +1,9 @@ +#ifndef LIGHTKEEPER_GAMECOMPONENTLIST_H +#define LIGHTKEEPER_GAMECOMPONENTLIST_H + +#include + +#define LIGHTKEEPER_GAME_COMPONENTS(X) \ + X(PrintComponent) + +#endif // LIGHTKEEPER_GAMECOMPONENTLIST_H diff --git a/lightkeeper/include/components/GameComponentRegistry.h b/lightkeeper/include/components/GameComponentRegistry.h new file mode 100644 index 0000000..1fa9dc2 --- /dev/null +++ b/lightkeeper/include/components/GameComponentRegistry.h @@ -0,0 +1,6 @@ +#ifndef LIGHTKEEPER_GAMECOMPONENTREGISTRY_H +#define LIGHTKEEPER_GAMECOMPONENTREGISTRY_H + +void RegisterGameComponents(); + +#endif // LIGHTKEEPER_GAMECOMPONENTREGISTRY_H diff --git a/lightkeeper/include/components/PrintComponent.h b/lightkeeper/include/components/PrintComponent.h new file mode 100644 index 0000000..22321cd --- /dev/null +++ b/lightkeeper/include/components/PrintComponent.h @@ -0,0 +1,28 @@ +#ifndef DESTRUM_PRINTCOMPONENT_H +#define DESTRUM_PRINTCOMPONENT_H +#include "destrum/ObjectModel/Component.h" + +class PrintComponent: public Component { +public: + + PrintComponent(GameObject& parent); + + std::string GetTypeName() const override { return "PrintComponent"; } + void Start() override; + void Update(float dt) override; + void ImGuiInspector() override; + nlohmann::json Serialize() const override; + void Deserialize(const nlohmann::json&) override; + + void SetMessage(std::string_view message) + { + m_message = message; + } + +private: + + std::string m_message{}; + +}; + +#endif //DESTRUM_PRINTCOMPONENT_H diff --git a/lightkeeper/src/Lightkeeper.cpp b/lightkeeper/src/Lightkeeper.cpp index a760a82..b5a52a6 100644 --- a/lightkeeper/src/Lightkeeper.cpp +++ b/lightkeeper/src/Lightkeeper.cpp @@ -24,6 +24,8 @@ #include #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(); + printComp->SetMessage("Testing"); + + } void LightKeeper::customUpdate(float dt) diff --git a/lightkeeper/src/components/GameComponentRegistry.cpp b/lightkeeper/src/components/GameComponentRegistry.cpp new file mode 100644 index 0000000..581055b --- /dev/null +++ b/lightkeeper/src/components/GameComponentRegistry.cpp @@ -0,0 +1,20 @@ +#include + +#include + +#include + +void RegisterGameComponents() +{ + static bool registered = false; + if (registered) { + return; + } + + registered = true; + +#define LIGHTKEEPER_REGISTER_COMPONENT(ComponentType) \ + ComponentFactory::Register(#ComponentType); + LIGHTKEEPER_GAME_COMPONENTS(LIGHTKEEPER_REGISTER_COMPONENT) +#undef LIGHTKEEPER_REGISTER_COMPONENT +} diff --git a/lightkeeper/src/components/PrintComponent.cpp b/lightkeeper/src/components/PrintComponent.cpp new file mode 100644 index 0000000..f7562af --- /dev/null +++ b/lightkeeper/src/components/PrintComponent.cpp @@ -0,0 +1,34 @@ +#include + +#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(); + } +}