1er commit
This commit is contained in:
37
src/misc/Time.cpp
Normal file
37
src/misc/Time.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "misc/Time.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
void Timer::update(){
|
||||
m_InternalTime += getTime() - m_LastTime;
|
||||
if(m_InternalTime >= m_Interval){
|
||||
if(m_Function != nullptr)
|
||||
m_Function();
|
||||
m_InternalTime %= m_Interval;
|
||||
}
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
void Timer::update(std::uint64_t delta){
|
||||
m_InternalTime += delta;
|
||||
if(m_InternalTime >= m_Interval){
|
||||
if(m_Function != nullptr)
|
||||
m_Function();
|
||||
m_InternalTime %= m_Interval;
|
||||
}
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
void Timer::reset(){
|
||||
m_InternalTime = 0;
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
std::uint64_t getTime(){
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user