aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 10:27:42 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 10:27:42 +0100
commit7d1f3b90a5d640e4ae23d6ff8f0bf1bf35b6e4cb (patch)
tree0697c269ce96e55c7841344ec426e0e3daa2c864 /src/crepe/api/LoopManager.cpp
parent5981ab2262a98b80a1339f86a6b71093576a9b35 (diff)
parentc7c4cc0e3b1a3152256bc8ebf6494c19519538db (diff)
merge 2 gameloop branches
Diffstat (limited to 'src/crepe/api/LoopManager.cpp')
-rw-r--r--src/crepe/api/LoopManager.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index df09f7e..14e68c2 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,32 @@ 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;
+<<<<<<< HEAD
LoopTimer::get_instance().start();
LoopTimer::get_instance().set_target_fps(200);
+=======
+ this->loop_timer->start();
+ this->loop_timer->set_fps(60);
+>>>>>>> wouter/gameloop-improvements
}
void LoopManager::render() {
@@ -65,5 +73,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() {}