-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
31 lines (24 loc) · 811 Bytes
/
Timer.cpp
File metadata and controls
31 lines (24 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "Timer.h"
void Timer::start()
{
this->startTime = std::chrono::steady_clock::now();
this->running = true;
}
void Timer::stop()
{
this->endTime = std::chrono::steady_clock::now();
this->running = false;
Timer::accumulatedTime += std::chrono::duration_cast<std::chrono::milliseconds>(this->endTime - this->startTime).count();
text.setText(std::to_string(Timer::accumulatedTime) + " ms");
}
void Timer::tick(const Time time)
{
if (this->running)
{
auto endTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - this->startTime).count() + Timer::accumulatedTime;
text.setText(std::to_string(elapsedTime) + " ms");
}
text.tick(time);
}
int Timer::accumulatedTime = 0;