src/android patchset: changes AndroidAssetManager, AndroidInput, OGLESContext, JmeSystem, TextureLoader
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7502 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
0ec3bb6dba
commit
a8e9d803dc
@ -0,0 +1,287 @@ |
||||
/* |
||||
* Copyright (c) 2009-2010 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.app.android; |
||||
|
||||
import java.nio.CharBuffer; |
||||
import java.util.concurrent.atomic.AtomicBoolean; |
||||
|
||||
import android.app.Activity; |
||||
import android.app.AlertDialog; |
||||
import android.content.DialogInterface; |
||||
import com.jme3.app.Application; |
||||
import com.jme3.font.BitmapFont; |
||||
import com.jme3.font.BitmapText; |
||||
import com.jme3.input.android.AndroidInput; |
||||
import com.jme3.renderer.RenderManager; |
||||
import com.jme3.renderer.queue.RenderQueue.Bucket; |
||||
import com.jme3.scene.Node; |
||||
import com.jme3.scene.Spatial.CullHint; |
||||
import com.jme3.system.AppSettings; |
||||
import com.jme3.system.JmeSystem; |
||||
import com.jme3.util.FastInteger; |
||||
|
||||
|
||||
/** |
||||
* <code>AndroidApplication</code> extends the {@link com.jme3.app.Application} |
||||
* class to provide default functionality like a first-person camera, |
||||
* and an accessible root node that is updated and rendered regularly. |
||||
* It will display the current frames-per-second value on-screen. |
||||
* |
||||
* |
||||
*/ |
||||
public abstract class AndroidApplication extends Application implements DialogInterface.OnClickListener |
||||
{ |
||||
|
||||
protected Node rootNode = new Node("Root Node"); |
||||
protected Node guiNode = new Node("Gui Node"); |
||||
protected float secondCounter = 0.0f; |
||||
protected BitmapText fpsText; |
||||
protected CharBuffer textBuf = CharBuffer.allocate(50); |
||||
protected char[] fpsBuf = new char[16]; |
||||
protected BitmapFont guiFont; |
||||
|
||||
protected Activity activity; |
||||
protected AndroidInput input; |
||||
protected final AtomicBoolean loadingFinished; |
||||
|
||||
public AndroidApplication() |
||||
{ |
||||
this(null, null); |
||||
} |
||||
|
||||
public AndroidApplication(Activity activity, AndroidInput input) |
||||
{ |
||||
super(); |
||||
this.activity = activity; |
||||
this.input = input; |
||||
|
||||
loadingFinished = new AtomicBoolean(false); |
||||
} |
||||
|
||||
@Override |
||||
public void start() |
||||
{ |
||||
// Set the correct xml parser driver for android
|
||||
System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver"); |
||||
|
||||
if (settings == null) |
||||
{ |
||||
settings = new AppSettings(true); |
||||
} |
||||
|
||||
// Use vertex arrays for rendering
|
||||
settings.putBoolean("USE_VA", true); |
||||
// Verbose logging off
|
||||
settings.putBoolean("VERBOSE_LOGGING", false); |
||||
|
||||
//re-setting settings they can have been merged from the registry.
|
||||
setSettings(settings); |
||||
super.start(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Retrieves guiNode |
||||
* @return guiNode Node object |
||||
* |
||||
*/ |
||||
public Node getGuiNode() { |
||||
return guiNode; |
||||
} |
||||
|
||||
/** |
||||
* Retrieves rootNode |
||||
* @return rootNode Node object |
||||
* |
||||
*/ |
||||
public Node getRootNode() { |
||||
return rootNode; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Attaches FPS statistics to guiNode and displays it on the screen. |
||||
* |
||||
*/ |
||||
public void loadFPSText() { |
||||
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); |
||||
fpsText = new BitmapText(guiFont, false); |
||||
fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0); |
||||
fpsText.setText("Frames per second"); |
||||
guiNode.attachChild(fpsText); |
||||
} |
||||
|
||||
@Override |
||||
public void initialize() |
||||
{ |
||||
// Create a default Android assetmanager before Application can create one in super.initialize();
|
||||
assetManager = JmeSystem.newAssetManager(null); |
||||
super.initialize(); |
||||
|
||||
guiNode.setQueueBucket(Bucket.Gui); |
||||
guiNode.setCullHint(CullHint.Never); |
||||
loadFPSText(); |
||||
viewPort.attachScene(rootNode); |
||||
guiViewPort.attachScene(guiNode); |
||||
|
||||
// call user code
|
||||
init(); |
||||
|
||||
// Start thread for async load
|
||||
Thread t = new Thread(new Runnable() |
||||
{ |
||||
@Override |
||||
public void run () |
||||
{ |
||||
try |
||||
{ |
||||
// call user code
|
||||
asyncload(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
handleError("AsyncLoad failed", e); |
||||
} |
||||
loadingFinished.set(true); |
||||
} |
||||
}); |
||||
t.setDaemon(true); |
||||
t.start(); |
||||
} |
||||
|
||||
@Override |
||||
public void update() { |
||||
super.update(); // makes sure to execute AppTasks
|
||||
if (speed == 0 || paused) { |
||||
return; |
||||
} |
||||
|
||||
float tpf = timer.getTimePerFrame() * speed; |
||||
|
||||
secondCounter += timer.getTimePerFrame(); |
||||
int fps = (int) timer.getFrameRate(); |
||||
if (secondCounter >= 5.0f) { |
||||
textBuf.clear(); |
||||
textBuf.put("Frames per second: "); |
||||
FastInteger.toCharArray(fps, fpsBuf); |
||||
textBuf.put(fpsBuf); |
||||
textBuf.flip(); |
||||
fpsText.setText(textBuf); |
||||
secondCounter = 0.0f; |
||||
} |
||||
|
||||
// update states
|
||||
stateManager.update(tpf); |
||||
|
||||
// simple update and root node
|
||||
update(tpf); |
||||
rootNode.updateLogicalState(tpf); |
||||
guiNode.updateLogicalState(tpf); |
||||
rootNode.updateGeometricState(); |
||||
guiNode.updateGeometricState(); |
||||
|
||||
// render states
|
||||
stateManager.render(renderManager); |
||||
renderManager.render(tpf); |
||||
render(renderManager); |
||||
stateManager.postRender(); |
||||
} |
||||
|
||||
public abstract void init(); |
||||
|
||||
public void update(float tpf) { |
||||
} |
||||
|
||||
public void render(RenderManager rm) { |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Gets called by a different thread to allow |
||||
* async loading of assets. |
||||
* |
||||
* This means that update and rendering can already |
||||
* happen while some assets are still loading. |
||||
*/ |
||||
public void asyncload() |
||||
{ |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Called when an error has occured. This is typically |
||||
* invoked when an uncought exception is thrown in the render thread. |
||||
* @param errorMsg The error message, if any, or null. |
||||
* @param t Throwable object, or null. |
||||
*/ |
||||
@Override |
||||
public void handleError(final String errorMsg, final Throwable t) |
||||
{ |
||||
|
||||
String s = ""; |
||||
if (t != null && t.getStackTrace() != null) |
||||
{ |
||||
for (StackTraceElement ste: t.getStackTrace()) |
||||
{ |
||||
s += ste.getClassName() + "." + ste.getMethodName() + "(" + + ste.getLineNumber() + ") "; |
||||
} |
||||
} |
||||
final String sTrace = s; |
||||
activity.runOnUiThread(new Runnable() { |
||||
@Override |
||||
public void run() |
||||
{ |
||||
AlertDialog dialog = new AlertDialog.Builder(activity) |
||||
// .setIcon(R.drawable.alert_dialog_icon)
|
||||
.setTitle(t != null ? t.toString() : "Failed") |
||||
.setPositiveButton("Kill", AndroidApplication.this) |
||||
.setMessage((errorMsg != null ? errorMsg + ": " : "") + sTrace) |
||||
.create(); |
||||
dialog.show(); |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Called by the android alert dialog, terminate the activity and OpenGL rendering |
||||
* @param dialog |
||||
* @param whichButton |
||||
*/ |
||||
public void onClick(DialogInterface dialog, int whichButton) |
||||
{ |
||||
this.stop(); |
||||
activity.finish(); |
||||
} |
||||
|
||||
} |
@ -1,269 +1,118 @@ |
||||
/* |
||||
* Copyright (c) 2009-2010 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
package com.jme3.asset; |
||||
|
||||
import com.jme3.asset.plugins.AndroidLocator; |
||||
import com.jme3.audio.AudioData; |
||||
import com.jme3.audio.AudioKey; |
||||
import com.jme3.export.binary.BinaryExporter; |
||||
import com.jme3.export.binary.BinaryImporter; |
||||
import com.jme3.font.BitmapFont; |
||||
import com.jme3.font.plugins.BitmapFontLoader; |
||||
import com.jme3.material.Material; |
||||
import com.jme3.material.plugins.J3MLoader; |
||||
import com.jme3.scene.Spatial; |
||||
import com.jme3.shader.Shader; |
||||
import com.jme3.shader.ShaderKey; |
||||
import com.jme3.shader.plugins.GLSLLoader; |
||||
import com.jme3.texture.Image; |
||||
import com.jme3.texture.Texture; |
||||
import com.jme3.texture.plugins.AndroidImageLoader; |
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
import java.util.HashMap; |
||||
import java.util.logging.Level; |
||||
import java.net.URL; |
||||
import java.util.logging.Logger; |
||||
|
||||
import com.jme3.asset.plugins.AndroidLocator; |
||||
import com.jme3.asset.plugins.ClasspathLocator; |
||||
|
||||
/** |
||||
* AssetManager for Android |
||||
* <code>AndroidAssetManager</code> is an implementation of DesktopAssetManager for Android |
||||
* |
||||
* @author Kirill Vainer |
||||
* @author larynx |
||||
*/ |
||||
public final class AndroidAssetManager implements AssetManager { |
||||
public class AndroidAssetManager extends DesktopAssetManager { |
||||
|
||||
private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName()); |
||||
|
||||
private final AndroidLocator locator = new AndroidLocator(); |
||||
private final AndroidImageLoader imageLoader = new AndroidImageLoader(); |
||||
private final BinaryImporter modelLoader = new BinaryImporter(); |
||||
private final BitmapFontLoader fontLoader = new BitmapFontLoader(); |
||||
private final J3MLoader j3mLoader = new J3MLoader(); |
||||
private final J3MLoader j3mdLoader = new J3MLoader(); |
||||
private final GLSLLoader glslLoader = new GLSLLoader(); |
||||
|
||||
private final BinaryExporter exporter = new BinaryExporter(); |
||||
private final HashMap<AssetKey, Object> cache = new HashMap<AssetKey, Object>(); |
||||
|
||||
public AndroidAssetManager(){ |
||||
this(false); |
||||
} |
||||
|
||||
public AndroidAssetManager(boolean loadDefaults){ |
||||
if (loadDefaults){ |
||||
// AssetConfig cfg = new AssetConfig(this);
|
||||
// InputStream stream = AssetManager.class.getResourceAsStream("Desktop.cfg");
|
||||
// try{
|
||||
// cfg.loadText(stream);
|
||||
// }catch (IOException ex){
|
||||
// logger.log(Level.SEVERE, "Failed to load asset config", ex);
|
||||
// }finally{
|
||||
// if (stream != null)
|
||||
// try{
|
||||
// stream.close();
|
||||
// }catch (IOException ex){
|
||||
// }
|
||||
// }
|
||||
this(null); |
||||
} |
||||
|
||||
@Deprecated |
||||
public AndroidAssetManager(boolean loadDefaults){ |
||||
//this(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Android.cfg"));
|
||||
this(null); |
||||
} |
||||
|
||||
/** |
||||
* AndroidAssetManager constructor |
||||
* If URL == null then a default list of locators and loaders for android is set |
||||
* @param configFile |
||||
*/ |
||||
public AndroidAssetManager(URL configFile) |
||||
{ |
||||
super(configFile); |
||||
System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver"); |
||||
|
||||
if (configFile == null) |
||||
{ |
||||
// Set Default
|
||||
this.registerLocator("", AndroidLocator.class); |
||||
this.registerLocator("", ClasspathLocator.class); |
||||
this.registerLoader(AndroidImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg"); |
||||
this.registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3m"); |
||||
this.registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3md"); |
||||
this.registerLoader(com.jme3.font.plugins.BitmapFontLoader.class, "fnt"); |
||||
this.registerLoader(com.jme3.texture.plugins.DDSLoader.class, "dds"); |
||||
this.registerLoader(com.jme3.texture.plugins.PFMLoader.class, "pfm"); |
||||
this.registerLoader(com.jme3.texture.plugins.HDRLoader.class, "hdr"); |
||||
this.registerLoader(com.jme3.texture.plugins.TGALoader.class, "tga"); |
||||
this.registerLoader(com.jme3.export.binary.BinaryImporter.class, "j3o"); |
||||
this.registerLoader(com.jme3.scene.plugins.OBJLoader.class, "obj"); |
||||
this.registerLoader(com.jme3.scene.plugins.MTLLoader.class, "mtl"); |
||||
this.registerLoader(com.jme3.scene.plugins.ogre.MeshLoader.class, "meshxml", "mesh.xml"); |
||||
this.registerLoader(com.jme3.scene.plugins.ogre.SkeletonLoader.class, "skeletonxml", "skeleton.xml"); |
||||
this.registerLoader(com.jme3.scene.plugins.ogre.MaterialLoader.class, "material"); |
||||
this.registerLoader(com.jme3.scene.plugins.ogre.SceneLoader.class, "scene"); |
||||
this.registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib"); |
||||
} |
||||
|
||||
logger.info("AndroidAssetManager created."); |
||||
} |
||||
|
||||
public void registerLoader(String loaderClass, String ... extensions){ |
||||
} |
||||
|
||||
public void registerLocator(String rootPath, String locatorClass, String ... extensions){ |
||||
} |
||||
|
||||
private Object tryLoadFromHD(AssetKey key){ |
||||
if (!key.getExtension().equals("fnt")) |
||||
return null; |
||||
|
||||
File f = new File("/sdcard/" + key.getName() + ".opt"); |
||||
if (!f.exists()) |
||||
return null; |
||||
|
||||
try { |
||||
InputStream stream = new FileInputStream(f); |
||||
BitmapFont font = (BitmapFont) modelLoader.load(stream, null, null); |
||||
stream.close(); |
||||
return font; |
||||
} catch (IOException ex){ |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
private void tryPutToHD(AssetKey key, Object data){ |
||||
if (!key.getExtension().equals("fnt")) |
||||
return; |
||||
|
||||
File f = new File("/sdcard/" + key.getName() + ".opt"); |
||||
|
||||
try { |
||||
BitmapFont font = (BitmapFont) data; |
||||
OutputStream stream = new FileOutputStream(f); |
||||
exporter.save(font, stream); |
||||
stream.close(); |
||||
} catch (IOException ex){ |
||||
} |
||||
} |
||||
|
||||
public Object loadAsset(AssetKey key){ |
||||
logger.info("loadAsset(" + key + ")"); |
||||
Object asset; |
||||
// Object asset = tryLoadFromHD(key);
|
||||
// if (asset != null)
|
||||
// return asset;
|
||||
|
||||
if (key.shouldCache()){ |
||||
asset = cache.get(key); |
||||
if (asset != null) |
||||
return key.createClonedInstance(asset); |
||||
} |
||||
// find resource
|
||||
AssetInfo info = locator.locate(this, key); |
||||
if (info == null){ |
||||
logger.log(Level.WARNING, "Cannot locate resource: "+key.getName()); |
||||
return null; |
||||
} |
||||
|
||||
String ex = key.getExtension(); |
||||
logger.log(Level.INFO, "Loading asset: "+key.getName()); |
||||
try{ |
||||
if (ex.equals("png") || ex.equals("jpg") |
||||
|| ex.equals("jpeg") || ex.equals("j3i")){ |
||||
Image image; |
||||
if (ex.equals("j3i")){ |
||||
image = (Image) modelLoader.load(info); |
||||
}else{ |
||||
image = (Image) imageLoader.load(info); |
||||
} |
||||
TextureKey tkey = (TextureKey) key; |
||||
asset = image; |
||||
Texture tex = (Texture) tkey.postProcess(asset); |
||||
tex.setMagFilter(Texture.MagFilter.Nearest); |
||||
tex.setAnisotropicFilter(0); |
||||
if (tex.getMinFilter().usesMipMapLevels()){ |
||||
tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap); |
||||
}else{ |
||||
tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps); |
||||
} |
||||
asset = tex; |
||||
}else if (ex.equals("j3o")){ |
||||
asset = modelLoader.load(info); |
||||
}else if (ex.equals("fnt")){ |
||||
asset = fontLoader.load(info); |
||||
}else if (ex.equals("j3md")){ |
||||
asset = j3mdLoader.load(info); |
||||
}else if (ex.equals("j3m")){ |
||||
asset = j3mLoader.load(info); |
||||
}else{ |
||||
logger.info("loading asset as glsl shader ..."); |
||||
asset = glslLoader.load(info); |
||||
// logger.log(Level.WARNING, "No loader registered for type: "+ex);
|
||||
// return null;
|
||||
} |
||||
|
||||
if (key.shouldCache()) |
||||
cache.put(key, asset); |
||||
|
||||
// tryPutToHD(key, asset);
|
||||
|
||||
return key.createClonedInstance(asset); |
||||
} catch (Exception e){ |
||||
logger.log(Level.WARNING, "Failed to load resource: "+key.getName(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public AssetInfo locateAsset(AssetKey<?> key){ |
||||
AssetInfo info = locator.locate(this, key); |
||||
if (info == null){ |
||||
logger.log(Level.WARNING, "Cannot locate resource: "+key.getName()); |
||||
return null; |
||||
} |
||||
return info; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
public Object loadAsset(String name) { |
||||
return loadAsset(new AssetKey(name)); |
||||
} |
||||
|
||||
public Spatial loadModel(String name) { |
||||
return (Spatial) loadAsset(name); |
||||
} |
||||
|
||||
public Material loadMaterial(String name) { |
||||
return (Material) loadAsset(name); |
||||
} |
||||
|
||||
public BitmapFont loadFont(String name){ |
||||
return (BitmapFont) loadAsset(name); |
||||
} |
||||
|
||||
/** |
||||
* Loads a texture. |
||||
* |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Texture loadTexture(TextureKey key){ |
||||
return (Texture) loadAsset(key); |
||||
} |
||||
|
||||
public Texture loadTexture(String name){ |
||||
return loadTexture(new TextureKey(name, false)); |
||||
} |
||||
|
||||
public Shader loadShader(ShaderKey key){ |
||||
logger.info("loadShader(" + key + ")"); |
||||
|
||||
String vertName = key.getVertName(); |
||||
String fragName = key.getFragName(); |
||||
|
||||
String vertSource = (String) loadAsset(new AssetKey(vertName)); |
||||
String fragSource = (String) loadAsset(new AssetKey(fragName)); |
||||
|
||||
Shader s = new Shader(key.getLanguage()); |
||||
s.addSource(Shader.ShaderType.Vertex, vertName, vertSource, key.getDefines().getCompiled()); |
||||
s.addSource(Shader.ShaderType.Fragment, fragName, fragSource, key.getDefines().getCompiled()); |
||||
|
||||
logger.info("returing shader: [" + s + "]"); |
||||
return s; |
||||
} |
||||
|
||||
|
||||
public void registerLocator(String rootPath, String locatorClassName) { |
||||
throw new UnsupportedOperationException("Not supported yet."); |
||||
} |
||||
|
||||
public AudioData loadAudio(AudioKey key) { |
||||
throw new UnsupportedOperationException("Not supported yet."); |
||||
} |
||||
|
||||
public AudioData loadAudio(String name) { |
||||
throw new UnsupportedOperationException("Not supported yet."); |
||||
} |
||||
|
||||
public Spatial loadModel(ModelKey key) { |
||||
throw new UnsupportedOperationException("Not supported yet."); |
||||
} |
||||
|
||||
/* new */ |
||||
|
||||
private AssetEventListener eventListener = null; |
||||
|
||||
public void setAssetEventListener(AssetEventListener listener){ |
||||
eventListener = listener; |
||||
} |
||||
|
||||
public void registerLocator(String rootPath, Class<? extends AssetLocator> locatorClass){ |
||||
logger.warning("not implemented."); |
||||
} |
||||
|
||||
public void registerLoader(Class<? extends AssetLoader> loader, String ... extensions){ |
||||
logger.warning("not implemented."); |
||||
Texture tex = (Texture) loadAsset(key); |
||||
|
||||
// Needed for Android
|
||||
tex.setMagFilter(Texture.MagFilter.Nearest); |
||||
tex.setAnisotropicFilter(0); |
||||
if (tex.getMinFilter().usesMipMapLevels()){ |
||||
tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap); |
||||
}else{ |
||||
tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps); |
||||
} |
||||
return tex; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,19 @@ |
||||
package com.jme3.input.android; |
||||
|
||||
import com.jme3.input.RawInputListener; |
||||
|
||||
import android.view.KeyEvent; |
||||
import android.view.MotionEvent; |
||||
|
||||
/** |
||||
* AndroidTouchInputListener is an inputlistener interface which defines callbacks/events for android touch screens |
||||
* For use with class AndroidInput |
||||
* @author larynx |
||||
* |
||||
*/ |
||||
public interface AndroidTouchInputListener extends RawInputListener |
||||
{ |
||||
public void onTouchEvent(TouchEvent evt); |
||||
public void onMotionEvent(MotionEvent evt); |
||||
public void onAndroidKeyEvent(KeyEvent evt); |
||||
} |
@ -0,0 +1,359 @@ |
||||
package com.jme3.util; |
||||
|
||||
|
||||
/** |
||||
* The wrapper for the primitive type {@code int}. |
||||
* <p> |
||||
* As with the specification, this implementation relies on code laid out in <a |
||||
* href="http://www.hackersdelight.org/">Henry S. Warren, Jr.'s Hacker's |
||||
* Delight, (Addison Wesley, 2002)</a> as well as <a |
||||
* href="http://aggregate.org/MAGIC/">The Aggregate's Magic Algorithms</a>. |
||||
* |
||||
* @see java.lang.Number |
||||
* @since 1.1 |
||||
*/ |
||||
public final class FastInteger { |
||||
|
||||
/** |
||||
* Constant for the maximum {@code int} value, 2<sup>31</sup>-1. |
||||
*/ |
||||
public static final int MAX_VALUE = 0x7FFFFFFF; |
||||
|
||||
/** |
||||
* Constant for the minimum {@code int} value, -2<sup>31</sup>. |
||||
*/ |
||||
public static final int MIN_VALUE = 0x80000000; |
||||
|
||||
/** |
||||
* Constant for the number of bits needed to represent an {@code int} in |
||||
* two's complement form. |
||||
* |
||||
* @since 1.5 |
||||
*/ |
||||
public static final int SIZE = 32; |
||||
|
||||
/* |
||||
* Progressively smaller decimal order of magnitude that can be represented |
||||
* by an instance of Integer. Used to help compute the String |
||||
* representation. |
||||
*/ |
||||
private static final int[] decimalScale = new int[] { 1000000000, 100000000, |
||||
10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 }; |
||||
|
||||
/** |
||||
* Converts the specified integer into its decimal string representation. |
||||
* The returned string is a concatenation of a minus sign if the number is |
||||
* negative and characters from '0' to '9'. |
||||
* |
||||
* @param value |
||||
* the integer to convert. |
||||
* @return the decimal string representation of {@code value}. |
||||
*/ |
||||
public static boolean toCharArray(int value, char[] output) { |
||||
if (value == 0) |
||||
{ |
||||
output[0] = '0'; |
||||
output[1] = 0; |
||||
return true; |
||||
} |
||||
|
||||
// Faster algorithm for smaller Integers
|
||||
if (value < 1000 && value > -1000) { |
||||
|
||||
int positive_value = value < 0 ? -value : value; |
||||
int first_digit = 0; |
||||
if (value < 0) { |
||||
output[0] = '-'; |
||||
first_digit++; |
||||
} |
||||
int last_digit = first_digit; |
||||
int quot = positive_value; |
||||
do { |
||||
int res = quot / 10; |
||||
int digit_value = quot - ((res << 3) + (res << 1)); |
||||
digit_value += '0'; |
||||
output[last_digit++] = (char) digit_value; |
||||
quot = res; |
||||
} while (quot != 0); |
||||
|
||||
int count = last_digit--; |
||||
do { |
||||
char tmp = output[last_digit]; |
||||
output[last_digit--] = output[first_digit]; |
||||
output[first_digit++] = tmp; |
||||
} while (first_digit < last_digit); |
||||
output[count] = 0; |
||||
return true; |
||||
} |
||||
if (value == MIN_VALUE) { |
||||
System.arraycopy("-2147483648".toCharArray(), 0, output, 0, 12); |
||||
output[12] = 0; |
||||
return true; |
||||
} |
||||
|
||||
|
||||
int positive_value = value < 0 ? -value : value; |
||||
byte first_digit = 0; |
||||
if (value < 0) { |
||||
output[0] = '-'; |
||||
first_digit++; |
||||
} |
||||
byte last_digit = first_digit; |
||||
byte count; |
||||
int number; |
||||
boolean start = false; |
||||
for (int i = 0; i < 9; i++) { |
||||
count = 0; |
||||
if (positive_value < (number = decimalScale[i])) { |
||||
if (start) { |
||||
output[last_digit++] = '0'; |
||||
} |
||||
continue; |
||||
} |
||||
|
||||
if (i > 0) { |
||||
number = (decimalScale[i] << 3); |
||||
if (positive_value >= number) { |
||||
positive_value -= number; |
||||
count += 8; |
||||
} |
||||
number = (decimalScale[i] << 2); |
||||
if (positive_value >= number) { |
||||
positive_value -= number; |
||||
count += 4; |
||||
} |
||||
} |
||||
number = (decimalScale[i] << 1); |
||||
if (positive_value >= number) { |
||||
positive_value -= number; |
||||
count += 2; |
||||
} |
||||
if (positive_value >= decimalScale[i]) { |
||||
positive_value -= decimalScale[i]; |
||||
count++; |
||||
} |
||||
if (count > 0 && !start) { |
||||
start = true; |
||||
} |
||||
if (start) { |
||||
output[last_digit++] = (char) (count + '0'); |
||||
} |
||||
} |
||||
|
||||
output[last_digit++] = (char) (positive_value + '0'); |
||||
output[last_digit] = 0; |
||||
count = last_digit--; |
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Determines the highest (leftmost) bit of the specified integer that is 1 |
||||
* and returns the bit mask value for that bit. This is also referred to as |
||||
* the Most Significant 1 Bit. Returns zero if the specified integer is |
||||
* zero. |
||||
* |
||||
* @param i |
||||
* the integer to examine. |
||||
* @return the bit mask indicating the highest 1 bit in {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int highestOneBit(int i) { |
||||
i |= (i >> 1); |
||||
i |= (i >> 2); |
||||
i |= (i >> 4); |
||||
i |= (i >> 8); |
||||
i |= (i >> 16); |
||||
return (i & ~(i >>> 1)); |
||||
} |
||||
|
||||
/** |
||||
* Determines the lowest (rightmost) bit of the specified integer that is 1 |
||||
* and returns the bit mask value for that bit. This is also referred |
||||
* to as the Least Significant 1 Bit. Returns zero if the specified integer |
||||
* is zero. |
||||
* |
||||
* @param i |
||||
* the integer to examine. |
||||
* @return the bit mask indicating the lowest 1 bit in {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int lowestOneBit(int i) { |
||||
return (i & (-i)); |
||||
} |
||||
|
||||
/** |
||||
* Determines the number of leading zeros in the specified integer prior to |
||||
* the {@link #highestOneBit(int) highest one bit}. |
||||
* |
||||
* @param i |
||||
* the integer to examine. |
||||
* @return the number of leading zeros in {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int numberOfLeadingZeros(int i) { |
||||
i |= i >> 1; |
||||
i |= i >> 2; |
||||
i |= i >> 4; |
||||
i |= i >> 8; |
||||
i |= i >> 16; |
||||
return bitCount(~i); |
||||
} |
||||
|
||||
/** |
||||
* Determines the number of trailing zeros in the specified integer after |
||||
* the {@link #lowestOneBit(int) lowest one bit}. |
||||
* |
||||
* @param i |
||||
* the integer to examine. |
||||
* @return the number of trailing zeros in {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int numberOfTrailingZeros(int i) { |
||||
return bitCount((i & -i) - 1); |
||||
} |
||||
|
||||
/** |
||||
* Counts the number of 1 bits in the specified integer; this is also |
||||
* referred to as population count. |
||||
* |
||||
* @param i |
||||
* the integer to examine. |
||||
* @return the number of 1 bits in {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int bitCount(int i) { |
||||
i -= ((i >> 1) & 0x55555555); |
||||
i = (i & 0x33333333) + ((i >> 2) & 0x33333333); |
||||
i = (((i >> 4) + i) & 0x0F0F0F0F); |
||||
i += (i >> 8); |
||||
i += (i >> 16); |
||||
return (i & 0x0000003F); |
||||
} |
||||
|
||||
/** |
||||
* Rotates the bits of the specified integer to the left by the specified |
||||
* number of bits. |
||||
* |
||||
* @param i |
||||
* the integer value to rotate left. |
||||
* @param distance |
||||
* the number of bits to rotate. |
||||
* @return the rotated value. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int rotateLeft(int i, int distance) { |
||||
if (distance == 0) { |
||||
return i; |
||||
} |
||||
/* |
||||
* According to JLS3, 15.19, the right operand of a shift is always |
||||
* implicitly masked with 0x1F, which the negation of 'distance' is |
||||
* taking advantage of. |
||||
*/ |
||||
return ((i << distance) | (i >>> (-distance))); |
||||
} |
||||
|
||||
/** |
||||
* Rotates the bits of the specified integer to the right by the specified |
||||
* number of bits. |
||||
* |
||||
* @param i |
||||
* the integer value to rotate right. |
||||
* @param distance |
||||
* the number of bits to rotate. |
||||
* @return the rotated value. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int rotateRight(int i, int distance) { |
||||
if (distance == 0) { |
||||
return i; |
||||
} |
||||
/* |
||||
* According to JLS3, 15.19, the right operand of a shift is always |
||||
* implicitly masked with 0x1F, which the negation of 'distance' is |
||||
* taking advantage of. |
||||
*/ |
||||
return ((i >>> distance) | (i << (-distance))); |
||||
} |
||||
|
||||
/** |
||||
* Reverses the order of the bytes of the specified integer. |
||||
* |
||||
* @param i |
||||
* the integer value for which to reverse the byte order. |
||||
* @return the reversed value. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int reverseBytes(int i) { |
||||
int b3 = i >>> 24; |
||||
int b2 = (i >>> 8) & 0xFF00; |
||||
int b1 = (i & 0xFF00) << 8; |
||||
int b0 = i << 24; |
||||
return (b0 | b1 | b2 | b3); |
||||
} |
||||
|
||||
/** |
||||
* Reverses the order of the bits of the specified integer. |
||||
* |
||||
* @param i |
||||
* the integer value for which to reverse the bit order. |
||||
* @return the reversed value. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int reverse(int i) { |
||||
// From Hacker's Delight, 7-1, Figure 7-1
|
||||
i = (i & 0x55555555) << 1 | (i >> 1) & 0x55555555; |
||||
i = (i & 0x33333333) << 2 | (i >> 2) & 0x33333333; |
||||
i = (i & 0x0F0F0F0F) << 4 | (i >> 4) & 0x0F0F0F0F; |
||||
return reverseBytes(i); |
||||
} |
||||
|
||||
/** |
||||
* Returns the value of the {@code signum} function for the specified |
||||
* integer. |
||||
* |
||||
* @param i |
||||
* the integer value to check. |
||||
* @return -1 if {@code i} is negative, 1 if {@code i} is positive, 0 if |
||||
* {@code i} is zero. |
||||
* @since 1.5 |
||||
*/ |
||||
public static int signum(int i) { |
||||
return (i == 0 ? 0 : (i < 0 ? -1 : 1)); |
||||
} |
||||
|
||||
/** |
||||
* Returns a {@code Integer} instance for the specified integer value. |
||||
* <p> |
||||
* If it is not necessary to get a new {@code Integer} instance, it is |
||||
* recommended to use this method instead of the constructor, since it |
||||
* maintains a cache of instances which may result in better performance. |
||||
* |
||||
* @param i |
||||
* the integer value to store in the instance. |
||||
* @return a {@code Integer} instance containing {@code i}. |
||||
* @since 1.5 |
||||
*/ |
||||
public static Integer valueOf(int i) { |
||||
if (i < -128 || i > 127) { |
||||
return new Integer(i); |
||||
} |
||||
return valueOfCache.CACHE [i+128]; |
||||
|
||||
} |
||||
|
||||
static class valueOfCache { |
||||
/** |
||||
* <p> |
||||
* A cache of instances used by {@link Integer#valueOf(int)} and auto-boxing. |
||||
*/ |
||||
static final Integer[] CACHE = new Integer[256]; |
||||
|
||||
static { |
||||
for(int i=-128; i<=127; i++) { |
||||
CACHE[i+128] = new Integer(i); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue