@@ -1568,35 +1568,37 @@ void callLuaFunctionOnMORecursive(MovableObject* mo, const std::string& function
1568
1568
Attachable* attachable = *attachablrItr;
1569
1569
++attachablrItr;
1570
1570
1571
- attachable->RunScriptedFunctionInAppropriateScripts (" OnGlobalMessage " , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1571
+ attachable->RunScriptedFunctionInAppropriateScripts (functionName , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1572
1572
callLuaFunctionOnMORecursive (attachable, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1573
1573
}
1574
1574
1575
1575
for (auto woundItr = mosr->GetWoundList ().begin (); woundItr != mosr->GetWoundList ().end (); ) {
1576
1576
AEmitter* wound = *woundItr;
1577
1577
++woundItr;
1578
1578
1579
- wound->RunScriptedFunctionInAppropriateScripts (" OnGlobalMessage " , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1579
+ wound->RunScriptedFunctionInAppropriateScripts (functionName , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1580
1580
callLuaFunctionOnMORecursive (wound, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1581
1581
}
1582
1582
}
1583
1583
1584
- mo->RunScriptedFunctionInAppropriateScripts (" OnGlobalMessage " , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1584
+ mo->RunScriptedFunctionInAppropriateScripts (functionName , false , false , functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1585
1585
};
1586
1586
1587
1587
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1588
1588
1589
- void MovableMan::RunLuaFunctionOnAllMOs (const std::string &functionName, const std::vector<const Entity*> &functionEntityArguments, const std::vector<std::string_view> &functionLiteralArguments, const std::vector<LuabindObjectWrapper*> &functionObjectArguments, ThreadScriptsToRun scriptsToRun) {
1590
- for (Actor* actor : m_AddedActors) {
1591
- callLuaFunctionOnMORecursive (actor, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1592
- }
1589
+ void MovableMan::RunLuaFunctionOnAllMOs (const std::string &functionName, bool includeAdded, const std::vector<const Entity*> &functionEntityArguments, const std::vector<std::string_view> &functionLiteralArguments, const std::vector<LuabindObjectWrapper*> &functionObjectArguments, ThreadScriptsToRun scriptsToRun) {
1590
+ if (includeAdded) {
1591
+ for (Actor* actor : m_AddedActors) {
1592
+ callLuaFunctionOnMORecursive (actor, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1593
+ }
1593
1594
1594
- for (MovableObject *item : m_AddedItems) {
1595
- callLuaFunctionOnMORecursive (item, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1596
- }
1595
+ for (MovableObject *item : m_AddedItems) {
1596
+ callLuaFunctionOnMORecursive (item, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1597
+ }
1597
1598
1598
- for (MovableObject* particle : m_AddedParticles) {
1599
- callLuaFunctionOnMORecursive (particle, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1599
+ for (MovableObject* particle : m_AddedParticles) {
1600
+ callLuaFunctionOnMORecursive (particle, functionName, functionEntityArguments, functionLiteralArguments, functionObjectArguments, scriptsToRun);
1601
+ }
1600
1602
}
1601
1603
1602
1604
for (Actor *actor : m_Actors) {
@@ -1728,28 +1730,43 @@ void MovableMan::Update()
1728
1730
std::deque<MovableObject *>::iterator parIt;
1729
1731
std::deque<MovableObject *>::iterator midIt;
1730
1732
1731
- // Update all scripts for all objects
1733
+ // Update all multithreaded scripts for all objects
1734
+ g_PerformanceMan.StartPerformanceMeasurement (PerformanceMan::ScriptsUpdate);
1732
1735
{
1733
1736
ZoneScopedN (" Multithreaded Scripts Update" );
1734
1737
1735
- g_PerformanceMan.StartPerformanceMeasurement (PerformanceMan::ScriptsUpdate);
1738
+ const std::string threadedUpdate = " Update" ; // avoid string reconstruction
1739
+
1736
1740
LuaStatesArray& luaStates = g_LuaMan.GetThreadedScriptStates ();
1737
1741
std::for_each (std::execution::par, luaStates.begin (), luaStates.end (),
1738
1742
[&](LuaStateWrapper& luaState) {
1739
1743
g_LuaMan.SetThreadLuaStateOverride (&luaState);
1740
1744
1741
- // We may have new MOs registered to us by objects creating other things and being initialized
1742
- // So we need to copy this list before using it
1743
- std::unordered_set<MovableObject *> registeredMOs = luaState.GetRegisteredMOs ();
1744
- for (MovableObject *mo : registeredMOs) {
1745
- mo->UpdateScripts (ThreadScriptsToRun::MultiThreaded);
1745
+ for (MovableObject *mo : luaState.GetRegisteredMOs ()) {
1746
+ mo->RunScriptedFunctionInAppropriateScripts (threadedUpdate, false , false , {}, {}, {}, ThreadScriptsToRun::MultiThreaded);
1746
1747
}
1747
1748
1748
1749
g_LuaMan.SetThreadLuaStateOverride (nullptr );
1749
1750
});
1750
- g_PerformanceMan.StopPerformanceMeasurement (PerformanceMan::ScriptsUpdate);
1751
1751
}
1752
1752
1753
+ {
1754
+ ZoneScopedN (" Multithreaded Scripts SyncedUpdate" );
1755
+
1756
+ const std::string syncedUpdate = " SyncedUpdate" ; // avoid string reconstruction
1757
+
1758
+ for (LuaStateWrapper& luaState : g_LuaMan.GetThreadedScriptStates ()) {
1759
+ g_LuaMan.SetThreadLuaStateOverride (&luaState);
1760
+
1761
+ for (MovableObject* mo : luaState.GetRegisteredMOs ()) {
1762
+ mo->RunScriptedFunctionInAppropriateScripts (syncedUpdate, false , false , {}, {}, {}, ThreadScriptsToRun::MultiThreaded);
1763
+ }
1764
+
1765
+ g_LuaMan.SetThreadLuaStateOverride (nullptr );
1766
+ }
1767
+ }
1768
+ g_PerformanceMan.StopPerformanceMeasurement (PerformanceMan::ScriptsUpdate);
1769
+
1753
1770
{
1754
1771
{
1755
1772
ZoneScopedN (" Actors Update" );
0 commit comments