diff options
| author | Ryan Houdek <Sonicadvance1@gmail.com> | 2013-04-14 20:39:56 -0500 |
|---|---|---|
| committer | Ryan Houdek <Sonicadvance1@gmail.com> | 2013-04-14 20:39:56 -0500 |
| commit | bde7ea00ef9fd625a4e453ee9598fc20382a35a5 (patch) | |
| tree | b10963f47cc025adc892393f7537890fc8c46954 /Source/Android/src | |
| parent | 24347e51769b941c4bb1d070bfcd270209486b5a (diff) | |
Removes the Java ButtonManager for one in the C++ source so the OSD class can call in to it each frame for drawing the buttons. Copy our assets to the dolphin-emu directory for now. Remove NativeRenderer, ButtonManager, and Button Java classes since they aren't used anymore. Buttons A, B, and Start all work and are drawn on screen now. Button input on Android is still a bit hacky, needs a proper controller interface still. Android specific button drawing code is still hanging out in SWRenderer.cpp
Diffstat (limited to 'Source/Android/src')
5 files changed, 68 insertions, 262 deletions
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/Button.java b/Source/Android/src/org/dolphinemu/dolphinemu/Button.java deleted file mode 100644 index 629e572d83..0000000000 --- a/Source/Android/src/org/dolphinemu/dolphinemu/Button.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.dolphinemu.dolphinemu; - -public class Button { - private String ButtonID; - private float _x; - private float _y; - private float _ex; - private float _ey; - public Button(String Button, float[] Coords) - { - ButtonID = Button; - _x = Coords[0]; - _y = Coords[1]; - _ex = Coords[4]; - _ey = Coords[5]; - } - public float X() - { - return _x; - } - public float Y() - { - return _y; - } - public float EX() - { - return _ex; - } - public float EY() - { - return _ey; - } -} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/ButtonManager.java b/Source/Android/src/org/dolphinemu/dolphinemu/ButtonManager.java deleted file mode 100644 index ee7a8f79d0..0000000000 --- a/Source/Android/src/org/dolphinemu/dolphinemu/ButtonManager.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.dolphinemu.dolphinemu; - -public class ButtonManager { - - private final int NUMBUTTONS = 15; - - Button[] Buttons; - float[][] ButtonCoords = - { // X, Y, X, EY, EX, EY, EX, Y - {0.75f, -1.0f, 0.75f, -0.75f, 1.0f, -0.75f, 1.0f, -1.0f}, - {0.50f, -1.0f, 0.50f, -0.75f, 0.75f, -0.75f, 0.75f, -1.0f}, - }; - public ButtonManager() - { - Buttons = new Button[NUMBUTTONS]; - - Buttons[0] = new Button("A", ButtonCoords[0]); - Buttons[1] = new Button("B", ButtonCoords[1]); - - } - Button GetButton(int ID) - { - return Buttons[ID]; - } - float[][] GetButtonCoords() - { - return ButtonCoords; - } - public int ButtonPressed(int action, float x, float y) - { - for (int a = 0; a < 2; ++a) - { - if (x >= Buttons[a].X() && - x <= Buttons[a].EX() && - -y >= Buttons[a].Y() && - -y <= Buttons[a].EY()) - { - return a; - } - } - return -1; - } -} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java index 249ec33703..5c79ab94fd 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java @@ -1,29 +1,29 @@ package org.dolphinemu.dolphinemu; -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import android.app.Activity; import android.content.Intent; -import android.content.res.Configuration; -import android.opengl.GLSurfaceView; import android.os.Bundle; +import android.os.Environment; import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; import android.view.WindowManager; -public class DolphinEmulator<MainActivity> extends Activity { - +public class DolphinEmulator<MainActivity> extends Activity +{ static private NativeGLSurfaceView GLview = null; static private boolean Running = false; private float screenWidth; private float screenHeight; - public static native void SetKey(int Value, int Key); + public static native void onTouchEvent(int Action, float X, float Y); static { @@ -36,6 +36,29 @@ public class DolphinEmulator<MainActivity> extends Activity { Log.w("me", ex.toString()); } } + private void CopyAsset(String asset, String output) { + InputStream in = null; + OutputStream out = null; + try { + in = getAssets().open(asset); + out = new FileOutputStream(output); + copyFile(in, out); + in.close(); + in = null; + out.flush(); + out.close(); + out = null; + } catch(IOException e) { + Log.e("tag", "Failed to copy asset file: " + asset, e); + } + } + private void copyFile(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + int read; + while((read = in.read(buffer)) != -1){ + out.write(buffer, 0, read); + } + } @Override public void onStop() { @@ -67,6 +90,30 @@ public class DolphinEmulator<MainActivity> extends Activity { { Intent ListIntent = new Intent(this, NativeListView.class); startActivityForResult(ListIntent, 1); + + // Make the assets directory + try + { + File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu"); + directory.mkdirs(); + } + catch (Exception ex) + { + Log.w("me", ex.toString()); + } + + // Copy assets if needed + java.io.File file = new java.io.File( + Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonStart.png"); + if(!file.exists()) + { + CopyAsset("ButtonA.png", + Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonA.png"); + CopyAsset("ButtonB.png", + Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonB.png"); + CopyAsset("ButtonStart.png", + Environment.getExternalStorageDirectory()+File.separator+"dolphin-emu" + File.separator + "ButtonStart.png"); + } } } @@ -85,7 +132,7 @@ public class DolphinEmulator<MainActivity> extends Activity { String FileName = data.getStringExtra("Select"); GLview = new NativeGLSurfaceView(this); - + //this.getWindow().setUiOptions(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); GLview.SetDimensions(screenWidth, screenHeight); GLview.SetFileName(FileName); setContentView(GLview); @@ -102,10 +149,11 @@ public class DolphinEmulator<MainActivity> extends Activity { Y = event.getY(); Action = event.getActionMasked(); - //int Button = Renderer.ButtonPressed(Action, ((X / screenWidth) * 2.0f) - 1.0f, ((Y / screenHeight) * 2.0f) - 1.0f); - - //if (Button != -1) - //SetKey(Action, Button); + // Converts button locations 0 - 1 to OGL screen coords -1.0 - 1.0 + float ScreenX = ((X / screenWidth) * 2.0f) - 1.0f; + float ScreenY = ((Y / screenHeight) * -2.0f) + 1.0f; + + onTouchEvent(Action, ScreenX, ScreenY); return false; } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java index 22cba8a4e9..25c7ace0a0 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java @@ -16,7 +16,6 @@ public class NativeGLSurfaceView extends SurfaceView { static private float height; public static native void main(String File, Surface surf, int width, int height); - public static native void UnPauseEmulation(); public static native void PauseEmulation(); public static native void StopEmulation(); @@ -32,7 +31,6 @@ public class NativeGLSurfaceView extends SurfaceView { Log.w("me", ex.toString()); } } - public NativeGLSurfaceView(Context context) { super(context); @@ -46,11 +44,13 @@ public class NativeGLSurfaceView extends SurfaceView { } }; getHolder().addCallback(new SurfaceHolder.Callback() { - - public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub - myRun.start(); + if (!Running) + { + myRun.start(); + Running = true; + } } public void surfaceChanged(SurfaceHolder arg0, int arg1, @@ -72,11 +72,10 @@ public class NativeGLSurfaceView extends SurfaceView { { FileName = file; } + public void SetDimensions(float screenWidth, float screenHeight) { width = screenWidth; height = screenHeight; } - - } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java deleted file mode 100644 index 031d9aff17..0000000000 --- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.dolphinemu.dolphinemu; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLES20; -import android.opengl.GLSurfaceView; -import android.opengl.GLUtils; -import android.util.Log; - -public class NativeRenderer implements GLSurfaceView.Renderer { - // Button Manager - private static ButtonManager Buttons; - - private static boolean Running = false; - - // Context - private static Context _gContext; - - // Native - public static native void DrawME(); - public static native void DrawButton(int GLTex, int ID); - public static native void SetButtonCoords(float[] Coords); - public static native void PrepareME(); - - // Texture loading - private static int buttonA = -1; - private static int buttonB = -1; - - // Get a new texture id: - private static int newTextureID(GL10 gl) - { - int[] temp = new int[1]; - gl.glGenTextures(1, temp, 0); - return temp[0]; - } - - // Will load a texture out of a drawable resource file, and return an OpenGL texture ID: - private int loadTexture(GL10 gl, String resource) - { - // In which ID will we be storing this texture? - int id = newTextureID(gl); - - // Load up, and flip the texture: - InputStream File = null; - try { - File = _gContext.getAssets().open(resource); - } - catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - return 0; - } - - Bitmap bmp = BitmapFactory.decodeStream(File); - - gl.glBindTexture(GL10.GL_TEXTURE_2D, id); - - // Set all of our texture parameters: - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); - - // Generate, and load up all of the mipmaps: - for(int level=0, height = bmp.getHeight(), width = bmp.getWidth(); true; level++) - { - // Push the bitmap onto the GPU: - GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0); - - // We need to stop when the texture is 1x1: - if(height==1 && width==1) break; - - // Resize, and let's go again: - width >>= 1; height >>= 1; - if(width<1) width = 1; - if(height<1) height = 1; - - Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true); - bmp.recycle(); - bmp = bmp2; - } - bmp.recycle(); - - return id; - } - - static - { - try - { - System.loadLibrary("dolphin-emu-nogui"); - } - catch (Exception ex) - { - Log.w("me", ex.toString()); - } - if (!Running) - Buttons = new ButtonManager(); - } - - public void onSurfaceChanged(GL10 gl, int width, int height) - { - gl.glViewport(0, 0, width, height); - } - - public void onSurfaceCreated(GL10 gl, EGLConfig config) - { - if (!Running) - { - gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - gl.glEnable(GL10.GL_BLEND); - gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); - - buttonA = loadTexture(gl, "ButtonA.png"); - buttonB = loadTexture(gl, "ButtonB.png"); - SetButtonCoords(Flatten(Buttons.GetButtonCoords())); - PrepareME(); - Running = true; - } - } - public static float[] Flatten(float[][] data) { - - float[] list = new float[data.length * data[0].length]; - - for(int y = 0; y < data.length; ++y) - for (int x = 0; x < data[y].length; ++x) - list[y * data[0].length + x] = data[y][x]; - return list; - } - public void onDrawFrame(GL10 gl) - { - if (Running) - { - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - DrawME(); - - // -1 is left - // -1 is bottom - - DrawButton(buttonA, 0); - DrawButton(buttonB, 1); - } - } - public void setContext(Context ctx) - { - _gContext = ctx; - } - public int ButtonPressed(int action, float x, float y) - { - return Buttons.ButtonPressed(action, x, y); - } -} |
