By storing only the four corners, we can save the object overhead of an array and 4 float elements per sprite. This results in savings of around 5 MiB to store these coordinates.
78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation. For more information,
|
|
* see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System.Drawing;
|
|
|
|
namespace OpenRA.Graphics
|
|
{
|
|
public class Sprite
|
|
{
|
|
public readonly Rectangle bounds;
|
|
public readonly Sheet sheet;
|
|
public readonly BlendMode blendMode;
|
|
public readonly TextureChannel channel;
|
|
public readonly float2 size;
|
|
public readonly float2 offset;
|
|
public readonly float2 fractionalOffset;
|
|
readonly float top, left, bottom, right;
|
|
|
|
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
|
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) {}
|
|
|
|
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel, BlendMode blendMode)
|
|
: this(sheet, bounds, float2.Zero, channel, blendMode) {}
|
|
|
|
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode)
|
|
{
|
|
this.sheet = sheet;
|
|
this.bounds = bounds;
|
|
this.offset = offset;
|
|
this.channel = channel;
|
|
this.size = new float2(bounds.Size);
|
|
this.blendMode = blendMode;
|
|
|
|
this.fractionalOffset = offset / this.size;
|
|
|
|
left = (float)(bounds.Left) / sheet.Size.Width;
|
|
top = (float)(bounds.Top) / sheet.Size.Height;
|
|
right = (float)(bounds.Right) / sheet.Size.Width;
|
|
bottom = (float)(bounds.Bottom) / sheet.Size.Height;
|
|
}
|
|
|
|
public float2 TopLeftTextureCoords
|
|
{
|
|
get { return new float2(left, top); }
|
|
}
|
|
|
|
public float2 TopRightTextureCoords
|
|
{
|
|
get { return new float2(right, top); }
|
|
}
|
|
|
|
public float2 BottomLeftTextureCoords
|
|
{
|
|
get { return new float2(left, bottom); }
|
|
}
|
|
|
|
public float2 BottomRightTextureCoords
|
|
{
|
|
get { return new float2(right, bottom); }
|
|
}
|
|
}
|
|
|
|
public enum TextureChannel
|
|
{
|
|
Red = 0,
|
|
Green = 1,
|
|
Blue = 2,
|
|
Alpha = 3,
|
|
}
|
|
}
|