Don't store pre-calculated texture coords in Sprite.

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.
This commit is contained in:
RoosterDragon
2014-10-03 21:04:21 +01:00
parent 59b3cd154d
commit bbb3990a0f
3 changed files with 30 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Graphics
public readonly float2 size;
public readonly float2 offset;
public readonly float2 fractionalOffset;
readonly float2[] textureCoords;
readonly float top, left, bottom, right;
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) {}
@@ -40,22 +40,30 @@ namespace OpenRA.Graphics
this.fractionalOffset = offset / this.size;
var left = (float)(bounds.Left) / sheet.Size.Width;
var top = (float)(bounds.Top) / sheet.Size.Height;
var right = (float)(bounds.Right) / sheet.Size.Width;
var bottom = (float)(bounds.Bottom) / sheet.Size.Height;
textureCoords = new float2[]
{
new float2(left, top),
new float2(right, top),
new float2(left, bottom),
new float2(right, bottom),
};
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 FastMapTextureCoords(int k)
public float2 TopLeftTextureCoords
{
return textureCoords[k];
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); }
}
}