Add MapGrid class
MapGrid is a mod Manifest field which includes (and thus makes redundant) TileSize, TileShape, SubCells info and MaximumTerrainHeight.
This commit is contained in:
@@ -20,12 +20,12 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false)
|
||||
{
|
||||
var isDiamond = map.TileShape == TileShape.Diamond;
|
||||
var isDiamond = map.Grid.Type == TileShape.Diamond;
|
||||
var b = map.Bounds;
|
||||
|
||||
// Fudge the heightmap offset by adding as much extra as we need / can.
|
||||
// This tries to correct for our incorrect assumption that MPos == PPos
|
||||
var heightOffset = Math.Min(map.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
|
||||
var heightOffset = Math.Min(map.Grid.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
|
||||
var width = b.Width;
|
||||
var height = b.Height + heightOffset;
|
||||
|
||||
@@ -81,12 +81,12 @@ namespace OpenRA.Graphics
|
||||
static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap)
|
||||
{
|
||||
var terrain = new Bitmap(terrainBitmap);
|
||||
var isDiamond = map.TileShape == TileShape.Diamond;
|
||||
var isDiamond = map.Grid.Type == TileShape.Diamond;
|
||||
var b = map.Bounds;
|
||||
|
||||
// Fudge the heightmap offset by adding as much extra as we need / can
|
||||
// This tries to correct for our incorrect assumption that MPos == PPos
|
||||
var heightOffset = Math.Min(map.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
|
||||
var heightOffset = Math.Min(map.Grid.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
|
||||
var width = b.Width;
|
||||
var height = b.Height + heightOffset;
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var pos = sprite == null ? float2.Zero :
|
||||
worldRenderer.ScreenPosition(map.CenterOfCell(cell)) + sprite.Offset - 0.5f * sprite.Size;
|
||||
Update(cell.ToMPos(map.TileShape), sprite, pos);
|
||||
Update(cell.ToMPos(map.Grid.Type), sprite, pos);
|
||||
}
|
||||
|
||||
public void Update(MPos uv, Sprite sprite, float2 pos)
|
||||
|
||||
@@ -92,15 +92,15 @@ namespace OpenRA.Graphics
|
||||
public Viewport(WorldRenderer wr, Map map)
|
||||
{
|
||||
worldRenderer = wr;
|
||||
var grid = Game.ModData.Manifest.Get<MapGrid>();
|
||||
|
||||
// Calculate map bounds in world-px
|
||||
if (wr.World.Type == WorldType.Editor)
|
||||
{
|
||||
// The full map is visible in the editor
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
var width = map.MapSize.X * ts.Width;
|
||||
var height = map.MapSize.Y * ts.Height;
|
||||
if (wr.World.Map.TileShape == TileShape.Diamond)
|
||||
var width = map.MapSize.X * grid.TileSize.Width;
|
||||
var height = map.MapSize.Y * grid.TileSize.Height;
|
||||
if (wr.World.Map.Grid.Type == TileShape.Diamond)
|
||||
height /= 2;
|
||||
|
||||
mapBounds = new Rectangle(0, 0, width, height);
|
||||
@@ -115,23 +115,22 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
|
||||
Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
|
||||
tileSize = Game.ModData.Manifest.TileSize;
|
||||
tileSize = grid.TileSize;
|
||||
}
|
||||
|
||||
public CPos ViewToWorld(int2 view)
|
||||
{
|
||||
var world = worldRenderer.Viewport.ViewToWorldPx(view);
|
||||
var map = worldRenderer.World.Map;
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
var candidates = CandidateMouseoverCells(world);
|
||||
var candidates = CandidateMouseoverCells(world).ToList();
|
||||
var tileSet = worldRenderer.World.TileSet;
|
||||
|
||||
foreach (var uv in candidates)
|
||||
{
|
||||
// Coarse filter to nearby cells
|
||||
var p = map.CenterOfCell(uv.ToCPos(map.TileShape));
|
||||
var p = map.CenterOfCell(uv.ToCPos(map.Grid.Type));
|
||||
var s = worldRenderer.ScreenPxPosition(p);
|
||||
if (Math.Abs(s.X - world.X) <= ts.Width && Math.Abs(s.Y - world.Y) <= ts.Height)
|
||||
if (Math.Abs(s.X - world.X) <= tileSize.Width && Math.Abs(s.Y - world.Y) <= tileSize.Height)
|
||||
{
|
||||
var ramp = 0;
|
||||
if (map.Contains(uv))
|
||||
@@ -153,11 +152,11 @@ namespace OpenRA.Graphics
|
||||
|
||||
// Mouse is not directly over a cell (perhaps on a cliff)
|
||||
// Try and find the closest cell
|
||||
if (candidates.Any())
|
||||
if (candidates.Count > 0)
|
||||
{
|
||||
return candidates.OrderBy(uv =>
|
||||
{
|
||||
var p = map.CenterOfCell(uv.ToCPos(map.TileShape));
|
||||
var p = map.CenterOfCell(uv.ToCPos(map.Grid.Type));
|
||||
var s = worldRenderer.ScreenPxPosition(p);
|
||||
var dx = Math.Abs(s.X - world.X);
|
||||
var dy = Math.Abs(s.Y - world.Y);
|
||||
@@ -177,8 +176,8 @@ namespace OpenRA.Graphics
|
||||
var minPos = worldRenderer.ProjectedPosition(world);
|
||||
|
||||
// Find all the cells that could potentially have been clicked
|
||||
var a = map.CellContaining(minPos - new WVec(1024, 0, 0)).ToMPos(map.TileShape);
|
||||
var b = map.CellContaining(minPos + new WVec(512, 512 * map.MaximumTerrainHeight, 0)).ToMPos(map.TileShape);
|
||||
var a = map.CellContaining(minPos - new WVec(1024, 0, 0)).ToMPos(map.Grid.Type);
|
||||
var b = map.CellContaining(minPos + new WVec(512, 512 * map.Grid.MaximumTerrainHeight, 0)).ToMPos(map.Grid.Type);
|
||||
|
||||
for (var v = b.V; v >= a.V; v--)
|
||||
for (var u = b.U; u >= a.U; u--)
|
||||
@@ -244,7 +243,7 @@ namespace OpenRA.Graphics
|
||||
// Diamond tile shapes don't have straight edges, and so we need
|
||||
// an additional cell margin to include the cells that are half
|
||||
// visible on each edge.
|
||||
if (map.TileShape == TileShape.Diamond)
|
||||
if (map.Grid.Type == TileShape.Diamond)
|
||||
{
|
||||
tl = new PPos(tl.U - 1, tl.V - 1);
|
||||
br = new PPos(br.U + 1, br.V + 1);
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace OpenRA.Graphics
|
||||
static readonly int[][] RangeCircleStartRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i).AsMatrix());
|
||||
static readonly int[][] RangeCircleEndRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i + 6).AsMatrix());
|
||||
|
||||
public readonly Size TileSize;
|
||||
public readonly World World;
|
||||
public readonly Theater Theater;
|
||||
public Viewport Viewport { get; private set; }
|
||||
@@ -40,6 +41,7 @@ namespace OpenRA.Graphics
|
||||
internal WorldRenderer(World world)
|
||||
{
|
||||
World = world;
|
||||
TileSize = World.Map.Grid.TileSize;
|
||||
Viewport = new Viewport(this, world.Map);
|
||||
|
||||
createPaletteReference = CreatePaletteReference;
|
||||
@@ -231,8 +233,7 @@ namespace OpenRA.Graphics
|
||||
// Conversion between world and screen coordinates
|
||||
public float2 ScreenPosition(WPos pos)
|
||||
{
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return new float2(ts.Width * pos.X / 1024f, ts.Height * (pos.Y - pos.Z) / 1024f);
|
||||
return new float2(TileSize.Width * pos.X / 1024f, TileSize.Height * (pos.Y - pos.Z) / 1024f);
|
||||
}
|
||||
|
||||
public int2 ScreenPxPosition(WPos pos)
|
||||
@@ -245,10 +246,9 @@ namespace OpenRA.Graphics
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
public void ScreenVectorComponents(WVec vec, out float x, out float y, out float z)
|
||||
{
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
x = ts.Width * vec.X / 1024f;
|
||||
y = ts.Height * vec.Y / 1024f;
|
||||
z = ts.Height * vec.Z / 1024f;
|
||||
x = TileSize.Width * vec.X / 1024f;
|
||||
y = TileSize.Height * vec.Y / 1024f;
|
||||
z = TileSize.Height * vec.Z / 1024f;
|
||||
}
|
||||
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
@@ -269,8 +269,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public float ScreenZPosition(WPos pos, int offset)
|
||||
{
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return ZPosition(pos, offset) * ts.Height / 1024f;
|
||||
return ZPosition(pos, offset) * TileSize.Height / 1024f;
|
||||
}
|
||||
|
||||
static int ZPosition(WPos pos, int offset)
|
||||
@@ -284,8 +283,7 @@ namespace OpenRA.Graphics
|
||||
/// </summary>
|
||||
public WPos ProjectedPosition(int2 screenPx)
|
||||
{
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return new WPos(1024 * screenPx.X / ts.Width, 1024 * screenPx.Y / ts.Height, 0);
|
||||
return new WPos(1024 * screenPx.X / TileSize.Width, 1024 * screenPx.Y / TileSize.Height, 0);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in New Issue
Block a user