Skip to content

Commit ad2df9e

Browse files
committed
Reworking the DatabaseReloadWithMM to be "safe"
1 parent 38e9035 commit ad2df9e

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

Source/ModuleManager/ModuleManager.cs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -280,63 +280,67 @@ public static bool IsABadIdea()
280280
}
281281
*/
282282

283-
internal IEnumerator DataBaseReloadWithMM(bool dump = false)
284-
{
285-
QualitySettings.vSyncCount = 0;
286-
Application.targetFrameRate = -1;
287-
288-
patchRunner = new MMPatchRunner(ModLogger.Instance);
289-
290-
bool startedReload = false;
283+
internal IEnumerator DataBaseReloadWithMM(bool dump = false)
284+
{
285+
PerformanceMetrics.Instance.Start();
286+
try
287+
{
288+
patchRunner = new MMPatchRunner(ModLogger.Instance);
291289

292-
GUI.ReloadingDatabaseDialog reloadingDialog = GUI.ReloadingDatabaseDialog.Show(this, startedReload);
290+
bool startedReload = false;
293291

294-
yield return null;
292+
GUI.ReloadingDatabaseDialog reloadingDialog = GUI.ReloadingDatabaseDialog.Show(this, startedReload);
295293

296-
GameDatabase.Instance.Recompile = true;
297-
GameDatabase.Instance.StartLoad();
294+
yield return null;
298295

299-
startedReload = true;
296+
GameDatabase.Instance.Recompile = true;
297+
GameDatabase.Instance.StartLoad();
300298

301-
yield return null;
302-
StartCoroutine(patchRunner.Run());
299+
startedReload = true;
303300

304-
// wait for it to finish
305-
while (!GameDatabase.Instance.IsReady())
306-
yield return null;
301+
yield return null;
302+
StartCoroutine(patchRunner.Run());
307303

308-
PostPatchLoader.Instance.StartLoad();
304+
// wait for it to finish
305+
while (!GameDatabase.Instance.IsReady())
306+
yield return null;
309307

310-
while (!PostPatchLoader.Instance.IsReady())
311-
yield return null;
308+
PostPatchLoader.Instance.StartLoad();
312309

313-
if (dump)
314-
OutputAllConfigs();
310+
while (!PostPatchLoader.Instance.IsReady())
311+
yield return null;
315312

316-
PartLoader.Instance.StartLoad();
313+
if (dump)
314+
OutputAllConfigs();
317315

318-
while (!PartLoader.Instance.IsReady())
319-
yield return null;
316+
PartLoader.Instance.StartLoad();
320317

321-
// Needs more work.
322-
//ConfigNode game = HighLogic.CurrentGame.config.GetNode("GAME");
318+
while (!PartLoader.Instance.IsReady())
319+
yield return null;
323320

324-
//if (game != null && ResearchAndDevelopment.Instance != null)
325-
//{
326-
// ScreenMessages.PostScreenMessage("GAME found");
327-
// ConfigNode scenario = game.GetNodes("SCENARIO").FirstOrDefault((ConfigNode n) => n.name == "ResearchAndDevelopment");
328-
// if (scenario != null)
329-
// {
330-
// ScreenMessages.PostScreenMessage("SCENARIO found");
331-
// ResearchAndDevelopment.Instance.OnLoad(scenario);
332-
// }
333-
//}
321+
// Needs more work.
322+
//ConfigNode game = HighLogic.CurrentGame.config.GetNode("GAME");
334323

335-
QualitySettings.vSyncCount = GameSettings.SYNC_VBL;
336-
Application.targetFrameRate = GameSettings.FRAMERATE_LIMIT;
324+
//if (game != null && ResearchAndDevelopment.Instance != null)
325+
//{
326+
// ScreenMessages.PostScreenMessage("GAME found");
327+
// ConfigNode scenario = game.GetNodes("SCENARIO").FirstOrDefault((ConfigNode n) => n.name == "ResearchAndDevelopment");
328+
// if (scenario != null)
329+
// {
330+
// ScreenMessages.PostScreenMessage("SCENARIO found");
331+
// ResearchAndDevelopment.Instance.OnLoad(scenario);
332+
// }
333+
//}
337334

338-
reloadingDialog.Dismiss();
339-
}
335+
reloadingDialog.Dismiss();
336+
}
337+
finally
338+
{
339+
PerformanceMetrics.Instance.Stop();
340+
Log("Total reloading Time = " + PerformanceMetrics.Instance.ElapsedTimeInSecs.ToString("F3") + "s");
341+
PerformanceMetrics.Instance.Destroy();
342+
}
343+
}
340344

341345
public static void OutputAllConfigs()
342346
{

0 commit comments

Comments
 (0)