diff --git a/OpenRa.DataStructures/float2.cs b/OpenRa.DataStructures/float2.cs index dd80f7fc70..6b57223279 100644 --- a/OpenRa.DataStructures/float2.cs +++ b/OpenRa.DataStructures/float2.cs @@ -26,7 +26,7 @@ namespace OpenRa public static float2 operator -(float2 a) { return new float2(-a.X, -a.Y); } - static float Lerp(float a, float b, float t) { return (1 - t) * a + t * b; } + static float Lerp(float a, float b, float t) { return a + t * (b - a); } public static float2 Lerp(float2 a, float2 b, float t) { diff --git a/OpenRa.FileFormats/IniFile.cs b/OpenRa.FileFormats/IniFile.cs index cb3a158120..e4d931a1e3 100644 --- a/OpenRa.FileFormats/IniFile.cs +++ b/OpenRa.FileFormats/IniFile.cs @@ -17,8 +17,15 @@ namespace OpenRa.FileFormats while( !reader.EndOfStream ) { string line = reader.ReadLine(); - if( !ProcessEntry( line ) ) - ProcessSection( line ); + + if (line.Length == 0) continue; + + switch (line[0]) + { + case ';': break; + case '[': ProcessSection(line); break; + default: ProcessEntry(line); break; + } } } @@ -27,9 +34,6 @@ namespace OpenRa.FileFormats bool ProcessSection( string line ) { - if (string.IsNullOrEmpty(line) || line.StartsWith(";")) - return false; - Match m = sectionPattern.Match( line ); if( m == null || !m.Success ) return false; @@ -43,9 +47,6 @@ namespace OpenRa.FileFormats bool ProcessEntry( string line ) { - if (string.IsNullOrEmpty(line) || line.StartsWith(";")) - return false; - Match m = entryPattern.Match( line ); if( m == null || !m.Success ) return false; diff --git a/OpenRa.Game/Sprite.cs b/OpenRa.Game/Sprite.cs index 5aa690b4aa..857d7d4d09 100644 --- a/OpenRa.Game/Sprite.cs +++ b/OpenRa.Game/Sprite.cs @@ -11,6 +11,7 @@ namespace OpenRa.Game public readonly Sheet sheet; public readonly TextureChannel channel; public readonly RectangleF uv; + public readonly float2 size; internal Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel) { @@ -23,6 +24,8 @@ namespace OpenRa.Game (float)(bounds.Top + 0.5f) / sheet.Size.Height, (float)(bounds.Width) / sheet.Size.Width, (float)(bounds.Height) / sheet.Size.Height); + + this.size = new float2(bounds.Size); } public float2 MapTextureCoords(float2 p) @@ -31,6 +34,8 @@ namespace OpenRa.Game p.X > 0 ? uv.Right : uv.Left, p.Y > 0 ? uv.Bottom : uv.Top); } + + public float2 Size { get { return size; } } } public enum TextureChannel diff --git a/OpenRa.Game/Util.cs b/OpenRa.Game/Util.cs index 72b60520cb..c94d240df1 100644 --- a/OpenRa.Game/Util.cs +++ b/OpenRa.Game/Util.cs @@ -31,7 +31,7 @@ namespace OpenRa.Game public static Vertex MakeVertex(float2 o, float2 uv, Sprite r, int palette) { return new Vertex( - float2.Lerp( o, o + new float2(r.bounds.Size), uv ), + float2.Lerp( o, o + r.Size, uv ), r.MapTextureCoords(uv), EncodeVertexAttributes(r.channel, palette)); } diff --git a/OpenRa.TechTree/TechTree.cs b/OpenRa.TechTree/TechTree.cs index ee9a757472..fae4a26ae3 100644 --- a/OpenRa.TechTree/TechTree.cs +++ b/OpenRa.TechTree/TechTree.cs @@ -9,6 +9,9 @@ namespace OpenRa.TechTree { public class TechTree { + static IniFile rules; + static IniFile Rules { get { return rules ?? (rules = new IniFile(FileSystem.Open("rules.ini"))); } } + Dictionary objects = new Dictionary(); public ICollection built = new List(); @@ -54,13 +57,12 @@ namespace OpenRa.TechTree void LoadRules() { - IniFile rulesFile = new IniFile(FileSystem.Open("rules.ini")); IEnumerable> definitions = Concat( Lines("buildings.txt", true), Lines("units.txt", false)); foreach (Tuple p in definitions) - objects.Add(p.a, new Item(p.a, p.b, rulesFile.GetSection(p.a), p.c)); + objects.Add(p.a, new Item(p.a, p.b, Rules.GetSection(p.a), p.c)); } public bool Build(string key, bool force)