[ADDED] timer class

This commit is contained in:
Menno
2021-06-01 11:41:21 +02:00
parent 739b4a9eb6
commit f03cc485cd
4 changed files with 61 additions and 6 deletions

View File

@@ -55,6 +55,11 @@ int main(void)
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE)
{
glfwSetWindowShouldClose(window, true);
}
current_scene->onKey(window, key, scancode, action, mods);
});

46
src/toolbox/Timer.h Normal file
View File

@@ -0,0 +1,46 @@
#pragma once
namespace toolbox
{
/*
* This class represents a timer which needs to be updated
* every frame to work correctly.
*/
class Timer
{
private:
float current_time;
float final_time;
bool has_finished;
public:
/*
* @brief: Constructor to make the timer
*
* @param final_time: The time which the timer needs to count to
*/
Timer(float final_time): current_time(0), final_time(final_time), has_finished(false) {}
/*
* @brief: Updates the timer. Call this method once every iteration in the game loop
*
* @param delta: The deltatime of the game
*/
void UpdateTimer(const double delta)
{
current_time += delta;
if (current_time >= final_time)
{
has_finished = true;
}
}
/*
* @brief: Returns if the timer has finished
*
* @return: True if the timer has finished
*/
bool HasFinished() const { return has_finished; }
};
}