fixed the build function

This commit is contained in:
Harrison Deng 2018-12-07 11:20:46 -06:00
parent 26a359de46
commit b705b2a457

View File

@ -66,19 +66,19 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
ImageHandler imageHandler; ImageHandler imageHandler;
while (imageHandlerQueue.TryDequeue(out imageHandler)) while (imageHandlerQueue.TryDequeue(out imageHandler))
{ {
try Node activeNode = null;
do
{ {
masterNode.InsertImageHandler(imageHandler); activeNode = masterNode.InsertImageHandler(imageHandler);
} if (activeNode == null)
catch (InvalidOperationException)
{
textureLength *= 2;
if (!AutoCorrectAtlasSize || textureLength > Math.Pow(2, powLimit))
{ {
throw new InvalidOperationException("Dimensions of texture goes past limit amount of " + powLimit + " which is " + Math.Pow(2, powLimit) + ". New texture size would be " + textureLength + "x" + textureLength + "."); if (!AutoCorrectAtlasSize || (textureLength *= 2) > Math.Pow(2, powLimit))
{
throw new InvalidOperationException("Dimensions of texture goes past limit amount of " + powLimit + " which is " + Math.Pow(2, powLimit) + ". New texture size would be " + textureLength + "x" + textureLength + ".");
}
} }
Build();
} }
while (activeNode == null);
} }
} }
@ -105,8 +105,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
public Node childA { get { if (a == null) a = new Node(this); return a; } set { value.parent = this; a = value; } } public Node childA { get { if (a == null) a = new Node(this); return a; } set { value.parent = this; a = value; } }
public Node childB { get { if (b == null) { b = new Node(this); } return b; } set { value.parent = this; b = value; } } public Node childB { get { if (b == null) { b = new Node(this); } return b; } set { value.parent = this; b = value; } }
public Rectangle region; public Rectangle region;
public ImageHandler imageHandler; public bool containsImage = false;
public bool Filled { get { return (imageHandler != null) || (a != null && b != null && a.Filled && b.Filled); } } public bool Filled { get { return containsImage || (a != null && b != null && a.Filled && b.Filled); } }
public Node(Node parent = null) public Node(Node parent = null)
{ {
@ -114,21 +114,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
region = parent.region; region = parent.region;
} }
public void SetNodeRegion(int x, int y, int width, int height, ImageHandler imageHandler) /// <summary>
{ /// Attempts to insert image within the node. This builds the node to have children if needed.
region.X = x; /// </summary>
region.Y = y; /// <param name="imageHandler">the image to insert.</param>
region.Width = width; /// <returns>The node the image is placed in.</returns>
region.Height = height;
this.imageHandler = imageHandler;
}
public void SetNodeRegion(ImageHandler imageHandler)
{
SetNodeRegion(imageHandler.x, imageHandler.y, imageHandler.Width, imageHandler.Height, imageHandler);
}
public Node InsertImageHandler(ImageHandler imageHandler) public Node InsertImageHandler(ImageHandler imageHandler)
{ {
if (imageHandler.Width != region.Width) if (imageHandler.Width != region.Width)
@ -176,11 +166,10 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
{ {
imageHandler.x = region.X; imageHandler.x = region.X;
imageHandler.y = region.Y; imageHandler.y = region.Y;
this.imageHandler = imageHandler; containsImage = true;
return this; return this;
} }
return null;
throw new ArgumentException();
} }
} }