- 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
3.0
nor..67 13 years ago
parent 99c7797ea5
commit d3c92b586f
  1. 37
      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);

Loading…
Cancel
Save