|
4 | 4 | #include "api/PlayerAPI.h" |
5 | 5 | #include "engine/EngineOwnData.h" |
6 | 6 | #include "engine/GlobalShareData.h" |
| 7 | +#include "ll/api/chrono/GameChrono.h" |
7 | 8 | #include "ll/api/event/EventBus.h" |
| 9 | +#include "ll/api/schedule/Scheduler.h" |
| 10 | +#include "ll/api/schedule/Task.h" |
8 | 11 | #include "ll/api/service/Bedrock.h" |
9 | 12 | #include "main/Global.hpp" |
10 | 13 | #include <exception> |
11 | 14 | #include <list> |
| 15 | +#include <shared_mutex> |
12 | 16 |
|
13 | 17 | #include "ll/api/event/EventBus.h" |
14 | 18 | #include "ll/api/event/player/PlayerChatEvent.h" |
@@ -1449,36 +1453,35 @@ void InitBasicEventListeners() { |
1449 | 1453 | // return true; |
1450 | 1454 | // }); |
1451 | 1455 |
|
1452 | | - // // 植入tick |
1453 | | - // Schedule::repeat( |
1454 | | - // []() { |
1455 | | - // #ifndef LLSE_BACKEND_NODEJS |
1456 | | - // try { |
1457 | | - // std::list<ScriptEngine *> tmpList; |
1458 | | - // { |
1459 | | - // SRWLockSharedHolder lock(globalShareData->engineListLock); |
1460 | | - // // low efficiency |
1461 | | - // tmpList = globalShareData->globalEngineList; |
1462 | | - // } |
1463 | | - // for (auto engine : tmpList) { |
1464 | | - // if (EngineManager::isValid(engine) && |
1465 | | - // EngineManager::getEngineType(engine) == LLSE_BACKEND_TYPE) |
1466 | | - // { |
1467 | | - // EngineScope enter(engine); |
1468 | | - // engine->messageQueue()->loopQueue( |
1469 | | - // script::utils::MessageQueue::LoopType::kLoopOnce); |
1470 | | - // } |
1471 | | - // } |
1472 | | - // } catch (...) { |
1473 | | - // logger.error("Error occurred in Engine Message Loop!"); |
1474 | | - // logger.error("Uncaught Exception Detected!"); |
1475 | | - // } |
1476 | | - // #endif |
1477 | | - // // Call tick event |
1478 | | - // IF_LISTENED(EVENT_TYPES::onTick) { CallEvent(EVENT_TYPES::onTick); |
1479 | | - // } IF_LISTENED_END(EVENT_TYPES::onTick); |
1480 | | - // }, |
1481 | | - // 1); |
| 1456 | + // 植入tick |
| 1457 | + ll::schedule::ServerTimeScheduler scheduler; |
| 1458 | + scheduler.add<ll::schedule::RepeatTask>(ll::chrono::ticks(1), []() { |
| 1459 | +#ifndef LLSE_BACKEND_NODEJS |
| 1460 | + try { |
| 1461 | + std::list<ScriptEngine *> tmpList; |
| 1462 | + { |
| 1463 | + std::shared_lock<std::shared_mutex> lock( |
| 1464 | + globalShareData->engineListLock); |
| 1465 | + // low efficiency |
| 1466 | + tmpList = globalShareData->globalEngineList; |
| 1467 | + } |
| 1468 | + for (auto engine : tmpList) { |
| 1469 | + if (EngineManager::isValid(engine) && |
| 1470 | + EngineManager::getEngineType(engine) == LLSE_BACKEND_TYPE) { |
| 1471 | + EngineScope enter(engine); |
| 1472 | + engine->messageQueue()->loopQueue( |
| 1473 | + script::utils::MessageQueue::LoopType::kLoopOnce); |
| 1474 | + } |
| 1475 | + } |
| 1476 | + } catch (...) { |
| 1477 | + logger.error("Error occurred in Engine Message Loop!"); |
| 1478 | + logger.error("Uncaught Exception Detected!"); |
| 1479 | + } |
| 1480 | +#endif |
| 1481 | + // Call tick event |
| 1482 | + IF_LISTENED(EVENT_TYPES::onTick) { CallEvent(EVENT_TYPES::onTick); } |
| 1483 | + IF_LISTENED_END(EVENT_TYPES::onTick); |
| 1484 | + }); |
1482 | 1485 | } |
1483 | 1486 |
|
1484 | 1487 | /* onTurnLectern // 由于还是不能拦截掉书,暂时注释 |
|
0 commit comments