forked from teamnwah/openmw-tes3coop
[Server] Change signature of TimerController::kill, validate callback
This commit is contained in:
parent
51a92bcf8f
commit
2019128d92
2 changed files with 12 additions and 6 deletions
|
@ -50,14 +50,14 @@ Timer::Timer(sol::environment &env, sol::function &callback, long msec, sol::tab
|
|||
data(std::move(args)),
|
||||
env(std::move(env))
|
||||
{
|
||||
printf("Timer::Timer()\n");
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_TRACE, "Timer::Timer()");
|
||||
targetMsec = msec;
|
||||
end = true;
|
||||
}
|
||||
|
||||
Timer::~Timer()
|
||||
{
|
||||
printf("Timer::~Timer()\n");
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_TRACE, "Timer::~Timer()");
|
||||
}
|
||||
|
||||
void Timer::tick()
|
||||
|
@ -71,7 +71,13 @@ void Timer::tick()
|
|||
if (time - startTime >= targetMsec)
|
||||
{
|
||||
end = true;
|
||||
callback.call(data);
|
||||
if(callback.valid())
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_TRACE, "Timer::tick time expired, callback %p valid", callback.registry_index());
|
||||
callback.call(data);
|
||||
}
|
||||
else
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_TRACE, "Timer::tick time expired, callback invalid");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,12 +100,12 @@ std::shared_ptr<Timer> TimerController::create(sol::environment env, sol::functi
|
|||
return timers.back();
|
||||
}
|
||||
|
||||
void TimerController::kill(std::shared_ptr<Timer> timer)
|
||||
void TimerController::kill(const std::shared_ptr<Timer> &timer)
|
||||
{
|
||||
auto it = find(timers.begin(), timers.end(), timer);
|
||||
if (it != timers.end())
|
||||
{
|
||||
printf("TimerController::kill\n");
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_TRACE, "Timer %p killed\n", timer.get());
|
||||
timers.erase(it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
static void Init(LuaState &lua);
|
||||
public:
|
||||
std::shared_ptr<Timer> create(sol::environment env, sol::function callback, long msec, sol::table args);
|
||||
void kill(std::shared_ptr<Timer> timer);
|
||||
void kill(const std::shared_ptr<Timer> &timer);
|
||||
|
||||
void terminate();
|
||||
void tick();
|
||||
|
|
Loading…
Reference in a new issue