From d3c92b586f1c2003d849450b7a9886866ae077f2 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Sun, 15 Jan 2012 00:39:07 +0000 Subject: [PATCH] - make TextureAtlas more strict - make TextureAtlas only return false if atlas is full git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9037 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3tools/optimize/TextureAtlas.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/engine/src/tools/jme3tools/optimize/TextureAtlas.java b/engine/src/tools/jme3tools/optimize/TextureAtlas.java index 8251aac15..612fb24b7 100644 --- a/engine/src/tools/jme3tools/optimize/TextureAtlas.java +++ b/engine/src/tools/jme3tools/optimize/TextureAtlas.java @@ -71,10 +71,18 @@ public class TextureAtlas { * Add a texture for a specific map name * @param texture A texture to add to the atlas * @param mapName A freely chosen map name that can be later retrieved as a Texture. The first map name supplied will be the master map. - * @return + * @return false If texture cannot be added to atlas because it does not fit */ public boolean addTexture(Texture texture, String mapName) { - return addTexture(texture, mapName, (String) null); + if (texture == null) { + throw new IllegalStateException("Texture cannot be null"); + } + String name = textureName(texture); + if (texture.getImage() != null && name != null) { + return addImage(texture.getImage(), name, mapName, null); + } else { + throw new IllegalStateException("Source texture has no asset name"); + } } /** @@ -82,14 +90,14 @@ public class TextureAtlas { * @param texture A texture to add to the atlas. * @param mapName A freely chosen map name that can be later retrieved as a Texture. * @param sourceTexture The base texture for determining the location. - * @return + * @return false If texture cannot be added to atlas because it does not fit */ - public boolean addTexture(Texture texture, String mapName, Texture sourceTexture) { + public void addTexture(Texture texture, String mapName, Texture sourceTexture) { String sourceTextureName = textureName(sourceTexture); if (sourceTextureName == null) { - return false; + throw new IllegalStateException("Source texture has no asset name"); } else { - return addTexture(texture, mapName, sourceTextureName); + addTexture(texture, mapName, sourceTextureName); } } @@ -98,17 +106,17 @@ public class TextureAtlas { * @param texture A texture to add to the atlas. * @param mapName A freely chosen map name that can be later retrieved as a Texture. * @param sourceTextureName Name of the base texture for the location. - * @return + * @return false If texture cannot be added to atlas because it does not fit */ - public boolean addTexture(Texture texture, String mapName, String sourceTextureName) { + public void addTexture(Texture texture, String mapName, String sourceTextureName) { if (texture == null) { - return false; + throw new IllegalStateException("Texture cannot be null"); } String name = textureName(texture); if (texture.getImage() != null && name != null) { - return addImage(texture.getImage(), name, mapName, sourceTextureName); + addImage(texture.getImage(), name, mapName, sourceTextureName); } else { - return false; + throw new IllegalStateException("Texture has no asset name"); } } @@ -140,10 +148,9 @@ public class TextureAtlas { location = node.location; } else { location = locationMap.get(sourceTextureName); - } - if (location == null) { - logger.log(Level.WARNING, "Source texture not found"); - return false; + if (location == null) { + throw new IllegalStateException("Cannot find location for source texture"); + } } locationMap.put(name, location); drawImage(image, location.getX(), location.getY(), mapName);