|
|
@ -1,7 +1,3 @@
|
|
|
|
//
|
|
|
|
|
|
|
|
// Created by koncord on 15.03.16.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "TimerAPI.hpp"
|
|
|
|
#include "TimerAPI.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <chrono>
|
|
|
@ -14,7 +10,7 @@ Timer::Timer(ScriptFunc callback, long msec, const std::string& def, std::vector
|
|
|
|
{
|
|
|
|
{
|
|
|
|
targetMsec = msec;
|
|
|
|
targetMsec = msec;
|
|
|
|
this->args = args;
|
|
|
|
this->args = args;
|
|
|
|
end = true;
|
|
|
|
isEnded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_LUA)
|
|
|
|
#if defined(ENABLE_LUA)
|
|
|
@ -22,13 +18,13 @@ Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::strin
|
|
|
|
{
|
|
|
|
{
|
|
|
|
targetMsec = msec;
|
|
|
|
targetMsec = msec;
|
|
|
|
this->args = args;
|
|
|
|
this->args = args;
|
|
|
|
end = true;
|
|
|
|
isEnded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Timer::Tick()
|
|
|
|
void Timer::Tick()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (end)
|
|
|
|
if (isEnded)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
const auto duration = chrono::system_clock::now().time_since_epoch();
|
|
|
|
const auto duration = chrono::system_clock::now().time_since_epoch();
|
|
|
@ -36,19 +32,19 @@ void Timer::Tick()
|
|
|
|
|
|
|
|
|
|
|
|
if (time - startTime >= targetMsec)
|
|
|
|
if (time - startTime >= targetMsec)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
end = true;
|
|
|
|
isEnded = true;
|
|
|
|
Call(args);
|
|
|
|
Call(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Timer::IsEnd()
|
|
|
|
bool Timer::IsEnded()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return end;
|
|
|
|
return isEnded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timer::Stop()
|
|
|
|
void Timer::Stop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
end = true;
|
|
|
|
isEnded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timer::Restart(int msec)
|
|
|
|
void Timer::Restart(int msec)
|
|
|
@ -59,7 +55,7 @@ void Timer::Restart(int msec)
|
|
|
|
|
|
|
|
|
|
|
|
void Timer::Start()
|
|
|
|
void Timer::Start()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
end = false;
|
|
|
|
isEnded = false;
|
|
|
|
|
|
|
|
|
|
|
|
const auto duration = chrono::system_clock::now().time_since_epoch();
|
|
|
|
const auto duration = chrono::system_clock::now().time_since_epoch();
|
|
|
|
const auto msec = chrono::duration_cast<chrono::milliseconds>(duration).count();
|
|
|
|
const auto msec = chrono::duration_cast<chrono::milliseconds>(duration).count();
|
|
|
@ -172,12 +168,12 @@ void TimerAPI::StopTimer(int timerid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TimerAPI::IsEndTimer(int timerid)
|
|
|
|
bool TimerAPI::IsTimerElapsed(int timerid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
bool ret = false;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = timers.at(timerid)->IsEnd();
|
|
|
|
ret = timers.at(timerid)->IsEnded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|