Skip to content

Commit 781515b

Browse files
committed
fix: fix nodejs engine
1 parent 9024fce commit 781515b

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/legacy/main/NodeJsHelper.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
#include "engine/EngineOwnData.h"
1111
#include "engine/RemoteCall.h"
1212
#include "ll/api/chrono/GameChrono.h"
13+
#include "ll/api/coro/CoroTask.h"
1314
#include "ll/api/io/FileUtils.h"
14-
#include "ll/api/schedule/Scheduler.h"
15-
#include "ll/api/schedule/Task.h"
1615
#include "ll/api/service/ServerInfo.h"
16+
#include "ll/api/thread/ThreadPoolExecutor.h"
1717
#include "ll/api/utils/StringUtils.h"
1818
#include "main/Configs.h"
1919
#include "main/Global.h"
2020
#include "uv/uv.h"
2121
#include "v8/v8.h"
2222

2323
#include <functional>
24+
#include <ll/api/service/GamingStatus.h>
2425

25-
ll::schedule::ServerTimeScheduler nodeScheduler;
2626
using ll::chrono_literals::operator""_tick;
2727

2828
// pre-declare
@@ -38,8 +38,8 @@ std::unique_ptr<node::MultiIsolatePlatform>
3838
std::unordered_map<script::ScriptEngine*, node::Environment*> environments;
3939
std::unordered_map<script::ScriptEngine*, std::unique_ptr<node::CommonEnvironmentSetup>>* setups =
4040
new std::unordered_map<script::ScriptEngine*, std::unique_ptr<node::CommonEnvironmentSetup>>();
41-
std::unordered_map<node::Environment*, bool> isRunning;
42-
std::unordered_map<node::Environment*, uint64> uvLoopTask;
41+
std::unordered_map<node::Environment*, bool> isRunning;
42+
std::vector<node::Environment*> uvLoopTask;
4343

4444
bool initNodeJs() {
4545
// Init NodeJs
@@ -165,22 +165,23 @@ bool loadPluginCode(script::ScriptEngine* engine, std::string entryScriptPath, s
165165
}
166166

167167
// Start libuv event loop
168-
uvLoopTask[env] =
169-
nodeScheduler
170-
.add<ll::schedule::RepeatTask>(
171-
2_tick,
172-
[engine, env, isRunningMap{&isRunning}, eventLoop{it->second->event_loop()}]() {
173-
if (!(ll::getGamingStatus() != ll::GamingStatus::Running) && (*isRunningMap)[env]) {
174-
EngineScope enter(engine);
175-
uv_run(eventLoop, UV_RUN_NOWAIT);
176-
}
177-
if ((ll::getGamingStatus() != ll::GamingStatus::Running)) {
178-
uv_stop(eventLoop);
179-
lse::getSelfPluginInstance().getLogger().debug("Destroy ServerStopping");
180-
}
168+
uvLoopTask.push_back(env);
169+
ll::coro::keepThis(
170+
[engine, env, isRunningMap{&isRunning}, eventLoop{it->second->event_loop()}]() -> ll::coro::CoroTask<> {
171+
using namespace ll::chrono_literals;
172+
while (std::find(uvLoopTask.begin(), uvLoopTask.end(), env) != uvLoopTask.end()) {
173+
co_await 2_tick;
174+
if (!(ll::getGamingStatus() != ll::GamingStatus::Running) && (*isRunningMap)[env]) {
175+
EngineScope enter(engine);
176+
uv_run(eventLoop, UV_RUN_NOWAIT);
181177
}
182-
)
183-
->getId();
178+
if ((ll::getGamingStatus() != ll::GamingStatus::Running)) {
179+
uv_stop(eventLoop);
180+
lse::getSelfPluginInstance().getLogger().debug("Destroy ServerStopping");
181+
}
182+
}
183+
}
184+
).launch(ll::thread::ThreadPoolExecutor::getDefault());
184185

185186
return true;
186187
} catch (...) {
@@ -210,9 +211,9 @@ bool stopEngine(node::Environment* env) {
210211
node::Stop(env);
211212

212213
// Stop libuv event loop
213-
auto it = uvLoopTask.find(env);
214+
auto it = std::find(uvLoopTask.begin(), uvLoopTask.end(), env);
214215
if (it != uvLoopTask.end()) {
215-
nodeScheduler.remove(it->second);
216+
uvLoopTask.erase(it);
216217
}
217218

218219
return true;

src/lse/PluginMigration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa
9898
.name = ll::string_utils::u8str2str(pluginFileBaseName.u8string()),
9999
.type = pluginType,
100100
.dependencies =
101-
std::unordered_set<ll::mod::Dependency>{
102-
ll::mod::Dependency{
101+
ll::SmallDenseSet<ll::mod::Dependency>{
102+
ll::mod::Dependency{
103103
.name = self.getManifest().name,
104104
}, },
105105
};

0 commit comments

Comments
 (0)