diff options
author | rtk0c <[email protected]> | 2023-10-19 22:50:07 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-08-16 11:31:16 -0700 |
commit | 297232d21594b138bb368a42b5b0d085ff9ed6aa (patch) | |
tree | 075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /src/brussel.engine/GameObject.hpp | |
parent | d5cd34ff69f7fd134d5450696f298af1a864afbc (diff) |
The great renaming: switch to "module style"
Diffstat (limited to 'src/brussel.engine/GameObject.hpp')
-rw-r--r-- | src/brussel.engine/GameObject.hpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/brussel.engine/GameObject.hpp b/src/brussel.engine/GameObject.hpp new file mode 100644 index 0000000..40c52e7 --- /dev/null +++ b/src/brussel.engine/GameObject.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include "EditorAttachment.hpp" +#include "Material.hpp" +#include "Renderer.hpp" +#include "VertexIndex.hpp" + +#include <MacrosCodegen.hpp> +#include <PodVector.hpp> + +#include <rapidjson/fwd.h> +#include <glm/glm.hpp> +#include <glm/gtc/quaternion.hpp> +#include <span> +#include <vector> + +namespace Tags { +enum class GameObjectKind { + // clang-format off + BRUSSEL_ENUM(ToString, FromString, RemovePrefix KD_, AddPrefix GameObject, ExcludeHeuristics) + // clang-format on + + KD_Generic, + KD_Player, + KD_SimpleGeometry, + KD_Building, + KD_LevelWrapper, + KD_COUNT, +}; +} // namespace Tags + +class GameWorld; +class GameObject { + BRUSSEL_CLASS(InheritanceHiearchy) + +public: + using Kind = Tags::GameObjectKind; + using enum Tags::GameObjectKind; + +private: + std::unique_ptr<EditorAttachment> mEditorAttachment; + GameWorld* mWorld; + GameObject* mParent; + PodVector<GameObject*> 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<GameObject*>& GetChildren() const; + void AddChild(GameObject* child); + GameObject* RemoveChild(int index); + GameObject* RemoveChild(GameObject* child); + void RemoveSelfFromParent(); + PodVector<GameObject*> 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<const RenderObject> 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<GameObject> 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 <generated/GameObject.gh.inl> |