aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-21 10:00:12 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-21 10:00:12 +0100
commitaa00be5fae68e4ccb7b592f1193d86f09105723a (patch)
tree47fcc6aad7b18723b926608e5177f677e4493801 /src/crepe
parent502fb8e8d1dcfe10f55fdef2cdfb71afec806204 (diff)
parent1bc04b371f2cc8740f2ee039f75101922da671d6 (diff)
Merge branch 'master' into loek/scripts
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/LoopManager.h18
-rw-r--r--src/crepe/api/LoopManager.hpp5
-rw-r--r--src/crepe/api/Scene.cpp4
-rw-r--r--src/crepe/api/Scene.h21
-rw-r--r--src/crepe/api/SceneManager.cpp2
-rw-r--r--src/crepe/api/SceneManager.h14
-rw-r--r--src/crepe/api/SceneManager.hpp6
7 files changed, 58 insertions, 12 deletions
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index f6904be..13e6dac 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -4,14 +4,28 @@
#include "../ComponentManager.h"
#include "../system/System.h"
+#include "api/SceneManager.h"
namespace crepe {
+/**
+ * \brief Main game loop manager
+ *
+ * This class is responsible for managing the game loop, including initialization and updating.
+ */
class LoopManager {
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 +67,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 +87,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/Scene.cpp b/src/crepe/api/Scene.cpp
index 88aa82d..849945e 100644
--- a/src/crepe/api/Scene.cpp
+++ b/src/crepe/api/Scene.cpp
@@ -2,6 +2,4 @@
using namespace crepe;
-Scene::Scene(ComponentManager & mgr, const std::string & name)
- : component_manager(mgr),
- name(name) {}
+Scene::Scene(ComponentManager & mgr) : component_manager(mgr) {}
diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h
index 0e516b6..869bf6f 100644
--- a/src/crepe/api/Scene.h
+++ b/src/crepe/api/Scene.h
@@ -7,19 +7,36 @@ namespace crepe {
class SceneManager;
class ComponentManager;
+/**
+ * \brief Represents a Scene
+ *
+ * This class represents a Scene. The Scene class is only used as an interface for the game
+ * programmer.
+ */
class Scene {
protected:
- Scene(ComponentManager & mgr, const std::string & name);
+ //TODO: Use Loek's custom reference class to set ComponentManger via SceneManager instead of via constructor
+ /**
+ * \param mgr Reference to the ComponentManager
+ */
+ Scene(ComponentManager & mgr);
+ //! SceneManager instances Scene
friend class SceneManager;
public:
virtual ~Scene() = default;
public:
+ //! Load the scene
virtual void load_scene() = 0;
- const std::string name;
+ /**
+ * \brief Get the scene's name
+ * \return The scene's name
+ */
+ virtual std::string get_name() const = 0;
protected:
+ //! Reference to the ComponentManager
ComponentManager & component_manager;
};
diff --git a/src/crepe/api/SceneManager.cpp b/src/crepe/api/SceneManager.cpp
index 7fb5cb0..1f783ad 100644
--- a/src/crepe/api/SceneManager.cpp
+++ b/src/crepe/api/SceneManager.cpp
@@ -18,7 +18,7 @@ void SceneManager::load_next_scene() {
auto it = find_if(this->scenes.begin(), this->scenes.end(),
[&next_scene = this->next_scene](unique_ptr<Scene> & scene) {
- return scene->name == next_scene;
+ return scene.get()->get_name() == next_scene;
});
// next scene not found
diff --git a/src/crepe/api/SceneManager.h b/src/crepe/api/SceneManager.h
index e854794..45ba668 100644
--- a/src/crepe/api/SceneManager.h
+++ b/src/crepe/api/SceneManager.h
@@ -1,7 +1,6 @@
#pragma once
#include <memory>
-#include <queue>
#include <vector>
#include "Scene.h"
@@ -10,8 +9,15 @@ namespace crepe {
class ComponentManager;
+/**
+ * \brief Manages scenes
+ *
+ * This class manages scenes. It can add new scenes and load them. It also manages the current scene
+ * and the next scene.
+ */
class SceneManager {
public:
+ //! \param mgr Reference to the ComponentManager
SceneManager(ComponentManager & mgr);
public:
@@ -19,10 +25,9 @@ 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(const std::string & name);
+ void add_scene();
/**
* \brief Set the next scene
*
@@ -35,8 +40,11 @@ public:
void load_next_scene();
private:
+ //! Vector of concrete scenes (added by add_scene())
std::vector<std::unique_ptr<Scene>> scenes;
+ //! Next scene to load
std::string next_scene;
+ //! Reference to the ComponentManager
ComponentManager & component_manager;
};
diff --git a/src/crepe/api/SceneManager.hpp b/src/crepe/api/SceneManager.hpp
index 714f690..94e5946 100644
--- a/src/crepe/api/SceneManager.hpp
+++ b/src/crepe/api/SceneManager.hpp
@@ -5,16 +5,16 @@
namespace crepe {
template <typename T>
-void SceneManager::add_scene(const std::string & name) {
+void SceneManager::add_scene() {
using namespace std;
static_assert(is_base_of<Scene, T>::value, "T must be derived from Scene");
- Scene * scene = new T(this->component_manager, name);
+ Scene * scene = new T(this->component_manager);
this->scenes.emplace_back(unique_ptr<Scene>(scene));
// The first scene added, is the one that will be loaded at the beginning
if (next_scene.empty()) {
- next_scene = name;
+ next_scene = scene->get_name();
}
}