aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api/LoopManager.h')
-rw-r--r--src/crepe/api/LoopManager.h108
1 files changed, 72 insertions, 36 deletions
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 288dca2..124cd3a 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -2,15 +2,40 @@
#include <memory>
-#include "../ComponentManager.h"
+#include "../facade/SDLContext.h"
+#include "../manager/ComponentManager.h"
+#include "../manager/EventManager.h"
+#include "../manager/LoopTimerManager.h"
+#include "../manager/Mediator.h"
+#include "../manager/ResourceManager.h"
+#include "../manager/SaveManager.h"
+#include "../manager/SceneManager.h"
#include "../system/System.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 Start the gameloop
+ *
+ * This is the start of the engine where the setup is called and then the loop keeps running until the game stops running.
+ * The Game programmer needs to call this function to run the game. This should be done after creating and adding all scenes.
+ */
+ void start();
+
+ /**
+ * \brief Add a new concrete scene to the scene manager
+ *
+ * \tparam T Type of concrete scene
+ */
+ template <typename T>
+ void add_scene();
private:
/**
@@ -27,59 +52,70 @@ private:
void loop();
/**
- * \brief Function for handling input-related system calls.
+ * \brief Per-frame update.
*
- * Processes user inputs from keyboard and mouse.
+ * Updates the game state based on the elapsed time since the last frame.
*/
- void process_input();
+ virtual void frame_update();
/**
- * \brief Per-frame update.
+ * \brief Fixed update executed at a fixed rate.
*
- * Updates the game state based on the elapsed time since the last frame.
+ * This function updates physics and game logic based on LoopTimer's fixed_delta_time.
*/
- void update();
+ virtual void fixed_update();
+
+ //! Indicates whether the game is running.
+ bool game_running = false;
+private:
+ //! Global context
+ Mediator mediator;
/**
- * \brief Late update which is called after update().
+ * \brief Collection of System instances
*
- * This function can be used for final adjustments before rendering.
+ * This map holds System instances indexed by the system's class typeid. It is filled in the
+ * constructor of LoopManager using LoopManager::load_system.
*/
- void late_update();
+ std::unordered_map<std::type_index, std::unique_ptr<System>> systems;
+ //! SDLContext instance
+ SDLContext sdl_context{mediator};
+ //! Resource manager instance
+ ResourceManager resource_manager{mediator};
+
+ //! Component manager instance
+ ComponentManager component_manager{mediator};
+ //! Scene manager instance
+ SceneManager scene_manager{mediator};
+ //! LoopTimerManager instance
+ LoopTimerManager loop_timer{mediator};
+ //! EventManager instance
+ EventManager event_manager{mediator};
+ //! Save manager instance
+ SaveManager save_manager{mediator};
+
+private:
/**
- * \brief Fixed update executed at a fixed rate.
+ * \brief Callback function for ShutDownEvent
*
- * This function updates physics and game logic based on LoopTimer's fixed_delta_time.
+ * This function sets the game_running variable to false, stopping the gameloop and therefor quitting the game.
*/
- void fixed_update();
+ bool on_shutdown(const ShutDownEvent & e);
/**
- * \brief Set game running variable
- *
- * \param running running (false = game shutdown, true = game running)
+ * \brief Initialize a system
+ * \tparam T System type (must be derivative of \c System)
*/
- void set_running(bool running);
+ template <class T>
+ void load_system();
/**
- * \brief Function for executing render-related systems.
- *
- * Renders the current state of the game to the screen.
+ * \brief Retrieve a reference to ECS system
+ * \tparam T System type
+ * \returns Reference to system instance
+ * \throws std::runtime_error if the System is not initialized
*/
- void render();
-
- bool game_running = false;
-
-protected:
- ComponentManager & get_component_manager();
template <class T>
T & get_system();
-
-private:
- ComponentManager component_manager{};
- std::unordered_map<std::type_index, std::unique_ptr<System>> systems;
-
-private:
- template <class T>
- void load_system();
};
} // namespace crepe