|
4 | 4 | #include "engine/EngineManager.h" |
5 | 5 | #include "engine/EngineOwnData.h" |
6 | 6 | #include "engine/MessageSystem.h" |
| 7 | +#include "ll/api/schedule/Scheduler.h" |
7 | 8 | #include "ll/api/schedule/scheduler.h" |
8 | 9 |
|
9 | 10 | #include <chrono> |
|
15 | 16 | #include <shared_mutex> |
16 | 17 | #include <vector> |
17 | 18 |
|
18 | | -std::atomic_uint timeTaskId = 0; |
19 | | -std::mutex locker; |
20 | | -ll::schedule::GameTickScheduler taskScheduler; |
| 19 | +std::atomic_uint timeTaskId = 0; |
| 20 | +std::mutex locker; |
| 21 | +ll::schedule::ServerTimeScheduler taskScheduler; |
21 | 22 | struct TimeTaskData { |
22 | 23 | uint64 task; |
23 | 24 | script::Global<Function> func; |
@@ -69,7 +70,7 @@ std::unordered_map<int, TimeTaskData> timeTaskMap; |
69 | 70 | // taskScheduler.add<ll::schedule::DelayTask>( |
70 | 71 | // std::chrono::milliseconds(timeout), |
71 | 72 | // [engine, func = std::move(func), paras = std::move(tmp)]() { |
72 | | -// if ((ll::getServerStatus() != ll::ServerStatus::Running)) return; |
| 73 | +// if ((ll::getServerStatus() == ll::ServerStatus::Stopping)) return; |
73 | 74 | // if (!EngineManager::isValid(engine)) return; |
74 | 75 | // EngineScope enter(engine); |
75 | 76 | // if (paras.empty()) { |
@@ -97,7 +98,7 @@ int NewTimeout(Local<Function> func, vector<Local<Value>> paras, int timeout) { |
97 | 98 | std::chrono::milliseconds(timeout), |
98 | 99 | [engine{EngineScope::currentEngine()}, id{tid}]() { |
99 | 100 | try { |
100 | | - if ((ll::getServerStatus() != ll::ServerStatus::Running)) return; |
| 101 | + if ((ll::getServerStatus() == ll::ServerStatus::Stopping)) return; |
101 | 102 | if (!EngineManager::isValid(engine)) return; |
102 | 103 | // lock after enter EngineScope to prevent deadlock |
103 | 104 | EngineScope scope(engine); |
@@ -144,7 +145,7 @@ int NewTimeout(Local<String> func, int timeout) { |
144 | 145 | std::chrono::milliseconds(timeout), |
145 | 146 | [engine{EngineScope::currentEngine()}, id{tid}]() { |
146 | 147 | try { |
147 | | - if ((ll::getServerStatus() != ll::ServerStatus::Running)) return; |
| 148 | + if ((ll::getServerStatus() == ll::ServerStatus::Stopping)) return; |
148 | 149 | if (!EngineManager::isValid(engine)) return; |
149 | 150 | EngineScope scope(engine); |
150 | 151 | TimeTaskData taskData; |
@@ -184,7 +185,7 @@ int NewInterval(Local<Function> func, vector<Local<Value>> paras, int timeout) { |
184 | 185 | std::chrono::milliseconds(timeout), |
185 | 186 | [engine{EngineScope::currentEngine()}, id{tid}]() { |
186 | 187 | try { |
187 | | - if ((ll::getServerStatus() != ll::ServerStatus::Running)) return; |
| 188 | + if ((ll::getServerStatus() == ll::ServerStatus::Stopping)) return; |
188 | 189 | if (!EngineManager::isValid(engine)) { |
189 | 190 | ClearTimeTask(id); |
190 | 191 | return; |
@@ -235,7 +236,7 @@ int NewInterval(Local<String> func, int timeout) { |
235 | 236 | std::chrono::milliseconds(timeout), |
236 | 237 | [engine{EngineScope::currentEngine()}, id{tid}]() { |
237 | 238 | try { |
238 | | - if ((ll::getServerStatus() != ll::ServerStatus::Running)) return; |
| 239 | + if ((ll::getServerStatus() == ll::ServerStatus::Stopping)) return; |
239 | 240 | if (!EngineManager::isValid(engine)) { |
240 | 241 | ClearTimeTask(id); |
241 | 242 | return; |
|
0 commit comments