diff --git a/apps/openmw-mp/Timer.cpp b/apps/openmw-mp/Timer.cpp index 1eb727401..86d96fcb4 100644 --- a/apps/openmw-mp/Timer.cpp +++ b/apps/openmw-mp/Timer.cpp @@ -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 TimerController::create(sol::environment env, sol::functi return timers.back(); } -void TimerController::kill(std::shared_ptr timer) +void TimerController::kill(const std::shared_ptr &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); } } diff --git a/apps/openmw-mp/Timer.hpp b/apps/openmw-mp/Timer.hpp index 1f4007f20..975ecd54f 100644 --- a/apps/openmw-mp/Timer.hpp +++ b/apps/openmw-mp/Timer.hpp @@ -38,7 +38,7 @@ public: static void Init(LuaState &lua); public: std::shared_ptr create(sol::environment env, sol::function callback, long msec, sol::table args); - void kill(std::shared_ptr timer); + void kill(const std::shared_ptr &timer); void terminate(); void tick();