Skip to content

Commit 649f57f

Browse files
committed
Implemented automatic debugger connection and setup when EnableLuaDebugging = 1 in config
Allowed objects in master script state to work properly and fully even with multithreaded instructions (by running them in the same manner but singlethreaded)
1 parent 096aa68 commit 649f57f

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

Source/Entities/MovableObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void MovableObject::Clear() {
8585
m_NumberValueMap.clear();
8686
m_ObjectValueMap.clear();
8787
m_ThreadedLuaState = nullptr;
88-
m_ForceIntoMasterLuaState = false;
88+
m_ForceIntoMasterLuaState = g_SettingsMan.EnableLuaDebugging();
8989
m_ScriptObjectName.clear();
9090
m_ScreenEffectFile.Reset();
9191
m_pScreenEffect = 0;

Source/Managers/LuaMan.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void LuaStateWrapper::Initialize() {
276276
if (g_SettingsMan.EnableLuaDebugging()) {
277277
// Enable Lua debugging
278278
// Right now we're not requiring the mobdebug module because it doesn't play well with multithreading- we need this to additionally push everything into one Lua state.
279-
luaL_dostring(m_State, "require(\"mobdebug\").coro(); --require(\"mobdebug\").start();");
279+
luaL_dostring(m_State, "require(\"mobdebug\").coro(); require(\"mobdebug\").start();");
280280
}
281281
}
282282

@@ -327,7 +327,9 @@ void LuaMan::Initialize() {
327327
m_MasterScriptState.Initialize();
328328

329329
int luaStateCount = std::thread::hardware_concurrency();
330-
if (g_SettingsMan.GetNumberOfLuaStatesOverride() != -1) {
330+
if (g_SettingsMan.EnableLuaDebugging()) {
331+
luaStateCount = 0;
332+
} else if (g_SettingsMan.GetNumberOfLuaStatesOverride() != -1) {
331333
luaStateCount = g_SettingsMan.GetNumberOfLuaStatesOverride();
332334
}
333335

Source/Managers/MovableMan.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,14 @@ void MovableMan::Update() {
13411341

13421342
const std::string threadedUpdate = "ThreadedUpdate"; // avoid string reconstruction
13431343

1344+
g_LuaMan.SetThreadLuaStateOverride(&g_LuaMan.GetMasterScriptState());
1345+
for (MovableObject* mo: g_LuaMan.GetMasterScriptState().GetRegisteredMOs()) {
1346+
if (ValidMO(mo->GetRootParent())) {
1347+
mo->RunScriptedFunctionInAppropriateScripts(threadedUpdate, false, false, {}, {}, {});
1348+
}
1349+
}
1350+
g_LuaMan.SetThreadLuaStateOverride(nullptr);
1351+
13441352
LuaStatesArray& luaStates = g_LuaMan.GetThreadedScriptStates();
13451353
g_ThreadMan.GetPriorityThreadPool().parallelize_loop(luaStates.size(),
13461354
[&](int start, int end) {
@@ -1364,6 +1372,14 @@ void MovableMan::Update() {
13641372

13651373
const std::string syncedUpdate = "SyncedUpdate"; // avoid string reconstruction
13661374

1375+
g_LuaMan.SetThreadLuaStateOverride(&g_LuaMan.GetMasterScriptState());
1376+
for (MovableObject* mo: g_LuaMan.GetMasterScriptState().GetRegisteredMOs()) {
1377+
if (ValidMO(mo->GetRootParent())) {
1378+
mo->RunScriptedFunctionInAppropriateScripts(syncedUpdate, false, false, {}, {}, {});
1379+
}
1380+
}
1381+
g_LuaMan.SetThreadLuaStateOverride(nullptr);
1382+
13671383
for (LuaStateWrapper& luaState: g_LuaMan.GetThreadedScriptStates()) {
13681384
g_LuaMan.SetThreadLuaStateOverride(&luaState);
13691385

@@ -1754,6 +1770,14 @@ void MovableMan::UpdateControllers() {
17541770
actor->GetController()->Update();
17551771
}
17561772

1773+
g_LuaMan.SetThreadLuaStateOverride(&g_LuaMan.GetMasterScriptState());
1774+
for (Actor* actor: m_Actors) {
1775+
if (actor->GetLuaState() == &g_LuaMan.GetMasterScriptState() && actor->GetController()->ShouldUpdateAIThisFrame()) {
1776+
actor->RunScriptedFunctionInAppropriateScripts("ThreadedUpdateAI", false, true, {}, {}, {});
1777+
}
1778+
}
1779+
g_LuaMan.SetThreadLuaStateOverride(nullptr);
1780+
17571781
LuaStatesArray& luaStates = g_LuaMan.GetThreadedScriptStates();
17581782
g_ThreadMan.GetPriorityThreadPool().parallelize_loop(luaStates.size(),
17591783
[&](int start, int end) {

Source/Managers/SettingsMan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ namespace RTE {
389389
bool m_ShowMetaScenes; //!< Show MetaScenes in editors and activities.
390390

391391
bool m_DisableLuaJIT; //!< Whether to disable LuaJIT or not. Disabling will skip loading the JIT library entirely as just setting 'jit.off()' seems to have no visible effect.
392-
bool m_EnableLuaDebugging; //!< Whether the Lua debugger mode is enabled or not. This will disable JITing and will attempt to connect to a debugger on launch.
392+
bool m_EnableLuaDebugging; //!< Whether the Lua debugger mode is enabled or not. This will disable MT and attempt to connect to a debugger on launch.
393393
int m_RecommendedMOIDCount; //!< Recommended max MOID's before removing actors from scenes.
394394
int m_SceneBackgroundAutoScaleMode; //!< Scene background layer auto-scaling mode. 0 for off, 1 for fit screen dimensions and 2 for always upscaled to x2.
395395
bool m_DisableFactionBuyMenuThemes; //!< Whether faction BuyMenu theme support is disabled.

0 commit comments

Comments
 (0)