AssetManager: set locator path only once per thread
This commit is contained in:
parent
7659a7b986
commit
500f57a64f
@ -75,7 +75,7 @@ final class ImplHandler {
|
||||
this.assetManager = assetManager;
|
||||
}
|
||||
|
||||
protected static class ImplThreadLocal<T> extends ThreadLocal {
|
||||
protected static class ImplThreadLocal<T> extends ThreadLocal<T> {
|
||||
|
||||
private final Class<T> type;
|
||||
private final String path;
|
||||
@ -112,9 +112,13 @@ final class ImplHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object initialValue(){
|
||||
protected T initialValue(){
|
||||
try {
|
||||
return type.newInstance();
|
||||
T obj = type.newInstance();
|
||||
if (path != null) {
|
||||
((AssetLocator)obj).setRootPath(path);
|
||||
}
|
||||
return obj;
|
||||
} catch (InstantiationException ex) {
|
||||
logger.log(Level.SEVERE,"Cannot create locator of type {0}, does"
|
||||
+ " the class have an empty and publically accessible"+
|
||||
@ -169,14 +173,11 @@ final class ImplHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ImplThreadLocal local : locatorsList){
|
||||
AssetLocator locator = (AssetLocator) local.get();
|
||||
if (local.getPath() != null){
|
||||
locator.setRootPath((String) local.getPath());
|
||||
}
|
||||
AssetInfo info = locator.locate(assetManager, key);
|
||||
if (info != null)
|
||||
for (ImplThreadLocal<AssetLocator> local : locatorsList){
|
||||
AssetInfo info = local.get().locate(assetManager, key);
|
||||
if (info != null) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -36,10 +36,10 @@ import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.asset.TextureKey;
|
||||
import com.jme3.asset.plugins.HttpZipLocator;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.jme3.ui.Picture;
|
||||
|
||||
/**
|
||||
* This tests loading a file from a jar stored online.
|
||||
@ -59,22 +59,27 @@ public class TestOnlineJar extends SimpleApplication {
|
||||
quadMesh.updateGeometry(1, 1, true);
|
||||
|
||||
Geometry quad = new Geometry("Textured Quad", quadMesh);
|
||||
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/town.zip",
|
||||
HttpZipLocator.class);
|
||||
|
||||
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/town.zip",
|
||||
HttpZipLocator.class);
|
||||
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip",
|
||||
HttpZipLocator.class);
|
||||
|
||||
TextureKey key = new TextureKey("grass.jpg", false);
|
||||
key.setGenerateMips(true);
|
||||
Texture tex = assetManager.loadTexture(key);
|
||||
|
||||
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat.setTexture("ColorMap", tex);
|
||||
quad.setMaterial(mat);
|
||||
|
||||
float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
|
||||
quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
|
||||
quad.center();
|
||||
|
||||
rootNode.attachChild(quad);
|
||||
Picture pic1 = new Picture("Picture1");
|
||||
pic1.move(0, 0, -1);
|
||||
pic1.setPosition(0, 0);
|
||||
pic1.setWidth(128);
|
||||
pic1.setHeight(128);
|
||||
pic1.setImage(assetManager, "grass.jpg", false);
|
||||
guiNode.attachChild(pic1);
|
||||
|
||||
Picture pic2 = new Picture("Picture1");
|
||||
pic2.move(0, 0, -1);
|
||||
pic2.setPosition(128, 0);
|
||||
pic2.setWidth(128);
|
||||
pic2.setHeight(128);
|
||||
pic2.setImage(assetManager, "glasstile2.png", false);
|
||||
guiNode.attachChild(pic2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user