gedeng/cpp/Application.cpp
Karl a0e1bf8592 Add game loop to Application
Implements fixed and variable time steps.

Might be a moved to a separate class later.
2021-04-30 10:23:59 +02:00

32 lines
857 B
C++

#include "Gedeng/Application.h"
#include "Gedeng/Time.h"
#include "Gedeng/Logger.h"
namespace Gedeng {
void Application::run() {
unsigned long previous_time_ms = Time::get_time_ms();
unsigned long time_until_fixed_update_ms = 0.0;
while (true) {
unsigned long current_time_ms = Time::get_time_ms();
unsigned long elapsed_time_ms = current_time_ms - previous_time_ms;
previous_time_ms = current_time_ms;
time_until_fixed_update_ms += elapsed_time_ms;
// Process Input
// Update fixed time step
while (time_until_fixed_update_ms >= MS_PER_UPDATE) {
// Fixed Update
GG_CORE_INFO("Fixed Update");
time_until_fixed_update_ms -= MS_PER_UPDATE;
}
// Variable update
GG_CORE_INFO("Variable Update");
}
}
} // namespace Gedeng