Merge pull request #7405 from Rydra/upstream/int2immutable
Made int2 class immutable
This commit is contained in:
@@ -45,9 +45,18 @@ namespace OpenRA.Graphics
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if (d.ContainsKey("X"))
|
if (d.ContainsKey("X"))
|
||||||
Exts.TryParseIntegerInvariant(d["X"].Value, out Hotspot.X);
|
{
|
||||||
|
int x;
|
||||||
|
Exts.TryParseIntegerInvariant(d["X"].Value, out x);
|
||||||
|
Hotspot = Hotspot.WithX(x);
|
||||||
|
}
|
||||||
|
|
||||||
if (d.ContainsKey("Y"))
|
if (d.ContainsKey("Y"))
|
||||||
Exts.TryParseIntegerInvariant(d["Y"].Value, out Hotspot.Y);
|
{
|
||||||
|
int y;
|
||||||
|
Exts.TryParseIntegerInvariant(d["Y"].Value, out y);
|
||||||
|
Hotspot = Hotspot.WithY(y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
dataX = -hotspot.X;
|
dataX = -hotspot.X;
|
||||||
dataWidth += dataX;
|
dataWidth += dataX;
|
||||||
hotspot.X = 0;
|
hotspot = hotspot.WithX(0);
|
||||||
}
|
}
|
||||||
else if (hotspot.X >= frameWidth)
|
else if (hotspot.X >= frameWidth)
|
||||||
dataWidth = hotspot.X + 1;
|
dataWidth = hotspot.X + 1;
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
dataY = -hotspot.Y;
|
dataY = -hotspot.Y;
|
||||||
dataHeight += dataY;
|
dataHeight += dataY;
|
||||||
hotspot.Y = 0;
|
hotspot = hotspot.WithY(0);
|
||||||
}
|
}
|
||||||
else if (hotspot.Y >= frameHeight)
|
else if (hotspot.Y >= frameHeight)
|
||||||
dataHeight = hotspot.Y + 1;
|
dataHeight = hotspot.Y + 1;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
Sprite = s,
|
Sprite = s,
|
||||||
Advance = (int)face.Glyph.Metrics.HorizontalAdvance / 64f,
|
Advance = (int)face.Glyph.Metrics.HorizontalAdvance / 64f,
|
||||||
Offset = { X = face.Glyph.BitmapLeft, Y = -face.Glyph.BitmapTop }
|
Offset = new int2(face.Glyph.BitmapLeft, -face.Glyph.BitmapTop)
|
||||||
};
|
};
|
||||||
|
|
||||||
// A new bitmap is generated each time this property is accessed, so we do need to dispose it.
|
// A new bitmap is generated each time this property is accessed, so we do need to dispose it.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA
|
|||||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||||
public struct int2
|
public struct int2
|
||||||
{
|
{
|
||||||
public int X, Y;
|
public readonly int X, Y;
|
||||||
public int2(int x, int y) { this.X = x; this.Y = y; }
|
public int2(int x, int y) { this.X = x; this.Y = y; }
|
||||||
public int2(Point p) { X = p.X; Y = p.Y; }
|
public int2(Point p) { X = p.X; Y = p.Y; }
|
||||||
public int2(Size p) { X = p.Width; Y = p.Height; }
|
public int2(Size p) { X = p.Width; Y = p.Height; }
|
||||||
@@ -39,6 +39,16 @@ namespace OpenRA
|
|||||||
public int Length { get { return Exts.ISqrt(LengthSquared); } }
|
public int Length { get { return Exts.ISqrt(LengthSquared); } }
|
||||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||||
|
|
||||||
|
public int2 WithX(int newX)
|
||||||
|
{
|
||||||
|
return new int2(newX, Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int2 WithY(int newY)
|
||||||
|
{
|
||||||
|
return new int2(X, newY);
|
||||||
|
}
|
||||||
|
|
||||||
public static int2 Max(int2 a, int2 b) { return new int2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
public static int2 Max(int2 a, int2 b) { return new int2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
||||||
public static int2 Min(int2 a, int2 b) { return new int2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
|
public static int2 Min(int2 a, int2 b) { return new int2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
|
||||||
|
|
||||||
|
|||||||
@@ -96,10 +96,7 @@ namespace OpenRA.Traits
|
|||||||
foreach (var pip in thisRow)
|
foreach (var pip in thisRow)
|
||||||
{
|
{
|
||||||
if (pipxyOffset.X + pipSize.X >= width)
|
if (pipxyOffset.X + pipSize.X >= width)
|
||||||
{
|
pipxyOffset = new int2(0, pipxyOffset.Y - pipSize.Y);
|
||||||
pipxyOffset.X = 0;
|
|
||||||
pipxyOffset.Y -= pipSize.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
pipImages.PlayRepeating(PipStrings[(int)pip]);
|
pipImages.PlayRepeating(PipStrings[(int)pip]);
|
||||||
pipxyOffset += new int2(pipSize.X, 0);
|
pipxyOffset += new int2(pipSize.X, 0);
|
||||||
@@ -108,8 +105,7 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Increment row
|
// Increment row
|
||||||
pipxyOffset.X = 0;
|
pipxyOffset = new int2(0, pipxyOffset.Y - (pipSize.Y + 1));
|
||||||
pipxyOffset.Y -= pipSize.Y + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +127,7 @@ namespace OpenRA.Traits
|
|||||||
yield return new UISpriteRenderable(tagImages.Image, pos, 0, pal, 1f);
|
yield return new UISpriteRenderable(tagImages.Image, pos, 0, pal, 1f);
|
||||||
|
|
||||||
// Increment row
|
// Increment row
|
||||||
tagxyOffset.Y += 8;
|
tagxyOffset = tagxyOffset.WithY(tagxyOffset.Y + 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
|
var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
|
||||||
chatpos.Y -= Math.Max(15, font.Measure(text).Y) + 5;
|
chatpos = chatpos.WithY(chatpos.Y - (Math.Max(15, font.Measure(text).Y) + 5));
|
||||||
|
|
||||||
if (chatpos.Y < pos.Y)
|
if (chatpos.Y < pos.Y)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -30,14 +30,13 @@ namespace OpenRA.Widgets
|
|||||||
if (pos.X + widget.ItemSpacing + w.Bounds.Width > widget.Bounds.Width - widget.ScrollbarWidth)
|
if (pos.X + widget.ItemSpacing + w.Bounds.Width > widget.Bounds.Width - widget.ScrollbarWidth)
|
||||||
{
|
{
|
||||||
/* start a new row */
|
/* start a new row */
|
||||||
pos.X = widget.ItemSpacing;
|
pos = new int2(widget.ItemSpacing, widget.ContentHeight);
|
||||||
pos.Y = widget.ContentHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Bounds.X += pos.X;
|
w.Bounds.X += pos.X;
|
||||||
w.Bounds.Y += pos.Y;
|
w.Bounds.Y += pos.Y;
|
||||||
|
|
||||||
pos.X += w.Bounds.Width + widget.ItemSpacing;
|
pos = pos.WithX(pos.X + w.Bounds.Width + widget.ItemSpacing);
|
||||||
|
|
||||||
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Widgets
|
|||||||
if (tooltip != null)
|
if (tooltip != null)
|
||||||
{
|
{
|
||||||
if (pos.X + tooltip.Bounds.Right > Game.Renderer.Resolution.Width)
|
if (pos.X + tooltip.Bounds.Right > Game.Renderer.Resolution.Width)
|
||||||
pos.X = Game.Renderer.Resolution.Width - tooltip.Bounds.Right;
|
pos = pos.WithX(Game.Renderer.Resolution.Width - tooltip.Bounds.Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
|
|||||||
@@ -147,8 +147,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
map = Map.FromTileset(rules.TileSets[tileset]);
|
map = Map.FromTileset(rules.TileSets[tileset]);
|
||||||
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile));
|
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile));
|
||||||
map.Author = "Westwood Studios";
|
map.Author = "Westwood Studios";
|
||||||
map.MapSize.X = mapSize;
|
map.MapSize = new int2(mapSize, mapSize);
|
||||||
map.MapSize.Y = mapSize;
|
|
||||||
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
|
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
|
||||||
|
|
||||||
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
|
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
|
||||||
|
|||||||
@@ -310,8 +310,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands
|
|||||||
map = Map.FromTileset(tileSet);
|
map = Map.FromTileset(tileSet);
|
||||||
map.Title = Path.GetFileNameWithoutExtension(mapFile);
|
map.Title = Path.GetFileNameWithoutExtension(mapFile);
|
||||||
map.Author = "Westwood Studios";
|
map.Author = "Westwood Studios";
|
||||||
map.MapSize.X = mapSize.Width + 2 * MapCordonWidth;
|
map.MapSize = new int2(mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth);
|
||||||
map.MapSize.Y = mapSize.Height + 2 * MapCordonWidth;
|
|
||||||
map.Bounds = new Rectangle(MapCordonWidth, MapCordonWidth, mapSize.Width, mapSize.Height);
|
map.Bounds = new Rectangle(MapCordonWidth, MapCordonWidth, mapSize.Width, mapSize.Height);
|
||||||
|
|
||||||
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
|
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
|
||||||
|
|||||||
@@ -80,10 +80,6 @@ namespace PathfinderTests
|
|||||||
|
|
||||||
IPathSearch search;
|
IPathSearch search;
|
||||||
Stopwatch stopwatch;
|
Stopwatch stopwatch;
|
||||||
List<CPos> path1 = null;
|
|
||||||
List<CPos> path2 = null;
|
|
||||||
List<CPos> path3 = null;
|
|
||||||
List<CPos> path4 = null;
|
|
||||||
List<CPos> path5 = null;
|
List<CPos> path5 = null;
|
||||||
List<CPos> path6 = null;
|
List<CPos> path6 = null;
|
||||||
List<CPos> path7 = null;
|
List<CPos> path7 = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user