diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs
index ed817c7..025ad3b 100644
--- a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs
+++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs
@@ -66,19 +66,19 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
ImageHandler imageHandler;
while (imageHandlerQueue.TryDequeue(out imageHandler))
{
- try
+ Node activeNode = null;
+ do
{
- masterNode.InsertImageHandler(imageHandler);
- }
- catch (InvalidOperationException)
- {
- textureLength *= 2;
- if (!AutoCorrectAtlasSize || textureLength > Math.Pow(2, powLimit))
+ activeNode = masterNode.InsertImageHandler(imageHandler);
+ if (activeNode == null)
{
- 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 childB { get { if (b == null) { b = new Node(this); } return b; } set { value.parent = this; b = value; } }
public Rectangle region;
- public ImageHandler imageHandler;
- public bool Filled { get { return (imageHandler != null) || (a != null && b != null && a.Filled && b.Filled); } }
+ public bool containsImage = false;
+ public bool Filled { get { return containsImage || (a != null && b != null && a.Filled && b.Filled); } }
public Node(Node parent = null)
{
@@ -114,21 +114,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
region = parent.region;
}
- public void SetNodeRegion(int x, int y, int width, int height, ImageHandler imageHandler)
- {
- region.X = x;
- region.Y = y;
- region.Width = width;
- region.Height = height;
- this.imageHandler = imageHandler;
- }
-
- public void SetNodeRegion(ImageHandler imageHandler)
- {
- SetNodeRegion(imageHandler.x, imageHandler.y, imageHandler.Width, imageHandler.Height, imageHandler);
- }
-
-
+ ///
+ /// Attempts to insert image within the node. This builds the node to have children if needed.
+ ///
+ /// the image to insert.
+ /// The node the image is placed in.
public Node InsertImageHandler(ImageHandler imageHandler)
{
if (imageHandler.Width != region.Width)
@@ -176,11 +166,10 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
{
imageHandler.x = region.X;
imageHandler.y = region.Y;
- this.imageHandler = imageHandler;
+ containsImage = true;
return this;
}
-
- throw new ArgumentException();
+ return null;
}
}