We got GameObjects / Components and shit

This commit is contained in:
2026-01-10 06:09:50 +01:00
parent 10b00b0525
commit 0bfc5e0705
35 changed files with 1546 additions and 331 deletions

View File

@@ -0,0 +1,83 @@
#include <destrum/Scene/SceneManager.h>
#include <stdexcept>
#include <destrum/Scene/Scene.h>
void SceneManager::Update() {
m_scenes[m_ActiveSceneIndex]->Update();
}
void SceneManager::FixedUpdate() {
m_scenes[m_ActiveSceneIndex]->FixedUpdate();
}
void SceneManager::LateUpdate() {
m_scenes[m_ActiveSceneIndex]->LateUpdate();
}
void SceneManager::Render(const RenderContext& ctx) {
m_scenes[m_ActiveSceneIndex]->Render(ctx);
}
void SceneManager::RenderImgui() {
m_scenes[m_ActiveSceneIndex]->RenderImgui();
}
void SceneManager::HandleGameObjectDestroy() {
for (const auto& scene : m_scenes) {
scene->CleanupDestroyedGameObjects();
}
}
void SceneManager::DestroyGameObjects() {
for (const auto& scene: m_scenes) {
scene->DestroyGameObjects();
}
}
void SceneManager::UnloadAllScenes() {
for (const auto& scene : m_scenes) {
scene->Unload();
}
}
void SceneManager::HandleSceneDestroy() {
for (auto it = m_scenes.begin(); it != m_scenes.end();) {
if ((*it)->IsBeingUnloaded()) {
it = m_scenes.erase(it);
} else {
++it;
}
}
}
void SceneManager::HandleScene() {
DestroyGameObjects();
HandleGameObjectDestroy();
HandleSceneDestroy();
}
void SceneManager::Destroy() {
UnloadAllScenes();
DestroyGameObjects();
HandleGameObjectDestroy();
HandleSceneDestroy();
}
void SceneManager::SwitchScene(int index) {
// InputManager::GetInstance().RemoveAllBindings();
if (index < 0 || index >= static_cast<int>(m_scenes.size())) {
throw std::out_of_range("Scene index out of range");
}
m_scenes[m_ActiveSceneIndex]->UnloadBindings();
m_ActiveSceneIndex = index;
m_scenes[m_ActiveSceneIndex]->LoadBindings();
}
Scene &SceneManager::CreateScene(const std::string &name) {
const auto &scene = std::shared_ptr<Scene>(new Scene(name));
m_scenes.push_back(scene);
return *scene;
}