Skip to content

Commit 530a471

Browse files
committed
Added requested synced updates
1 parent 45ae371 commit 530a471

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

Entities/MovableObject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void MovableObject::Clear()
124124

125125
m_SimUpdatesBetweenScriptedUpdates = 1;
126126
m_SimUpdatesSinceLastScriptedUpdate = 0;
127+
m_RequestedSyncedUpdate = false;
127128
}
128129

129130
LuaStateWrapper & MovableObject::GetAndLockStateForScript(const std::string &scriptPath, const LuaFunction *function) {

Entities/MovableObject.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,22 @@ enum MOType
18951895
/// </summary>
18961896
virtual void OnSave() { RunScriptedFunctionInAppropriateScripts("OnSave"); }
18971897

1898+
/// <summary>
1899+
/// Requests a synced update for the MO this frame.
1900+
/// </summary>
1901+
virtual void RequestSyncedUpdate() { m_RequestedSyncedUpdate = true; }
1902+
1903+
/// <summary>
1904+
/// Resets the requested update flag.
1905+
/// </summary>
1906+
virtual void ResetRequestedSyncedUpdateFlag() { m_RequestedSyncedUpdate = false; }
1907+
1908+
/// <summary>
1909+
/// Returns whether this MO has requested a synced update this frame.
1910+
/// </summary>
1911+
/// <returns>Whether this MO has requested a synced update this frame.</returns>
1912+
virtual bool HasRequestedSyncedUpdate() { return m_RequestedSyncedUpdate; }
1913+
18981914
//////////////////////////////////////////////////////////////////////////////////////////
18991915
// Protected member variable and method declarations
19001916

@@ -2054,6 +2070,8 @@ enum MOType
20542070
std::unordered_map<std::string, bool> m_AllLoadedScripts; //!< A map of script paths to the enabled state of the given script.
20552071
std::unordered_map<std::string, std::vector<LuaFunction>> m_FunctionsAndScripts; //!< A map of function names to vectors of Lua functions. Used to maintain script execution order and avoid extraneous Lua calls.
20562072

2073+
bool m_RequestedSyncedUpdate; //!< For optimisation purposes, multithreaded scripts explicitly request a synced update if they want one.
2074+
20572075
std::unordered_map<std::string, std::string> m_StringValueMap; //<! Map to store any generic strings available from script
20582076
std::unordered_map<std::string, double> m_NumberValueMap; //<! Map to store any generic numbers available from script
20592077
std::unordered_map<std::string, Entity*> m_ObjectValueMap; //<! Map to store any generic object pointers available from script

Lua/LuaBindingsEntities.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ namespace RTE {
10841084
.def("MoveOutOfTerrain", &MovableObject::MoveOutOfTerrain)
10851085
.def("RotateOffset", &MovableObject::RotateOffset)
10861086
.def("SendMessage", &LuaAdaptersMovableObject::SendMessage1)
1087-
.def("SendMessage", &LuaAdaptersMovableObject::SendMessage2);
1087+
.def("SendMessage", &LuaAdaptersMovableObject::SendMessage2)
1088+
.def("RequestSyncedUpdate", &MovableObject::RequestSyncedUpdate);
10881089
}
10891090

10901091
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Managers/MovableMan.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,10 @@ void MovableMan::Update()
17591759
g_LuaMan.SetThreadLuaStateOverride(&luaState);
17601760

17611761
for (MovableObject* mo : luaState.GetRegisteredMOs()) {
1762-
mo->RunScriptedFunctionInAppropriateScripts(syncedUpdate, false, false, {}, {}, {}, ThreadScriptsToRun::MultiThreaded);
1762+
if (mo->HasRequestedSyncedUpdate()) {
1763+
mo->RunScriptedFunctionInAppropriateScripts(syncedUpdate, false, false, {}, {}, {}, ThreadScriptsToRun::MultiThreaded);
1764+
mo->ResetRequestedSyncedUpdateFlag();
1765+
}
17631766
}
17641767

17651768
g_LuaMan.SetThreadLuaStateOverride(nullptr);

0 commit comments

Comments
 (0)