diff options
author | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
commit | 60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (patch) | |
tree | 02ec83cc8387abfd08bd5ee7ea4e8115f1bfb8d0 /source/Game/World.cpp | |
parent | c2ef7737536bf1f8c81fcfae95c0183b21c9753f (diff) |
Changeset: 63 [WIP] Rename directories
Diffstat (limited to 'source/Game/World.cpp')
-rw-r--r-- | source/Game/World.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/Game/World.cpp b/source/Game/World.cpp new file mode 100644 index 0000000..d4a8344 --- /dev/null +++ b/source/Game/World.cpp @@ -0,0 +1,74 @@ +#include "World.hpp" + +#include "GameObject.hpp" +#include "PodVector.hpp" + +#include <glad/glad.h> + +namespace ProjectBrussel_UNITY_ID { +template <class TFunction> +void CallGameObjectRecursive(GameObject* start, TFunction&& func) { + PodVector<GameObject*> stack; + stack.push_back(start); + + while (!stack.empty()) { + auto obj = stack.back(); + stack.pop_back(); + + for (auto child : obj->GetChildren()) { + stack.push_back(child); + } + + func(obj); + } +} + +struct DrawCall { + GLuint vao; + GLuint vbo; +}; +} // namespace ProjectBrussel_UNITY_ID + +GameWorld::GameWorld() + : mRoot{ new GameObject(this) } { +} + +GameWorld::~GameWorld() { + if (mAwakened) { + Resleep(); + } + + delete mRoot; +} + +const GameObject& GameWorld::GetRoot() const { + return *mRoot; +}; + +void GameWorld::Awaken() { + if (mAwakened) return; + + ProjectBrussel_UNITY_ID::CallGameObjectRecursive(mRoot, [](GameObject* obj) { obj->Awaken(); }); + mAwakened = true; +} + +void GameWorld::Resleep() { + if (!mAwakened) return; + + ProjectBrussel_UNITY_ID::CallGameObjectRecursive(mRoot, [](GameObject* obj) { obj->Resleep(); }); + mAwakened = false; +} + +void GameWorld::Update() { + ProjectBrussel_UNITY_ID::CallGameObjectRecursive(mRoot, [this](GameObject* obj) { + obj->Update(); + }); +} + +GameObject& GameWorld::GetRoot() { + return *mRoot; +} + +bool GameWorld::IsAwake() const { + return mAwakened; +} |