Skip to content

Commit 1e29c7b

Browse files
authored
Merge pull request #11 from cortex-command-community/multithreading-settings
Multithreading Settings
2 parents 5b2e683 + 0a8ae1a commit 1e29c7b

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

Source/Entities/Activity.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "GUIFont.h"
1717
#include "AllegroBitmap.h"
1818

19+
#include "RTETools.h"
20+
1921
namespace RTE {
2022

2123
AbstractClassInfo(Activity, Entity);
@@ -284,6 +286,9 @@ void Activity::Clear() {
284286
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
285287

286288
int Activity::Start() {
289+
// Reseed the RNG for determinism
290+
SeedRNG();
291+
287292
if (m_ActivityState != ActivityState::Editing) {
288293
m_ActivityState = ActivityState::Running;
289294
}

Source/Entities/Actor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,15 +1287,17 @@ void Actor::OnNewMovePath() {
12871287
//////////////////////////////////////////////////////////////////////////////////////////
12881288

12891289
void Actor::PreControllerUpdate() {
1290-
if (m_UpdateMovePath) {
1291-
UpdateMovePath();
1292-
}
1293-
12941290
if (m_PathRequest && m_PathRequest->complete) {
12951291
m_MovePath = const_cast<std::list<Vector> &>(m_PathRequest->path);
12961292
m_PathRequest.reset();
12971293
OnNewMovePath();
12981294
}
1295+
1296+
// We update this after, because pathing requests are forced to take at least 1 frame for the sake of determinism for now.
1297+
// In future maybe we can move this back, but it doesn't make much difference (the threadpool submission overhead makes it extremely unlikely that it would complete in less time anyways)
1298+
if (m_UpdateMovePath) {
1299+
UpdateMovePath();
1300+
}
12991301
}
13001302

13011303
//////////////////////////////////////////////////////////////////////////////////////////

Source/Managers/LuaMan.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ namespace RTE {
294294
void LuaMan::Initialize() {
295295
m_MasterScriptState.Initialize();
296296

297-
m_ScriptStates = std::vector<LuaStateWrapper>(std::thread::hardware_concurrency());
297+
int luaStateCount = std::thread::hardware_concurrency();
298+
if (g_SettingsMan.GetNumberOfLuaStatesOverride() != -1) {
299+
luaStateCount = g_SettingsMan.GetNumberOfLuaStatesOverride();
300+
}
301+
302+
m_ScriptStates = std::vector<LuaStateWrapper>(luaStateCount);
298303
for (LuaStateWrapper &luaState : m_ScriptStates) {
299304
luaState.Initialize();
300305
}

Source/Managers/MovableMan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,11 @@ void MovableMan::Update()
16881688
// Travel MOs
16891689
Travel();
16901690

1691+
// If our debug settings switch is forcing all pathing requests to immediately complete, make sure they're done here
1692+
if (g_SettingsMan.GetForceImmediatePathingRequestCompletion() && g_SceneMan.GetScene()) {
1693+
g_SceneMan.GetScene()->BlockUntilAllPathingRequestsComplete();
1694+
}
1695+
16911696
// Prior to controller/AI update, execute lua callbacks
16921697
g_LuaMan.ExecuteLuaScriptCallbacks();
16931698

Source/Managers/SettingsMan.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace RTE {
5252
m_DisableFactionBuyMenuThemeCursors = false;
5353
m_PathFinderGridNodeSize = c_PPM;
5454
m_AIUpdateInterval = 2;
55+
56+
m_NumberOfLuaStatesOverride = -1;
57+
m_ForceImmediatePathingRequestCompletion = false;
5558

5659
m_SkipIntro = false;
5760
m_ShowToolTips = true;
@@ -170,6 +173,8 @@ namespace RTE {
170173
MatchProperty("DisableFactionBuyMenuThemeCursors", { reader >> m_DisableFactionBuyMenuThemeCursors; });
171174
MatchProperty("PathFinderGridNodeSize", { reader >> m_PathFinderGridNodeSize; });
172175
MatchProperty("AIUpdateInterval", { reader >> m_AIUpdateInterval; });
176+
MatchProperty("NumberOfLuaStatesOverride", { reader >> m_NumberOfLuaStatesOverride; });
177+
MatchProperty("ForceImmediatePathingRequestCompletion", { reader >> m_ForceImmediatePathingRequestCompletion; });
173178
MatchProperty("EnableParticleSettling", { reader >> g_MovableMan.m_SettlingEnabled; });
174179
MatchProperty("EnableMOSubtraction", { reader >> g_MovableMan.m_MOSubtractionEnabled; });
175180
MatchProperty("DeltaTime", { g_TimerMan.SetDeltaTimeSecs(std::stof(reader.ReadPropValue())); });
@@ -315,6 +320,8 @@ namespace RTE {
315320
writer.NewPropertyWithValue("DisableFactionBuyMenuThemeCursors", m_DisableFactionBuyMenuThemeCursors);
316321
writer.NewPropertyWithValue("PathFinderGridNodeSize", m_PathFinderGridNodeSize);
317322
writer.NewPropertyWithValue("AIUpdateInterval", m_AIUpdateInterval);
323+
writer.NewPropertyWithValue("NumberOfLuaStatesOverride", m_NumberOfLuaStatesOverride);
324+
writer.NewPropertyWithValue("ForceImmediatePathingRequestCompletion", m_ForceImmediatePathingRequestCompletion);
318325
writer.NewPropertyWithValue("EnableParticleSettling", g_MovableMan.m_SettlingEnabled);
319326
writer.NewPropertyWithValue("EnableMOSubtraction", g_MovableMan.m_MOSubtractionEnabled);
320327
writer.NewPropertyWithValue("DeltaTime", g_TimerMan.GetDeltaTimeSecs());

Source/Managers/SettingsMan.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ namespace RTE {
134134
/// </summary>
135135
/// <param name="newAIUpdateInterval">How often Actor's AI will now be updated, in simulation updates.</param>
136136
void SetAIUpdateInterval(int newAIUpdateInterval) { m_AIUpdateInterval = newAIUpdateInterval; }
137+
138+
/// <summary>
139+
/// Gets how many threaded Lua states we'll use. -1 represents no override, which defaults to the maximum number of concurrent hardware threads.
140+
/// </summary>
141+
/// <returns>How many threaded Lua states we'll use.</returns>
142+
int GetNumberOfLuaStatesOverride() const { return m_NumberOfLuaStatesOverride; }
143+
144+
/// <summary>
145+
/// Gets whether pathing requests will be forced to immediately complete for the next frame, or if they can take multiple frames to calculate.
146+
/// </summary>
147+
/// <returns>Whether pathing requests will be forced to immediately complete for the next frame</returns>
148+
bool GetForceImmediatePathingRequestCompletion() const { return m_ForceImmediatePathingRequestCompletion; }
137149
#pragma endregion
138150

139151
#pragma region Gameplay Settings
@@ -549,6 +561,8 @@ namespace RTE {
549561
bool m_DisableFactionBuyMenuThemeCursors; //!< Whether custom cursor support in faction BuyMenu themes is disabled.
550562
int m_PathFinderGridNodeSize; //!< The grid size used by the PathFinder, in pixels.
551563
int m_AIUpdateInterval; //!< How often actor's AI should be updated, i.e. every n simulation updates.
564+
int m_NumberOfLuaStatesOverride; //!< Overrides how many threaded Lua states we'll use. -1 for no override, which defaults to the maximum number of concurrent hardware threads.
565+
bool m_ForceImmediatePathingRequestCompletion; //!< Whether pathing requests will be forced to immediately complete for the next frame, or if they can take multiple frames to calculate.
552566

553567
bool m_SkipIntro; //!< Whether to play the intro of the game or skip directly to the main menu.
554568
bool m_ShowToolTips; //!< Whether ToolTips are enabled or not.

0 commit comments

Comments
 (0)