[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 "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(...)
{ {

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

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

Loading…
Cancel
Save