Merge pull request #6830 from RoosterDragon/dispose-renderer-resources

Closes #5116
This commit is contained in:
Matthias Mailänder
2014-12-22 19:59:41 +01:00
34 changed files with 575 additions and 343 deletions

View File

@@ -11,20 +11,19 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.LoadScreens
{
public class DefaultLoadScreen : ILoadScreen
public sealed class DefaultLoadScreen : ILoadScreen
{
Stopwatch lastUpdate = Stopwatch.StartNew();
Renderer r;
Rectangle stripeRect;
float2 logoPos;
Sheet sheet;
Sprite stripe, logo;
string[] messages;
@@ -37,9 +36,9 @@ namespace OpenRA.Mods.Common.LoadScreens
return;
messages = info["Text"].Split(',');
var s = new Sheet(Platform.ResolvePath(info["Image"]));
logo = new Sprite(s, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha);
stripe = new Sprite(s, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha);
sheet = new Sheet(Platform.ResolvePath(info["Image"]));
logo = new Sprite(sheet, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha);
stripe = new Sprite(sheet, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha);
stripeRect = new Rectangle(0, r.Resolution.Height / 2 - 128, r.Resolution.Width, 256);
logoPos = new float2(r.Resolution.Width / 2 - 128, r.Resolution.Height / 2 - 128);
}
@@ -71,5 +70,11 @@ namespace OpenRA.Mods.Common.LoadScreens
{
Game.TestAndContinue();
}
public void Dispose()
{
if (sheet != null)
sheet.Dispose();
}
}
}

View File

@@ -15,7 +15,7 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.LoadScreens
{
public class ModChooserLoadScreen : ILoadScreen
public sealed class ModChooserLoadScreen : ILoadScreen
{
Sprite sprite;
Rectangle bounds;
@@ -43,5 +43,11 @@ namespace OpenRA.Mods.Common.LoadScreens
{
Ui.LoadWidget("MODCHOOSER", Ui.Root, new WidgetArgs());
}
public void Dispose()
{
if (sprite != null)
sprite.sheet.Dispose();
}
}
}

View File

@@ -13,7 +13,7 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.LoadScreens
{
public class NullLoadScreen : ILoadScreen
public sealed class NullLoadScreen : ILoadScreen
{
public void Init(Manifest m, Dictionary<string, string> info) { }
@@ -31,5 +31,9 @@ namespace OpenRA.Mods.Common.LoadScreens
{
Ui.ResetAll();
}
public void Dispose()
{
}
}
}
}

View File

@@ -20,15 +20,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class ModBrowserLogic
{
Widget modList;
ButtonWidget modTemplate;
ModMetadata[] allMods;
readonly Widget modList;
readonly ButtonWidget modTemplate;
readonly ModMetadata[] allMods;
readonly Dictionary<string, Sprite> previews = new Dictionary<string, Sprite>();
readonly Dictionary<string, Sprite> logos = new Dictionary<string, Sprite>();
readonly SheetBuilder sheetBuilder;
ModMetadata selectedMod;
string selectedAuthor;
string selectedDescription;
int modOffset = 0;
Dictionary<string, Sprite> previews;
Dictionary<string, Sprite> logos;
[ObjectCreator.UseCtor]
public ModBrowserLogic(Widget widget)
@@ -63,9 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return ret;
};
var sheetBuilder = new SheetBuilder(SheetType.BGRA);
previews = new Dictionary<string, Sprite>();
logos = new Dictionary<string, Sprite>();
sheetBuilder = new SheetBuilder(SheetType.BGRA);
allMods = ModMetadata.AllMods.Values.Where(m => m.Id != "modchooser")
.OrderBy(m => m.Title)
.ToArray();
@@ -75,21 +74,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
try
{
var preview = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "preview.png"));
if (preview.Width != 296 || preview.Height != 196)
continue;
previews.Add(mod.Id, sheetBuilder.Add(preview));
using (var preview = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "preview.png")))
if (preview.Width == 296 && preview.Height == 196)
previews.Add(mod.Id, sheetBuilder.Add(preview));
}
catch (Exception) { }
try
{
var logo = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "logo.png"));
if (logo.Width != 96 || logo.Height != 96)
continue;
logos.Add(mod.Id, sheetBuilder.Add(logo));
using (var logo = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "logo.png")))
if (logo.Width == 96 && logo.Height == 96)
logos.Add(mod.Id, sheetBuilder.Add(logo));
}
catch (Exception) { }
}
@@ -155,11 +150,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
modOffset = selectedIndex - 4;
}
static void LoadMod(ModMetadata mod)
void LoadMod(ModMetadata mod)
{
Game.RunAfterTick(() =>
{
Ui.CloseWindow();
sheetBuilder.Dispose();
Game.InitializeMod(mod.Id, null);
});
}