From 3fdc6eb4f2cbeffce9b250beec4d3a2d52a3f534 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Wed, 6 Apr 2022 20:52:51 -0700 Subject: Work on moving infrastruture to this project --- source/World.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 source/World.cpp (limited to 'source/World.cpp') diff --git a/source/World.cpp b/source/World.cpp new file mode 100644 index 0000000..907f056 --- /dev/null +++ b/source/World.cpp @@ -0,0 +1,68 @@ +#include "World.hpp" + +#include + +namespace ProjectBrussel_UNITY_ID { +template +void CallGameObjectRecursive(GameObject* start, TFunction&& func) { + PodVector 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 + +struct GameWorld::RenderData { + void SubmitDrawCalls() { + // TODO + } +}; + +GameWorld::GameWorld() + : mRender{ new RenderData() } + , mRoot(this) { +} + +GameWorld::~GameWorld() { + delete mRender; + for (auto child : mRoot.GetChildren()) { + GameObject::FreeRecursive(child); + } +} + +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(); + }); +} + +void GameWorld::Draw() { +} -- cgit v1.2.3-70-g09d2