New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Editor
for (var u = 0; u < template.Size.X; u++)
for (var v = 0; v < template.Size.Y; v++)
{
if (surface.Map.IsInMap(new int2(u, v) + pos))
if (surface.Map.IsInMap(new CVec(u, v) + pos))
{
var z = u + v * template.Size.X;
if (tile.TileBitmapBytes[z] != null)
@@ -69,17 +69,17 @@ namespace OpenRA.Editor
Brush.Bitmap.Height * surface.Zoom);
}
void FloodFillWithBrush(Surface s, int2 pos)
void FloodFillWithBrush(Surface s, CPos pos)
{
var queue = new Queue<int2>();
var queue = new Queue<CPos>();
var replace = s.Map.MapTiles.Value[pos.X, pos.Y];
var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];
Action<int, int> MaybeEnqueue = (x, y) =>
Action<int, int> maybeEnqueue = (x, y) =>
{
if (s.Map.IsInMap(x, y) && !touched[x, y])
{
queue.Enqueue(new int2(x, y));
queue.Enqueue(new CPos(x, y));
touched[x, y] = true;
}
};
@@ -91,16 +91,16 @@ namespace OpenRA.Editor
if (!s.Map.MapTiles.Value[p.X, p.Y].Equals(replace))
continue;
var a = FindEdge(s, p, new int2(-1, 0), replace);
var b = FindEdge(s, p, new int2(1, 0), replace);
var a = FindEdge(s, p, new CVec(-1, 0), replace);
var b = FindEdge(s, p, new CVec(1, 0), replace);
for (var x = a.X; x <= b.X; x++)
{
s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { type = Brush.N, index = (byte)0 };
if (s.Map.MapTiles.Value[x, p.Y - 1].Equals(replace))
MaybeEnqueue(x, p.Y - 1);
maybeEnqueue(x, p.Y - 1);
if (s.Map.MapTiles.Value[x, p.Y + 1].Equals(replace))
MaybeEnqueue(x, p.Y + 1);
maybeEnqueue(x, p.Y + 1);
}
}
@@ -109,7 +109,7 @@ namespace OpenRA.Editor
s.Chunks.Clear();
}
int2 FindEdge(Surface s, int2 p, int2 d, TileReference<ushort, byte> replace)
CPos FindEdge(Surface s, CPos p, CVec d, TileReference<ushort, byte> replace)
{
for (; ; )
{

View File

@@ -175,7 +175,7 @@ namespace OpenRA.Editor
foreach( var kv in wps )
{
var a = new ActorReference("mpspawn");
a.Add(new LocationInit(kv.Second));
a.Add(new LocationInit((CPos)kv.Second));
a.Add(new OwnerInit("Neutral"));
Map.Actors.Value.Add("spawn" + kv.First, a);
}
@@ -276,7 +276,7 @@ namespace OpenRA.Editor
Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(overlayActorMapping[raOverlayNames[o]])
{
new LocationInit( new int2(i, j) ),
new LocationInit( new CPos(i, j) ),
new OwnerInit( "Neutral" )
});
}
@@ -294,7 +294,7 @@ namespace OpenRA.Editor
Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(kv.Value.ToLowerInvariant())
{
new LocationInit(new int2(loc % MapSize, loc / MapSize)),
new LocationInit(new CPos(loc % MapSize, loc / MapSize)),
new OwnerInit("Neutral")
});
}
@@ -323,7 +323,7 @@ namespace OpenRA.Editor
foreach (KeyValuePair<string, string> kv in overlay)
{
var loc = int.Parse(kv.Key);
var cell = new int2(loc % MapSize, loc / MapSize);
var cell = new CPos(loc % MapSize, loc / MapSize);
var res = Pair.New((byte)0, (byte)0);
if (overlayResourceMapping.ContainsKey(kv.Value.ToLower()))
@@ -353,7 +353,7 @@ namespace OpenRA.Editor
Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
{
new LocationInit(new int2(loc % MapSize, loc / MapSize)),
new LocationInit(new CPos(loc % MapSize, loc / MapSize)),
new OwnerInit("Neutral")
});
}
@@ -380,7 +380,7 @@ namespace OpenRA.Editor
var actor = new ActorReference(parts[1].ToLowerInvariant())
{
new LocationInit(new int2(loc % MapSize, loc / MapSize)),
new LocationInit(new CPos(loc % MapSize, loc / MapSize)),
new OwnerInit(parts[0]),
new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo)/256),
new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])),
@@ -432,7 +432,7 @@ namespace OpenRA.Editor
(byte)(color.Second.GetBrightness() * 255))
};
var Neutral = new [] {"Neutral"};
var neutral = new [] {"Neutral"};
foreach (var s in file.GetSection(section, true))
{
Console.WriteLine(s.Key);
@@ -442,8 +442,8 @@ namespace OpenRA.Editor
pr.InitialCash = int.Parse(s.Value);
break;
case "Allies":
pr.Allies = s.Value.Split(',').Intersect(Players).Except(Neutral).ToArray();
pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(Neutral).ToArray();
pr.Allies = s.Value.Split(',').Intersect(Players).Except(neutral).ToArray();
pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(neutral).ToArray();
break;
}
}

View File

@@ -157,23 +157,23 @@ namespace OpenRA.Editor
void Erase()
{
// Crash preventing
var BrushLocation = GetBrushLocation();
var brushLocation = GetBrushLocation();
if (Map == null || BrushLocation.X >= Map.MapSize.X ||
BrushLocation.Y >= Map.MapSize.Y ||
BrushLocation.X < 0 ||
BrushLocation.Y < 0)
if (Map == null || brushLocation.X >= Map.MapSize.X ||
brushLocation.Y >= Map.MapSize.Y ||
brushLocation.X < 0 ||
brushLocation.Y < 0)
return;
Tool = null;
var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == BrushLocation);
var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == brushLocation);
if (key.Key != null) Map.Actors.Value.Remove(key.Key);
if (Map.MapResources.Value[BrushLocation.X, BrushLocation.Y].type != 0)
if (Map.MapResources.Value[brushLocation.X, brushLocation.Y].type != 0)
{
Map.MapResources.Value[BrushLocation.X, BrushLocation.Y] = new TileReference<byte, byte>();
var ch = new int2((BrushLocation.X) / ChunkSize, (BrushLocation.Y) / ChunkSize);
Map.MapResources.Value[brushLocation.X, brushLocation.Y] = new TileReference<byte, byte>();
var ch = new int2((brushLocation.X) / ChunkSize, (brushLocation.Y) / ChunkSize);
if (Chunks.ContainsKey(ch))
{
Chunks[ch].Dispose();
@@ -267,31 +267,31 @@ namespace OpenRA.Editor
return bitmap;
}
public int2 GetBrushLocation()
public CPos GetBrushLocation()
{
var vX = (int)Math.Floor((MousePos.X - Offset.X) / Zoom);
var vY = (int)Math.Floor((MousePos.Y - Offset.Y) / Zoom);
return new int2(vX / TileSet.TileSize, vY / TileSet.TileSize);
return new CPos(vX / TileSet.TileSize, vY / TileSet.TileSize);
}
public void DrawActor(SGraphics g, int2 p, ActorTemplate t, ColorPalette cp)
public void DrawActor(SGraphics g, CPos p, ActorTemplate t, ColorPalette cp)
{
var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft;
DrawImage(g, t.Bitmap, p, centered, cp);
}
float2 GetDrawPosition(int2 location, Bitmap bmp, bool centered)
float2 GetDrawPosition(CPos location, Bitmap bmp, bool centered)
{
float OffsetX = centered ? bmp.Width / 2 - TileSet.TileSize / 2 : 0;
float DrawX = TileSet.TileSize * location.X * Zoom + Offset.X - OffsetX;
float offsetX = centered ? bmp.Width / 2 - TileSet.TileSize / 2 : 0;
float drawX = TileSet.TileSize * location.X * Zoom + Offset.X - offsetX;
float OffsetY = centered ? bmp.Height / 2 - TileSet.TileSize / 2 : 0;
float DrawY = TileSet.TileSize * location.Y * Zoom + Offset.Y - OffsetY;
float offsetY = centered ? bmp.Height / 2 - TileSet.TileSize / 2 : 0;
float drawY = TileSet.TileSize * location.Y * Zoom + Offset.Y - offsetY;
return new float2(DrawX, DrawY);
return new float2(drawX, drawY);
}
public void DrawImage(SGraphics g, Bitmap bmp, int2 location, bool centered, ColorPalette cp)
public void DrawImage(SGraphics g, Bitmap bmp, CPos location, bool centered, ColorPalette cp)
{
var drawPos = GetDrawPosition(location, bmp, centered);
@@ -304,7 +304,7 @@ namespace OpenRA.Editor
if (cp != null) bmp.Palette = restorePalette;
}
void DrawActorBorder(SGraphics g, int2 p, ActorTemplate t)
void DrawActorBorder(SGraphics g, CPos p, ActorTemplate t)
{
var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft;
var drawPos = GetDrawPosition(p, t.Bitmap, centered);
@@ -399,9 +399,9 @@ namespace OpenRA.Editor
static class ActorReferenceExts
{
public static int2 Location(this ActorReference ar)
public static CPos Location(this ActorReference ar)
{
return ar.InitDict.Get<LocationInit>().value;
return (CPos)ar.InitDict.Get<LocationInit>().value;
}
public static void DrawStringContrast(this SGraphics g, Font f, string s, int x, int y, Brush fg, Brush bg)