Files
Destrum/destrum/include/destrum/ObjectModel/Component.h
T

68 lines
1.6 KiB
C++

#ifndef COMPONENT_H
#define COMPONENT_H
#include <string>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include <destrum/Graphics/RenderContext.h>
#include <destrum/ObjectModel/Object.h>
#include <destrum/ObjectModel/ObjectId.h>
class GameObject;
class Transform;
class Component : public Object {
public:
using ObjectMap = std::unordered_map<ObjectId, GameObject*>;
~Component() override = default;
Component(const Component& other) = delete;
Component(Component&& other) noexcept = delete;
Component& operator=(const Component& other) = delete;
Component& operator=(Component&& other) noexcept = delete;
[[nodiscard]] bool isEnabled() const { return m_IsEnabled; }
[[nodiscard]] GameObject* GetGameObject() const { return m_ParentGameObjectPtr; }
[[nodiscard]] Transform& GetTransform() const;
void Destroy() override;
virtual void Start();
virtual void SetEnabled(bool enabled);
virtual void Update() = 0;
virtual void LateUpdate();
virtual void FixedUpdate();
virtual void ImGuiInspector();
virtual void ImGuiRender();
virtual void Render(const RenderContext& ctx);
// Serialization.
virtual std::string GetTypeName() const = 0;
virtual nlohmann::json Serialize() const {
return {};
}
virtual void Deserialize(const nlohmann::json& data) {
}
virtual void ResolveReferences(const ObjectMap& objects) {
}
bool HasStarted{false};
protected:
explicit Component(GameObject& pParent, const std::string& name = "Component");
private:
GameObject* m_ParentGameObjectPtr{};
bool m_IsEnabled{true};
};
#endif // COMPONENT_H