Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw a sensible exception when no renderers are available. #4326

Merged
merged 2 commits into from
Dec 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 29 additions & 28 deletions OpenRA.Game/Game.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2013 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,
Expand Down Expand Up @@ -81,11 +81,10 @@ static void JoinLocal()
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } }


// Hacky workaround for orderManager visibility
public static Widget OpenWindow(World world, string widget)
{
return Ui.OpenWindow(widget, new WidgetArgs() {{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }});
return Ui.OpenWindow(widget, new WidgetArgs() { { "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer } });
}

// Who came up with the great idea of making these things
Expand Down Expand Up @@ -220,7 +219,7 @@ internal static void SyncLobbyInfo()
LobbyInfoChanged();
}

public static event Action BeforeGameStart = () => {};
public static event Action BeforeGameStart = () => { };
internal static void StartGame(string mapUID, bool isShellmap)
{
BeforeGameStart();
Expand Down Expand Up @@ -249,9 +248,9 @@ public static bool IsHost
{
get
{
var client= orderManager.LobbyInfo.ClientWithIndex(
orderManager.Connection.LocalClientId);
return ((client!=null) && client.IsAdmin);
var id = orderManager.Connection.LocalClientId;
var client = orderManager.LobbyInfo.ClientWithIndex(id);
return client != null && client.IsAdmin;
}
}

Expand Down Expand Up @@ -284,9 +283,12 @@ internal static void Initialize(Arguments args)
}

FileSystem.Mount("."); // Needed to access shaders
var renderers = new [] { Settings.Graphics.Renderer, "Sdl2", "Gl", "Cg" };
var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", "Gl", "Cg", null };
foreach (var r in renderers)
{
if (r == null)
throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details.");

Settings.Graphics.Renderer = r;
try
{
Expand All @@ -299,6 +301,7 @@ internal static void Initialize(Arguments args)
Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
}
}

Renderer = new Renderer();

try
Expand All @@ -314,26 +317,22 @@ internal static void Initialize(Arguments args)
}

Console.WriteLine("Available mods:");
foreach(var mod in Mod.AllMods)
foreach (var mod in Mod.AllMods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);

InitializeWithMod(Settings.Game.Mod);

if (Settings.Server.DiscoverNatDevices)
{
RunAfterDelay(Settings.Server.NatDiscoveryTimeout, () =>
UPnP.TryStoppingNatDiscovery()
);
}
RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.TryStoppingNatDiscovery);
}

public static void InitializeWithMod(string mod)
{
// Clear static state if we have switched mods
LobbyInfoChanged = () => {};
AddChatLine = (a,b,c) => {};
ConnectionStateChanged = om => {};
BeforeGameStart = () => {};
LobbyInfoChanged = () => { };
AddChatLine = (a, b, c) => { };
ConnectionStateChanged = om => { };
BeforeGameStart = () => { };
Ui.ResetAll();

worldRenderer = null;
Expand Down Expand Up @@ -375,21 +374,23 @@ public static void InitializeWithMod(string mod)
{
System.Threading.Thread.Sleep(100);

if ((server.State == Server.ServerState.GameStarted)
&& (server.Conns.Count<=1))
if (server.State == Server.ServerState.GameStarted && server.Conns.Count <= 1)
{
Console.WriteLine("No one is playing, shutting down...");
server.Shutdown();
break;
}
}

if (Settings.Server.DedicatedLoop)
{
Console.WriteLine("Starting a new server instance...");
continue;
}

break;
}

Environment.Exit(0);
}
else
Expand All @@ -406,7 +407,7 @@ public static void LoadShellMap()

static string ChooseShellmap()
{
var shellmaps = modData.AvailableMaps
var shellmaps = modData.AvailableMaps
.Where(m => m.Value.UseAsShellmap);

if (!shellmaps.Any())
Expand All @@ -416,7 +417,7 @@ static string ChooseShellmap()
}

static bool quit;
public static event Action OnQuit = () => {};
public static event Action OnQuit = () => { };

internal static void Run()
{
Expand Down Expand Up @@ -446,11 +447,11 @@ internal static void Run()

public static void Exit() { quit = true; }

public static Action<Color,string,string> AddChatLine = (c,n,s) => {};
public static Action<Color, string, string> AddChatLine = (c, n, s) => { };

public static void Debug(string s, params object[] args)
{
AddChatLine(Color.White, "Debug", String.Format(s,args));
AddChatLine(Color.White, "Debug", string.Format(s, args));
}

public static void Disconnect()
Expand All @@ -469,7 +470,7 @@ public static void CloseServer()
server.Shutdown();
}

public static T CreateObject<T>( string name )
public static T CreateObject<T>(string name)
{
return modData.ObjectCreator.CreateObject<T>(name);
}
Expand All @@ -486,7 +487,7 @@ public static int CreateLocalServer(string map)
Name = "Skirmish Game",
Map = map,
AdvertiseOnline = false,
AllowPortForward = false
AllowPortForward = false
};

server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, modData);
Expand All @@ -504,11 +505,11 @@ public static bool DownloadMap(string mapHash)
try
{
var mod = Game.modData.Manifest.Mod;
var dirPath = new [] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine);
var dirPath = new[] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine);
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);

var mapPath = Path.Combine(dirPath, mapHash+".oramap");
var mapPath = Path.Combine(dirPath, mapHash + ".oramap");
Console.Write("Trying to download map to {0} ... ".F(mapPath));

WebClient webClient = new WebClient();
Expand Down