2023-07-31 06:01:51 +00:00
|
|
|
#include "game.h"
|
|
|
|
|
2023-07-31 06:41:09 +00:00
|
|
|
// standard library includes
|
|
|
|
#include <string>
|
|
|
|
|
2023-07-31 06:01:51 +00:00
|
|
|
// third party includes
|
|
|
|
#include <raylib.h>
|
|
|
|
|
2023-07-31 06:41:09 +00:00
|
|
|
Game::Game()
|
|
|
|
: prev_time(std::chrono::steady_clock::now()), TEMP_cached_dt(0.0F) {}
|
2023-07-31 06:01:51 +00:00
|
|
|
|
2023-07-31 06:41:09 +00:00
|
|
|
void Game::update() {
|
|
|
|
auto next_time = std::chrono::steady_clock::now();
|
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
|
|
|
next_time - prev_time);
|
|
|
|
prev_time = next_time;
|
|
|
|
update_impl(((float)duration.count()) / 1000000);
|
|
|
|
}
|
2023-07-31 06:01:51 +00:00
|
|
|
|
2023-07-31 06:28:01 +00:00
|
|
|
void Game::draw() {
|
2023-07-31 06:41:09 +00:00
|
|
|
std::string dt_string =
|
|
|
|
std::string("Delta-time: ") + std::to_string(TEMP_cached_dt);
|
|
|
|
|
2023-07-31 06:28:01 +00:00
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(BLACK);
|
|
|
|
DrawText("Testing...", 100, 100, 30, RAYWHITE);
|
2023-07-31 06:41:09 +00:00
|
|
|
DrawText(dt_string.c_str(), 100, 140, 30, RAYWHITE);
|
2023-07-31 06:28:01 +00:00
|
|
|
EndDrawing();
|
|
|
|
}
|
2023-07-31 06:41:09 +00:00
|
|
|
|
|
|
|
void Game::update_impl(float dt) { TEMP_cached_dt = dt; }
|