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:
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user