diff options
Diffstat (limited to 'src/crepe/api/LoopManager.cpp')
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 731cfb7..040cb93 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -1,9 +1,12 @@ +#include "../facade/SDLContext.h" + #include "../system/AnimatorSystem.h" #include "../system/CollisionSystem.h" #include "../system/ParticleSystem.h" #include "../system/PhysicsSystem.h" #include "../system/RenderSystem.h" #include "../system/ScriptSystem.h" +#include "../manager/EventManager.h" #include "LoopManager.h" @@ -11,15 +14,17 @@ using namespace crepe; using namespace std; LoopManager::LoopManager() { - this->mediator.component_manager = this->component_manager; - this->mediator.scene_manager = this->scene_manager; - 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); + }); + this->loop_timer = make_unique<LoopTimer>(); + this->mediator.loop_timer = *loop_timer; } void LoopManager::process_input() { this->sdl_context.handle_events(this->game_running); } @@ -28,36 +33,33 @@ void LoopManager::start() { this->setup(); this->loop(); } -void LoopManager::set_running(bool running) { this->game_running = running; } void LoopManager::fixed_update() {} void LoopManager::loop() { - LoopTimer & timer = this->loop_timer; - timer.start(); + this->loop_timer->start(); while (game_running) { - timer.update(); - - while (timer.get_lag() >= timer.get_fixed_delta_time()) { + this->loop_timer->update(); + + 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() { - LoopTimer & timer = this->loop_timer; + this->game_running = true; - timer.start(); - timer.set_fps(200); + this->loop_timer->start(); + this->loop_timer->set_target_fps(200); } void LoopManager::render() { @@ -65,5 +67,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() {} |