proper handling of dirty sheets (about 2 years overdue)

This commit is contained in:
Chris Forbes
2010-03-17 22:32:12 +13:00
parent cbf11c3559
commit d37a59d1c9
3 changed files with 11 additions and 9 deletions

View File

@@ -28,8 +28,8 @@ namespace OpenRA.Graphics
{ {
readonly Renderer renderer; readonly Renderer renderer;
protected readonly Bitmap bitmap; protected readonly Bitmap bitmap;
ITexture texture; ITexture texture;
bool dirty;
internal Sheet(Renderer renderer, Size size) internal Sheet(Renderer renderer, Size size)
{ {
@@ -43,17 +43,18 @@ namespace OpenRA.Graphics
this.bitmap = (Bitmap)Image.FromStream(FileSystem.Open(filename)); this.bitmap = (Bitmap)Image.FromStream(FileSystem.Open(filename));
} }
void Resolve()
{
texture = renderer.Device.CreateTexture(bitmap);
}
public ITexture Texture public ITexture Texture
{ {
get get
{ {
if (texture == null) if (texture == null)
Resolve(); texture = renderer.Device.CreateTexture(bitmap);
if (dirty)
{
texture.SetData(bitmap);
dirty = false;
}
return texture; return texture;
} }
@@ -68,5 +69,7 @@ namespace OpenRA.Graphics
} }
public Bitmap Bitmap { get { return bitmap; } } // for perf public Bitmap Bitmap { get { return bitmap; } } // for perf
public void MakeDirty() { dirty = true; }
} }
} }

View File

@@ -111,6 +111,7 @@ namespace OpenRA.Graphics
} }
Sprite rect = new Sprite(current, new Rectangle(p, imageSize), channel.Value); Sprite rect = new Sprite(current, new Rectangle(p, imageSize), channel.Value);
current.MakeDirty();
p.X += imageSize.Width; p.X += imageSize.Width;
return rect; return rect;

View File

@@ -53,8 +53,6 @@ namespace OpenRA
sprites = new Sprite[map.MapSize, map.MapSize]; sprites = new Sprite[map.MapSize, map.MapSize];
gapField = new int[map.MapSize, map.MapSize]; gapField = new int[map.MapSize, map.MapSize];
gapActive = new bool[map.MapSize, map.MapSize]; gapActive = new bool[map.MapSize, map.MapSize];
shadowBits[0].sheet.Texture.SetData(shadowBits[0].sheet.Bitmap); // HACK
} }
public bool HasGPS public bool HasGPS