Skip to content

Commit

Permalink
Merged AndEngineTexturePackerExtension into GLES2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Gramlich committed May 7, 2012
1 parent 5506b9a commit 75c216e
Show file tree
Hide file tree
Showing 7 changed files with 746 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/org/andengine/util/texturepack/TexturePack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.andengine.util.texturepack;

import org.andengine.opengl.texture.ITexture;

/**
* (c) Zynga 2011
*
* @author Nicolas Gramlich <[email protected]>
* @since 23:23:47 - 30.07.2011
*/
public class TexturePack {
// ===========================================================
// Constants
// ===========================================================

// ===========================================================
// Fields
// ===========================================================

private final ITexture mTexture;
private final TexturePackTextureRegionLibrary mTexturePackTextureRegionLibrary;

// ===========================================================
// Constructors
// ===========================================================

public TexturePack(final ITexture pTexture, final TexturePackTextureRegionLibrary pTexturePackTextureRegionLibrary) {
this.mTexture = pTexture;
this.mTexturePackTextureRegionLibrary = pTexturePackTextureRegionLibrary;
}

// ===========================================================
// Getter & Setter
// ===========================================================

public ITexture getTexture() {
return this.mTexture;
}

public TexturePackTextureRegionLibrary getTexturePackTextureRegionLibrary() {
return this.mTexturePackTextureRegionLibrary;
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

public void loadTexture() {
this.mTexture.load();
}

public void unloadTexture() {
this.mTexture.unload();
}

// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
51 changes: 51 additions & 0 deletions src/org/andengine/util/texturepack/TexturePackLibrary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.andengine.util.texturepack;

import java.util.HashMap;

/**
* (c) Zynga 2012
*
* @author Nicolas Gramlich <[email protected]>
* @since 17:29:37 - 03.05.2012
*/
public class TexturePackLibrary {
// ===========================================================
// Constants
// ===========================================================

// ===========================================================
// Fields
// ===========================================================

private final HashMap<String, TexturePack> mTexturePackMapping = new HashMap<String, TexturePack>();
private final HashMap<String, TexturePackTextureRegion> mTexturePackTextureRegionSourceMapping = new HashMap<String, TexturePackTextureRegion>();

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

public void put(final String pID, final TexturePack pTexturePack) {
this.mTexturePackMapping.put(pID, pTexturePack);
this.mTexturePackTextureRegionSourceMapping.putAll(pTexturePack.getTexturePackTextureRegionLibrary().getSourceMapping());
}

// ===========================================================
// Methods
// ===========================================================

public TexturePackTextureRegion getTexturePackTextureRegion(final String pTexturePackTextureRegionSource) {
return this.mTexturePackTextureRegionSourceMapping.get(pTexturePackTextureRegionSource);
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
94 changes: 94 additions & 0 deletions src/org/andengine/util/texturepack/TexturePackLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.andengine.util.texturepack;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.andengine.opengl.texture.TextureManager;
import org.andengine.util.StreamUtils;
import org.andengine.util.texturepack.exception.TexturePackParseException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import android.content.res.AssetManager;

/**
* (c) Zynga 2011
*
* @author Nicolas Gramlich <[email protected]>
* @since 17:05:15 - 29.07.2011
*/
public class TexturePackLoader {
// ===========================================================
// Constants
// ===========================================================

// ===========================================================
// Fields
// ===========================================================

private final AssetManager mAssetManager;
private final TextureManager mTextureManager;

// ===========================================================
// Constructors
// ===========================================================

public TexturePackLoader(final AssetManager pAssetManager, final TextureManager pTextureManager) {
this.mAssetManager = pAssetManager;
this.mTextureManager = pTextureManager;
}

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

// ===========================================================
// Methods
// ===========================================================

public TexturePack loadFromAsset(final String pAssetPath, final String pAssetBasePath) throws TexturePackParseException {
try {
return this.load(this.mAssetManager.open(pAssetPath), pAssetBasePath);
} catch (final IOException e) {
throw new TexturePackParseException("Could not load " + this.getClass().getSimpleName() + " data from asset: " + pAssetPath, e);
}
}

public TexturePack load(final InputStream pInputStream, final String pAssetBasePath) throws TexturePackParseException {
try{
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();

final XMLReader xr = sp.getXMLReader();
final TexturePackParser texturePackParser = new TexturePackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
xr.setContentHandler(texturePackParser);

xr.parse(new InputSource(new BufferedInputStream(pInputStream)));

return texturePackParser.getTexturePack();
} catch (final SAXException e) {
throw new TexturePackParseException(e);
} catch (final ParserConfigurationException pe) {
/* Doesn't happen. */
return null;
} catch (final IOException e) {
throw new TexturePackParseException(e);
} finally {
StreamUtils.close(pInputStream);
}
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
Loading

0 comments on commit 75c216e

Please sign in to comment.