-
-
Save Reputeless/a5222d94cc31737cea7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <Siv3D.hpp> | |
class TimerMicrosec | |
{ | |
public: | |
void start() | |
{ | |
if (!m_pausing) | |
{ | |
return; | |
} | |
m_startTimeMicrosec = Time::GetMicrosec(); | |
m_isActive = true; | |
m_pausing = false; | |
} | |
unsigned long long elapsed() const | |
{ | |
if (!m_isActive) | |
{ | |
return 0; | |
} | |
if (m_pausing) | |
{ | |
return m_accumulationMicrosec; | |
} | |
return (m_accumulationMicrosec + (Time::GetMicrosec() - m_startTimeMicrosec)); | |
} | |
Property_Get(bool, isActive) const | |
{ | |
return m_isActive; | |
} | |
void pause() | |
{ | |
m_accumulationMicrosec = elapsed(); | |
m_pausing = true; | |
} | |
void reset() | |
{ | |
m_accumulationMicrosec = 0; | |
m_isActive = false; | |
m_pausing = true; | |
} | |
void restart() | |
{ | |
reset(); | |
start(); | |
} | |
void set(unsigned long long time) | |
{ | |
m_isActive |= (time != 0); | |
m_startTimeMicrosec = Time::GetMicrosec(); | |
m_accumulationMicrosec = time; | |
} | |
private: | |
unsigned long long m_startTimeMicrosec = 0; | |
unsigned long long m_accumulationMicrosec = 0; | |
bool m_isActive = false; | |
bool m_pausing = true; | |
}; | |
void Main() | |
{ | |
TimerMicrosec tm; | |
tm.start(); | |
System::Sleep(1.234); | |
Println(tm.elapsed()); | |
while (System::Update()) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment