Merge pull request #5600 from RoosterDragon/auto-restart

Offer user quick restart if settings change
This commit is contained in:
Matthias Mailänder
2014-06-20 08:56:08 +02:00
4 changed files with 71 additions and 18 deletions

View File

@@ -464,7 +464,7 @@ namespace OpenRA
return shellmaps.Random(CosmeticRandom);
}
static bool quit;
static RunStatus state = RunStatus.Running;
public static event Action OnQuit = () => { };
static double idealFrameTime;
@@ -473,7 +473,7 @@ namespace OpenRA
idealFrameTime = 1.0 / fps;
}
internal static void Run()
internal static RunStatus Run()
{
if (Settings.Graphics.MaxFramerate < 1)
{
@@ -483,7 +483,7 @@ namespace OpenRA
SetIdealFrameTime(Settings.Graphics.MaxFramerate);
while (!quit)
while (state == RunStatus.Running)
{
if (Settings.Graphics.CapFramerate)
{
@@ -506,9 +506,19 @@ namespace OpenRA
Renderer.Device.Dispose();
OnQuit();
return state;
}
public static void Exit() { quit = true; }
public static void Exit()
{
state = RunStatus.Success;
}
public static void Restart()
{
state = RunStatus.Restart;
}
public static Action<Color, string, string> AddChatLine = (c, n, s) => { };

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -11,30 +11,37 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
namespace OpenRA
{
enum RunStatus
{
Error = -1,
Success = 0,
Restart = 1,
Running = int.MaxValue
}
static class Program
{
[STAThread]
static void Main(string[] args)
static int Main(string[] args)
{
if (Debugger.IsAttached || args.Contains("--just-die"))
{
Run(args);
return;
}
return (int)Run(args);
AppDomain.CurrentDomain.UnhandledException += (_, e) => FatalError((Exception)e.ExceptionObject);
try
{
Run(args);
return (int)Run(args);
}
catch (Exception e)
{
FatalError(e);
return (int)RunStatus.Error;
}
}
@@ -102,11 +109,15 @@ namespace OpenRA
return sb;
}
static void Run(string[] args)
static RunStatus Run(string[] args)
{
Game.Initialize(new Arguments(args));
GC.Collect();
Game.Run();
var status = Game.Run();
if (status == RunStatus.Restart)
using (var p = Process.GetCurrentProcess())
Process.Start(Assembly.GetEntryAssembly().Location, p.StartInfo.Arguments);
return status;
}
}
}