From df1c49dacb7a524556ea1b4ead2f38ac8689a178 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 2 Jan 2010 02:19:53 -0800 Subject: [PATCH] Load custom settings from settings.ini (reading from commandline currently doesn't work) --- OpenRa.FileFormats/FileSystem.cs | 14 +++---- OpenRa.Game/Game.cs | 21 ++++------- OpenRa.Game/GameRules/FieldLoader.cs | 4 +- OpenRa.Game/MainWindow.cs | 55 ++++++++++++++++++---------- OpenRa.Game/OpenRa.Game.csproj | 1 + SequenceEditor/Program.cs | 10 ++--- 6 files changed, 57 insertions(+), 48 deletions(-) diff --git a/OpenRa.FileFormats/FileSystem.cs b/OpenRa.FileFormats/FileSystem.cs index 686f699c4a..a260c802a1 100644 --- a/OpenRa.FileFormats/FileSystem.cs +++ b/OpenRa.FileFormats/FileSystem.cs @@ -9,9 +9,8 @@ namespace OpenRa.FileFormats static List mountedFolders = new List(); static List temporaryMounts = new List(); - public static void MountDefault( bool useAftermath ) + public static void MountDefaultPackages() { - FileSystem.Mount( new Folder( "./" ) ); if( File.Exists( "main.mix" ) ) FileSystem.Mount( new Package( "main.mix" ) ); FileSystem.Mount( new Package( "redalert.mix" ) ); @@ -23,11 +22,12 @@ namespace OpenRa.FileFormats FileSystem.Mount( new Package( "speech.mix" ) ); FileSystem.Mount( new Package( "allies.mix" ) ); FileSystem.Mount( new Package( "russian.mix" ) ); - if( useAftermath ) - { - FileSystem.Mount( new Package( "expand2.mix" ) ); - FileSystem.Mount( new Package( "hires1.mix" ) ); - } + } + + public static void MountAftermathPackages() + { + FileSystem.Mount( new Package( "expand2.mix" ) ); + FileSystem.Mount( new Package( "hires1.mix" ) ); } public static void Mount(IFolder folder) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index e3a6cb490c..964f9012e7 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -22,7 +22,8 @@ namespace OpenRa.Game public static WorldRenderer worldRenderer; public static Controller controller; public static Chrome chrome; - + public static UserSettings Settings; + public static OrderManager orderManager; static int localPlayerIndex; @@ -41,11 +42,6 @@ namespace OpenRa.Game public static BuildingInfluenceMap BuildingInfluence; public static UnitInfluenceMap UnitInfluence; - public static string Replay; - - public static string NetworkHost; - public static int NetworkPort; - public static bool skipMakeAnims = true; static Renderer renderer; @@ -121,13 +117,13 @@ namespace OpenRa.Game ChangeMap(mapName); - if (Replay != "") - orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Replay) }); + if (Settings.Replay != "") + orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Settings.Replay) }); else { - var orderSources = (string.IsNullOrEmpty(NetworkHost)) + var orderSources = (string.IsNullOrEmpty(Settings.NetworkHost)) ? new IOrderSource[] { new LocalOrderSource() } - : new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(NetworkHost, NetworkPort)) }; + : new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(Settings.NetworkHost, Settings.NetworkPort)) }; orderManager = new OrderManager(orderSources, "replay.rep"); } } @@ -149,7 +145,6 @@ namespace OpenRa.Game } static int lastTime = Environment.TickCount; - public static int timestep = 40; public static void ResetTimer() { @@ -166,11 +161,11 @@ namespace OpenRa.Game { int t = Environment.TickCount; int dt = t - lastTime; - if (dt >= timestep) + if (dt >= Settings.Timestep) { using (new PerfSample("tick_time")) { - lastTime += timestep; + lastTime += Settings.Timestep; UpdatePalette(world.Actors.SelectMany( a => a.traits.WithInterface())); orderManager.TickImmediate(); diff --git a/OpenRa.Game/GameRules/FieldLoader.cs b/OpenRa.Game/GameRules/FieldLoader.cs index a71ef3fc36..bff21b7c5a 100755 --- a/OpenRa.Game/GameRules/FieldLoader.cs +++ b/OpenRa.Game/GameRules/FieldLoader.cs @@ -10,8 +10,8 @@ namespace OpenRa.Game.GameRules { foreach( var x in ini ) { - var field = self.GetType().GetField( x.Key ); - field.SetValue( self, GetValue( field.FieldType, x.Value ) ); + var field = self.GetType().GetField( x.Key.Trim() ); + field.SetValue( self, GetValue( field.FieldType, x.Value.Trim() ) ); } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index e32fe8d1d5..e35f87948f 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -6,6 +6,8 @@ using System.Windows.Forms; using OpenRa.FileFormats; using OpenRa.Game.Graphics; using OpenRa.Game.Orders; +using OpenRa.Game.GameRules; + namespace OpenRa.Game { @@ -16,34 +18,44 @@ namespace OpenRa.Game static Size GetResolution(Settings settings) { var desktopResolution = Screen.PrimaryScreen.Bounds.Size; - + if (Game.Settings.Width > 0 && Game.Settings.Height > 0) + { + desktopResolution.Width = Game.Settings.Width; + desktopResolution.Height = Game.Settings.Height; + } return new Size( - settings.GetValue("width", desktopResolution.Width), - settings.GetValue("height", desktopResolution.Height)); + desktopResolution.Width, + desktopResolution.Height); } [DllImport("user32")] static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible); + + public MainWindow(Settings settings) { + FileSystem.Mount(new Folder("./")); + FormBorderStyle = FormBorderStyle.None; BackColor = Color.Black; StartPosition = FormStartPosition.Manual; Location = Point.Empty; Visible = true; - - UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false); - UiOverlay.ShowBuildDebug = settings.GetValue("bdebug", false); - WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false); - Game.timestep = settings.GetValue("rate", 40); - Game.Replay = settings.GetValue("replay", ""); - Game.NetworkHost = settings.GetValue("host", ""); - Game.NetworkPort = int.Parse(settings.GetValue("port", "0")); - - var useAftermath = bool.Parse(settings.GetValue("aftermath", "false")); - - Renderer.SheetSize = int.Parse(settings.GetValue("sheetsize", "512")); + + // Load user settings + Game.Settings = new UserSettings(); + try + { + IniFile SettingsRules = new IniFile(FileSystem.Open("settings.ini")); + FieldLoader.Load(Game.Settings, SettingsRules.GetSection("Settings")); + } + catch (FileNotFoundException) {} + + UiOverlay.ShowUnitDebug = Game.Settings.UnitDebug; + UiOverlay.ShowBuildDebug = Game.Settings.BuildingDebug; + WorldRenderer.ShowUnitPaths = Game.Settings.PathDebug; + Renderer.SheetSize = Game.Settings.SheetSize; while (!File.Exists("redalert.mix")) { @@ -53,15 +65,20 @@ namespace OpenRa.Game Directory.SetCurrentDirectory(".."); } - FileSystem.MountDefault(useAftermath); + FileSystem.MountDefaultPackages(); + + if (Game.Settings.UseAftermath) + { + FileSystem.MountAftermathPackages(); + } - bool windowed = !settings.GetValue("fullscreen", false); + bool windowed = !Game.Settings.Fullscreen; renderer = new Renderer(this, GetResolution(settings), windowed); var controller = new Controller(() => (Modifiers)(int)ModifierKeys); /* a bit of insane input routing */ - Game.Initialize(settings.GetValue("map", "scm12ea.ini"), renderer, new int2(ClientSize), - settings.GetValue("player", 1), useAftermath, controller); + Game.Initialize(Game.Settings.Map, renderer, new int2(ClientSize), + Game.Settings.Player, Game.Settings.UseAftermath, controller); ShowCursor(false); Game.ResetTimer(); diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index c34482273f..03730391eb 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -92,6 +92,7 @@ + diff --git a/SequenceEditor/Program.cs b/SequenceEditor/Program.cs index a99f6479ee..cdef4b4285 100644 --- a/SequenceEditor/Program.cs +++ b/SequenceEditor/Program.cs @@ -70,16 +70,12 @@ namespace SequenceEditor { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - + FileSystem.MountDefaultPackages(); try { - FileSystem.MountDefault( true ); - } - catch( FileNotFoundException fnf ) - { - if( fnf.FileName != "expand2.mix" ) - throw new InvalidOperationException( "Unable to load MIX files" ); + FileSystem.MountAftermathPackages(); } + catch( FileNotFoundException ){} FileSystem.MountTemporary(new Package("temperat.mix"));