aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 10:26:32 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 10:26:32 +0100
commitc7c4cc0e3b1a3152256bc8ebf6494c19519538db (patch)
tree9c7a2201d94c8a51bb93de7cea45a9f14e2da5ea /src/crepe/api/LoopManager.cpp
parentf137451d0edb13543919cf2d1a3af379cb3a1485 (diff)
looptimer no singleton
Diffstat (limited to 'src/crepe/api/LoopManager.cpp')
-rw-r--r--src/crepe/api/LoopManager.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 7edf4d1..4a6d2cd 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -6,20 +6,25 @@
#include "../system/PhysicsSystem.h"
#include "../system/RenderSystem.h"
#include "../system/ScriptSystem.h"
-
+#include "../api/EventManager.h"
#include "LoopManager.h"
#include "LoopTimer.h"
-
+#include <iostream>
using namespace crepe;
using namespace std;
LoopManager::LoopManager() {
+ this->loop_timer = make_unique<LoopTimer>();
this->load_system<AnimatorSystem>();
this->load_system<CollisionSystem>();
this->load_system<ParticleSystem>();
this->load_system<PhysicsSystem>();
this->load_system<RenderSystem>();
this->load_system<ScriptSystem>();
+ EventManager::get_instance().subscribe<ShutDownEvent>([this](const ShutDownEvent& event) {
+ return this->on_shutdown(event);
+ });
+
}
void LoopManager::process_input() {
@@ -35,29 +40,27 @@ void LoopManager::set_running(bool running) { this->game_running = running; }
void LoopManager::fixed_update() {}
void LoopManager::loop() {
- LoopTimer & timer = LoopTimer::get_instance();
- timer.start();
+ this->loop_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_delta_time()) {
this->process_input();
this->fixed_update();
- timer.advance_fixed_update();
+ this->loop_timer->advance_fixed_update();
}
this->update();
this->render();
-
- timer.enforce_frame_rate();
+ this->loop_timer->enforce_frame_rate();
}
}
void LoopManager::setup() {
this->game_running = true;
- LoopTimer::get_instance().start();
- LoopTimer::get_instance().set_fps(200);
+ this->loop_timer->start();
+ this->loop_timer->set_fps(60);
}
void LoopManager::render() {
@@ -65,5 +68,9 @@ void LoopManager::render() {
this->get_system<RenderSystem>().update();
}
}
+bool LoopManager::on_shutdown(const ShutDownEvent & e){
+ this->game_running = false;
+ return false;
+}
-void LoopManager::update() { LoopTimer & timer = LoopTimer::get_instance(); }
+void LoopManager::update() {}