aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api/LoopManager.cpp')
-rw-r--r--src/crepe/api/LoopManager.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 88243c4..4f08bab 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -1,3 +1,6 @@
+#include "../facade/SDLContext.h"
+
+#include "../manager/EventManager.h"
#include "../system/AnimatorSystem.h"
#include "../system/CollisionSystem.h"
#include "../system/InputSystem.h"
@@ -20,51 +23,48 @@ LoopManager::LoopManager() {
this->load_system<RenderSystem>();
this->load_system<ScriptSystem>();
this->load_system<InputSystem>();
+ this->event_manager.subscribe<ShutDownEvent>(
+ [this](const ShutDownEvent & event) { return this->on_shutdown(event); });
}
-void LoopManager::process_input() { this->get_system<InputSystem>().update(); }
+void LoopManager::process_input() {
+ this->get_system<InputSystem>().update();
+ this->event_manager.dispatch_events();
+}
void LoopManager::start() {
this->setup();
this->loop();
}
-void LoopManager::set_running(bool running) { this->game_running = running; }
void LoopManager::fixed_update() {
- // TODO: retrieve EventManager from direct member after singleton refactor
- EventManager & ev = this->mediator.event_manager;
- ev.dispatch_events();
this->get_system<ScriptSystem>().update();
this->get_system<PhysicsSystem>().update();
this->get_system<CollisionSystem>().update();
}
void LoopManager::loop() {
- LoopTimer & timer = this->loop_timer;
- timer.start();
while (game_running) {
- timer.update();
+ this->loop_timer.update();
- while (timer.get_lag() >= timer.get_fixed_delta_time()) {
+ while (this->loop_timer.get_lag() >= this->loop_timer.get_fixed_loop_interval()) {
this->process_input();
this->fixed_update();
- timer.advance_fixed_update();
+ this->loop_timer.advance_fixed_update();
}
- this->update();
+ this->frame_update();
this->render();
-
- timer.enforce_frame_rate();
+ this->loop_timer.enforce_frame_rate();
}
}
void LoopManager::setup() {
- LoopTimer & timer = this->loop_timer;
this->game_running = true;
+ this->loop_timer.start();
this->scene_manager.load_next_scene();
timer.start();
- timer.set_fps(200);
}
void LoopManager::render() {
@@ -74,4 +74,9 @@ void LoopManager::render() {
this->get_system<RenderSystem>().update();
}
-void LoopManager::update() {}
+bool LoopManager::on_shutdown(const ShutDownEvent & e) {
+ this->game_running = false;
+ return false;
+}
+
+void LoopManager::frame_update() {}