aboutsummaryrefslogtreecommitdiff
path: root/source/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/World.cpp')
-rw-r--r--source/World.cpp68
1 files changed, 68 insertions, 0 deletions
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 <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
+
+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() {
+}