[Server] Use clearer variable & function names in TimerAPI

pull/506/head
David Cernat 6 years ago
parent 42b5a8054f
commit 6e1504f0a1

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

@ -1,7 +1,3 @@
//
// Created by koncord on 15.03.16.
//
#ifndef OPENMW_TIMERAPI_HPP
#define OPENMW_TIMERAPI_HPP
@ -27,7 +23,7 @@ namespace mwmp
#endif
void Tick();
bool IsEnd();
bool IsEnded();
void Stop();
void Start();
void Restart(int msec);
@ -36,7 +32,7 @@ namespace mwmp
std::string publ, arg_types;
std::vector<boost::any> args;
Script *scr;
bool end;
bool isEnded;
};
class TimerAPI
@ -50,7 +46,7 @@ namespace mwmp
static void ResetTimer(int timerid, long msec);
static void StartTimer(int timerid);
static void StopTimer(int timerid);
static bool IsEndTimer(int timerid);
static bool IsTimerElapsed(int timerid);
static void Terminate();

@ -54,5 +54,5 @@ void ScriptFunctions::FreeTimer(int timerId) noexcept
bool ScriptFunctions::IsTimerElapsed(int timerId) noexcept
{
return TimerAPI::IsEndTimer(timerId);
return TimerAPI::IsTimerElapsed(timerId);
}

Loading…
Cancel
Save