From 791b3f354b378769bffe623b05f1305c91b77101 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Fri, 3 Jun 2022 23:30:01 -0700 Subject: Changeset: 64 [WIP] Rename directories --- ProjectBrussel/Game/GameObject.hpp | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 ProjectBrussel/Game/GameObject.hpp (limited to 'ProjectBrussel/Game/GameObject.hpp') diff --git a/ProjectBrussel/Game/GameObject.hpp b/ProjectBrussel/Game/GameObject.hpp new file mode 100644 index 0000000..f975803 --- /dev/null +++ b/ProjectBrussel/Game/GameObject.hpp @@ -0,0 +1,102 @@ +#pragma once + +#include "EditorAttachment.hpp" +#include "Material.hpp" +#include "Renderer.hpp" +#include "VertexIndex.hpp" + +#include +#include + +#include +#include +#include +#include +#include + +namespace Tags { +enum class GameObjectKind { + KD_Generic, + KD_Player, + KD_SimpleGeometry, + KD_Building, + KD_LevelWrapper, + KD_COUNT, +}; +BRUSSEL_ENUM(GameObjectKind, ToString FromString ExcludeHeuristics); +} // namespace Tags + +class GameWorld; +class GameObject { +public: + using Kind = Tags::GameObjectKind; + using enum Tags::GameObjectKind; + +private: + std::unique_ptr mEditorAttachment; + GameWorld* mWorld; + GameObject* mParent; + PodVector mChildren; + glm::quat mRot; + glm::vec3 mPos; + glm::vec3 mScale; + Kind mKind; + +protected: + bool mStopFreePropagation : 1 = false; + +public: + static void FreeRecursive(GameObject* object); + + // TODO allow moving between worlds + GameObject(GameWorld* world); + GameObject(Kind kind, GameWorld* world); + virtual ~GameObject(); + + GameObject(const GameObject&) = delete; + GameObject& operator=(const GameObject&) = delete; + GameObject(GameObject&&) = default; + GameObject& operator=(GameObject&&) = default; + + Kind GetKind() const; + + GameWorld* GetWorld() const; + GameObject* GetParent() const; + const PodVector& GetChildren() const; + void AddChild(GameObject* child); + GameObject* RemoveChild(int index); + GameObject* RemoveChild(GameObject* child); + void RemoveSelfFromParent(); + PodVector RemoveAllChildren(); + + EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } + void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } + + const glm::vec3& GetPos() const; + void SetPos(const glm::vec3& pos); + + const glm::quat& GetRotation() const; + void SetRotation(const glm::quat& rotation); + + const glm::vec3& GetScale() const; + void SetScale(const glm::vec3& scale); + + // Visuals + virtual std::span GetRenderObjects() const; + + // Lifetime hooks + virtual void OnInitialized(); + virtual void Awaken(); + virtual void Resleep(); + virtual void Update(); + + static rapidjson::Value Serialize(GameObject* obj, rapidjson::Document& root); + static std::unique_ptr Deserialize(const rapidjson::Value& value, GameWorld* world); + virtual void ReadSaveFormat(const rapidjson::Value& value); + virtual void WriteSaveFormat(rapidjson::Value& value, rapidjson::Document& root); + +protected: + void SetParent(GameObject* parent); +}; + +#include -- cgit v1.2.3-70-g09d2