Release sheet buffers in SequenceProvider and MapCache.

The buffers in SequenceProvider can be freed if Preload is called, since we know everything is loaded. A SequenceProvider is created for each TileSet is use so this saves memory for however many tilesets had been used in the game. This will be at least one for the shellmap, and often more.

The MapCache loading thread is kept alive for 5 seconds after it last generated a map (in anticipation of more requests). Once this time expires the thread is allowed to die, as it is unlikely there will be more requests in the short term. At this time it is ideal to force the changes to be committed to the texture so we can release the buffer. As well as marking the buffer for release, we must access the texture to force the changes stored in the buffer to be written to the texture, after which the buffer can be reclaimed.

Additionally, when starting the MapCache loading thread we must ensure the buffer is created from the main thread since it may query the texture object which has thread affinity. After that the buffer may be modified freely on the loading thread until released.
This commit is contained in:
RoosterDragon
2014-10-13 21:16:14 +01:00
committed by RoosterDragon
parent a6f5a21ed4
commit c2b7d9ca5b
3 changed files with 47 additions and 14 deletions

View File

@@ -27,13 +27,7 @@ namespace OpenRA.Graphics
public readonly Size Size;
public byte[] GetData()
{
if (data != null)
return data;
if (texture == null)
data = new byte[4 * Size.Width * Size.Height];
else
data = texture.GetData();
releaseBufferOnCommit = false;
CreateBuffer();
return data;
}
public bool Buffered { get { return data != null || texture == null; } }
@@ -144,6 +138,17 @@ namespace OpenRA.Graphics
return bitmap;
}
public void CreateBuffer()
{
if (data != null)
return;
if (texture == null)
data = new byte[4 * Size.Width * Size.Height];
else
data = texture.GetData();
releaseBufferOnCommit = false;
}
public void CommitData()
{
CommitData(false);