Generalize SheetBuilder overflow behavior.

This commit is contained in:
Paul Chote
2013-06-07 17:06:16 +12:00
parent cd268c11ee
commit 0e1c12131a
6 changed files with 57 additions and 28 deletions

View File

@@ -41,6 +41,20 @@ namespace OpenRA.Graphics
int totalVertexCount;
int cachedVertexCount;
SheetBuilder CreateSheetBuilder()
{
var allocated = false;
Func<Sheet> allocate = () =>
{
if (allocated)
throw new SheetOverflowException("");
allocated = true;
return SheetBuilder.AllocateSheet();
};
return new SheetBuilder(SheetType.DualIndexed, allocate);
}
public VoxelLoader()
{
voxels = new Cache<Pair<string,string>, Voxel>(LoadFile);
@@ -48,7 +62,7 @@ namespace OpenRA.Graphics
totalVertexCount = 0;
cachedVertexCount = 0;
sheetBuilder = new SheetBuilder(SheetType.DualIndexed);
sheetBuilder = CreateSheetBuilder();
}
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
@@ -67,7 +81,7 @@ namespace OpenRA.Graphics
c++;
}
Sprite s = sheetBuilder.Allocate(new Size(su, sv), false);
Sprite s = sheetBuilder.Allocate(new Size(su, sv));
Util.FastCopyIntoChannel(s, 0, colors);
Util.FastCopyIntoChannel(s, 1, normals);
s.sheet.MakeDirty();
@@ -164,7 +178,7 @@ namespace OpenRA.Graphics
{
// Sheet overflow - allocate a new sheet and try once more
Log.Write("debug", "Voxel sheet overflow! Generating new sheet");
sheetBuilder = new SheetBuilder(SheetType.DualIndexed);
sheetBuilder = CreateSheetBuilder();
v = GenerateSlicePlanes(l).SelectMany(x => x).ToArray();
}