- add a way to add a classpath for loading in-asset classes to AssetManager, use in BinaryImporter

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8600 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 6936c34b75
commit 9f16b989fe
  1. 18
      engine/src/android/com/jme3/asset/AndroidAssetManager.java
  2. 12
      engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java
  3. 19
      engine/src/core/com/jme3/asset/AssetManager.java
  4. 20
      engine/src/desktop/com/jme3/asset/DesktopAssetManager.java

@ -39,6 +39,8 @@ import java.util.logging.Logger;
import com.jme3.asset.plugins.AndroidLocator; import com.jme3.asset.plugins.AndroidLocator;
import com.jme3.asset.plugins.ClasspathLocator; import com.jme3.asset.plugins.ClasspathLocator;
import com.jme3.audio.plugins.AndroidAudioLoader; import com.jme3.audio.plugins.AndroidAudioLoader;
import java.util.ArrayList;
import java.util.List;
/** /**
* <code>AndroidAssetManager</code> is an implementation of DesktopAssetManager for Android * <code>AndroidAssetManager</code> is an implementation of DesktopAssetManager for Android
@ -48,6 +50,7 @@ import com.jme3.audio.plugins.AndroidAudioLoader;
public class AndroidAssetManager extends DesktopAssetManager { public class AndroidAssetManager extends DesktopAssetManager {
private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName()); private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName());
private List<ClassLoader> classLoaders;
public AndroidAssetManager() { public AndroidAssetManager() {
this(null); this(null);
@ -94,6 +97,21 @@ public class AndroidAssetManager extends DesktopAssetManager {
logger.info("AndroidAssetManager created."); logger.info("AndroidAssetManager created.");
} }
public void addClassLoader(ClassLoader loader){
if(classLoaders == null)
classLoaders = new ArrayList<ClassLoader>();
classLoaders.add(loader);
}
public void removeClassLoader(ClassLoader loader){
if(classLoaders != null)
classLoaders.remove(loader);
}
public List<ClassLoader> getClassLoaders(){
return classLoaders;
}
/** /**
* Loads a texture. * Loads a texture.
* *

@ -50,10 +50,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -88,8 +86,6 @@ public final class BinaryImporter implements JmeImporter {
private static final boolean fastRead = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; private static final boolean fastRead = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
private List<ClassLoader> loaders;
public BinaryImporter() { public BinaryImporter() {
} }
@ -101,12 +97,6 @@ public final class BinaryImporter implements JmeImporter {
return fastRead; return fastRead;
} }
public void addClassLoader(ClassLoader loader){
if(loaders == null)
loaders = new ArrayList<ClassLoader>();
loaders.add(loader);
}
public static BinaryImporter getInstance() { public static BinaryImporter getInstance() {
return new BinaryImporter(); return new BinaryImporter();
} }
@ -346,7 +336,7 @@ public final class BinaryImporter implements JmeImporter {
int dataLength = ByteUtils.convertIntFromBytes(dataArray, loc); int dataLength = ByteUtils.convertIntFromBytes(dataArray, loc);
loc+=4; loc+=4;
Savable out = SavableClassUtil.fromName(bco.className, loaders); Savable out = SavableClassUtil.fromName(bco.className, assetManager.getClassLoaders());
BinaryInputCapsule cap = new BinaryInputCapsule(this, out, bco); BinaryInputCapsule cap = new BinaryInputCapsule(this, out, bco);
cap.setContent(dataArray, loc, loc+dataLength); cap.setContent(dataArray, loc, loc+dataLength);

@ -40,6 +40,7 @@ import com.jme3.scene.Spatial;
import com.jme3.shader.Shader; import com.jme3.shader.Shader;
import com.jme3.shader.ShaderKey; import com.jme3.shader.ShaderKey;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import java.util.List;
/** /**
* <code>AssetManager</code> provides an interface for managing the data assets * <code>AssetManager</code> provides an interface for managing the data assets
@ -47,6 +48,24 @@ import com.jme3.texture.Texture;
*/ */
public interface AssetManager { public interface AssetManager {
/**
* Adds a ClassLoader that is used to load *Classes* that are needed for Assets like j3o models.
* This does *not* allow loading assets from that classpath, use registerLocator for that.
* @param loader A ClassLoader that Classes in asset files can be loaded from
*/
public void addClassLoader(ClassLoader loader);
/**
* Remove a ClassLoader from the list of registered ClassLoaders
*/
public void removeClassLoader(ClassLoader loader);
/**
* Retrieve the list of registered ClassLoaders that are used for loading Classes from
* asset files.
*/
public List<ClassLoader> getClassLoaders();
/** /**
* Registers a loader for the given extensions. * Registers a loader for the given extensions.
* @param loaderClassName * @param loaderClassName

@ -44,7 +44,9 @@ import com.jme3.texture.Texture;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -62,6 +64,7 @@ public class DesktopAssetManager implements AssetManager {
private final ImplHandler handler = new ImplHandler(this); private final ImplHandler handler = new ImplHandler(this);
private AssetEventListener eventListener = null; private AssetEventListener eventListener = null;
private List<ClassLoader> classLoaders;
// private final ThreadingManager threadingMan = new ThreadingManager(this); // private final ThreadingManager threadingMan = new ThreadingManager(this);
// private final Set<AssetKey> alreadyLoadingSet = new HashSet<AssetKey>(); // private final Set<AssetKey> alreadyLoadingSet = new HashSet<AssetKey>();
@ -95,6 +98,21 @@ public class DesktopAssetManager implements AssetManager {
logger.info("DesktopAssetManager created."); logger.info("DesktopAssetManager created.");
} }
public void addClassLoader(ClassLoader loader){
if(classLoaders == null)
classLoaders = new ArrayList<ClassLoader>();
classLoaders.add(loader);
}
public void removeClassLoader(ClassLoader loader){
if(classLoaders != null)
classLoaders.remove(loader);
}
public List<ClassLoader> getClassLoaders(){
return classLoaders;
}
public void setAssetEventListener(AssetEventListener listener){ public void setAssetEventListener(AssetEventListener listener){
eventListener = listener; eventListener = listener;
} }
@ -198,7 +216,7 @@ public class DesktopAssetManager implements AssetManager {
* @param key * @param key
* @return * @return
*/ */
public <T> T loadAsset(AssetKey<T> key){ public <T> T loadAsset(AssetKey<T> key){
if (key == null) if (key == null)
throw new IllegalArgumentException("key cannot be null"); throw new IllegalArgumentException("key cannot be null");

Loading…
Cancel
Save