From f37c252dbea0c9a0ad93273d2df5b3cf662ecada Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 23 Dec 2018 05:07:11 +0800 Subject: [PATCH] [Server] Add timers support to Mono --- apps/openmw-mp/Script/API/TimerAPI.cpp | 31 +++++ apps/openmw-mp/Script/API/TimerAPI.hpp | 10 ++ apps/openmw-mp/Script/LangMono/LangMono.cpp | 119 ++++++++++++++++++-- apps/openmw-mp/Script/LangMono/LangMono.hpp | 4 + apps/openmw-mp/Script/ScriptFunction.cpp | 82 +++++++++++++- apps/openmw-mp/Script/ScriptFunction.hpp | 17 ++- 6 files changed, 249 insertions(+), 14 deletions(-) diff --git a/apps/openmw-mp/Script/API/TimerAPI.cpp b/apps/openmw-mp/Script/API/TimerAPI.cpp index 7489497d9..6aac348b5 100644 --- a/apps/openmw-mp/Script/API/TimerAPI.cpp +++ b/apps/openmw-mp/Script/API/TimerAPI.cpp @@ -26,6 +26,15 @@ Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::strin } #endif +#ifdef ENABLE_MONO +Timer::Timer(MonoObject *callback, long msec, const std::string &def, std::vector args) : ScriptFunction(callback, 'v', def) +{ + targetMsec = msec; + this->args = args; + end = true; +} +#endif + void Timer::Tick() { if (end) @@ -93,6 +102,28 @@ int TimerAPI::CreateTimerLua(lua_State *lua, ScriptFuncLua callback, long msec, } #endif +#if defined(ENABLE_MONO) +int TimerAPI::CreateTimerMono(MonoObject *callback, long msec, const std::string& def, std::vector args) +{ + int id = -1; + + for (auto timer : timers) + { + if (timer.second != nullptr) + continue; + timer.second = new Timer(callback, msec, def, args); + id = timer.first; + } + + if (id == -1) + { + timers[pointer] = new Timer(callback, msec, def, args); + id = pointer; + pointer++; + } + return id; +} +#endif int TimerAPI::CreateTimer(ScriptFunc callback, long msec, const std::string &def, std::vector args) { diff --git a/apps/openmw-mp/Script/API/TimerAPI.hpp b/apps/openmw-mp/Script/API/TimerAPI.hpp index b20be12d6..ae324329d 100644 --- a/apps/openmw-mp/Script/API/TimerAPI.hpp +++ b/apps/openmw-mp/Script/API/TimerAPI.hpp @@ -10,6 +10,10 @@ #include