aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-11-21 09:06:52 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-11-21 09:06:52 +0100
commitd3d207b9a2445a9219274466bae2254e1c3db268 (patch)
tree7c37a3d4f32de8ff617e1db42626eb6caa57b36c
parent8b5fd6188862bf9bdfc06a5419c8525d2dfd5f7f (diff)
Added SceneManger to LoopManager
-rw-r--r--src/crepe/api/LoopManager.h13
-rw-r--r--src/crepe/api/LoopManager.hpp5
-rw-r--r--src/crepe/api/SceneManager.h1
-rw-r--r--src/example/scene_manager.cpp20
4 files changed, 29 insertions, 10 deletions
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index f6904be..25b833a 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -4,6 +4,7 @@
#include "../ComponentManager.h"
#include "../system/System.h"
+#include "api/SceneManager.h"
namespace crepe {
@@ -12,6 +13,14 @@ public:
void start();
LoopManager();
+ /**
+ * \brief Add a new concrete scene to the scene manager
+ *
+ * \tparam T Type of concrete scene
+ */
+ template <typename T>
+ void add_scene();
+
private:
/**
* \brief Setup function for one-time initialization.
@@ -53,12 +62,14 @@ private:
* This function updates physics and game logic based on LoopTimer's fixed_delta_time.
*/
void fixed_update();
+
/**
* \brief Set game running variable
*
* \param running running (false = game shutdown, true = game running)
*/
void set_running(bool running);
+
/**
* \brief Function for executing render-related systems.
*
@@ -71,6 +82,8 @@ private:
private:
//! Component manager instance
ComponentManager component_manager{};
+ //! Scene manager instance
+ SceneManager scene_manager{component_manager};
private:
/**
diff --git a/src/crepe/api/LoopManager.hpp b/src/crepe/api/LoopManager.hpp
index 0b14fdb..9cf470b 100644
--- a/src/crepe/api/LoopManager.hpp
+++ b/src/crepe/api/LoopManager.hpp
@@ -11,6 +11,11 @@
namespace crepe {
template <class T>
+void LoopManager::add_scene() {
+ this->scene_manager.add_scene<T>();
+}
+
+template <class T>
T & LoopManager::get_system() {
using namespace std;
static_assert(is_base_of<System, T>::value,
diff --git a/src/crepe/api/SceneManager.h b/src/crepe/api/SceneManager.h
index a20d6a0..45ba668 100644
--- a/src/crepe/api/SceneManager.h
+++ b/src/crepe/api/SceneManager.h
@@ -25,7 +25,6 @@ public:
* \brief Add a new concrete scene to the scene manager
*
* \tparam T Type of concrete scene
- * \param name Name of new scene
*/
template <typename T>
void add_scene();
diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp
index ac7f439..7277afa 100644
--- a/src/example/scene_manager.cpp
+++ b/src/example/scene_manager.cpp
@@ -1,3 +1,6 @@
+#define private public
+
+#include "api/LoopManager.h"
#include <iostream>
#include <crepe/ComponentManager.h>
@@ -40,22 +43,21 @@ public:
};
int main() {
- ComponentManager component_mgr{};
- SceneManager scene_mgr{component_mgr};
+ LoopManager loop_mgr;
// Add the scenes to the scene manager
- scene_mgr.add_scene<ConcreteScene1>();
- scene_mgr.add_scene<ConcreteScene2>();
+ loop_mgr.add_scene<ConcreteScene1>();
+ loop_mgr.add_scene<ConcreteScene2>();
// There is no need to call set_next_scene() at the beginnen, because the first scene will be
// automatically set as the next scene
// Load scene1 (the first scene added)
- scene_mgr.load_next_scene();
+ loop_mgr.scene_manager.load_next_scene();
// Get the Metadata components of each GameObject of Scene1
vector<reference_wrapper<Metadata>> metadata
- = component_mgr.get_components_by_type<Metadata>();
+ = loop_mgr.component_manager.get_components_by_type<Metadata>();
cout << "Metadata components of Scene1:" << endl;
// Print the Metadata
@@ -65,12 +67,12 @@ int main() {
}
// Set scene2 as the next scene
- scene_mgr.set_next_scene("scene2");
+ loop_mgr.scene_manager.set_next_scene("scene2");
// Load scene2
- scene_mgr.load_next_scene();
+ loop_mgr.scene_manager.load_next_scene();
// Get the Metadata components of each GameObject of Scene2
- metadata = component_mgr.get_components_by_type<Metadata>();
+ metadata = loop_mgr.component_manager.get_components_by_type<Metadata>();
cout << "Metadata components of Scene2:" << endl;
// Print the Metadata