From 46015b9dc8ae35fac72da3ddb1f914f78c759051 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 10 Feb 2013 12:44:00 +0000 Subject: [PATCH] catch up --- jni/android_api.cpp | 169 +----------------- jni/android_api.h | 21 +-- jni/main_code.cpp | 26 --- jni/main_code.h | 11 +- .../doublehitballs/GL2JNIActivity.java | 114 ++---------- src/fishrungames/doublehitballs/GLView.java | 10 +- .../doublehitballs/JniWrapper.java | 11 +- 7 files changed, 31 insertions(+), 331 deletions(-) diff --git a/jni/android_api.cpp b/jni/android_api.cpp index 900eb3b..bab2d1e 100644 --- a/jni/android_api.cpp +++ b/jni/android_api.cpp @@ -2,176 +2,9 @@ #include "main_code.h" -boost::shared_ptr App(new TAndroidApplication); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height) { - try - { - App->OuterInit(width, height, 480.f, 320.f); - } - catch (ErrorCommon e) - { - throw; - } + JniInitApp(width, height, 480.f, 320.f); } -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_StopSounds(JNIEnv * env, jobject obj) -{ - try - { - App->OuterDeinit(); //Clean up what is left at previous launch (if applicable) - } - catch (ErrorCommon e) - { - throw; - } -} - - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Update(JNIEnv * env, jobject obj, long dt) -{ - try - { - - if (!App->IsInited()) - { - return; - } - App->OuterDraw(); - App->OuterUpdate(dt); - - } - catch (ErrorCommon e) - { - throw; - } -} - -JNIEXPORT int JNICALL Java_fishrungames_doublehitballs_JniWrapper_IsInited(JNIEnv * env, jobject obj) -{ - try - { - if (App->IsInited()) - { - return 1; - } - else - { - return 0; - } - - } - catch (ErrorCommon e) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Destroy(JNIEnv * env, jobject obj) -{ - try - { - *Console<<"Destroy!!!\n"; - } - catch (ErrorCommon e) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, float x, float y, long time) -{ - try - { - if (!App->IsInited()) - { - return; - } - - x = x * 480.f / Renderer->GetScreenWidth(); - y = y * 320.f / Renderer->GetScreenHeight(); - - //*Console<<"Tap down "<GetScreenHeight())<<" "<IsInited()) - { - return; - } - - x = x * 480.f / Renderer->GetScreenWidth(); - y = y * 320.f / Renderer->GetScreenHeight(); - - OnTapUpSignal(vec2(x, y)); - - } - catch (ErrorCommon e) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time) -{ -} - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time) -{ - - try - { - - if (!App->IsInited()) - { - return; - } - - velocityX = velocityX * 480.f / Renderer->GetScreenWidth(); - velocityY = velocityY * 320.f / Renderer->GetScreenHeight(); - - OnFlingSignal(vec2(velocityX, velocityY)); - - } - catch (ErrorCommon e) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time) -{ - try - { - if (!App->IsInited()) - { - return; - } - - distanceX = distanceX * 480.f / Renderer->GetScreenWidth(); - distanceY = distanceY * 320.f / Renderer->GetScreenHeight(); - OnScrollSignal(vec2(distanceX, distanceY)); - - } - catch (ErrorCommon e) - { - throw; - } - -} diff --git a/jni/android_api.h b/jni/android_api.h index 9e7395e..f0e87ae 100644 --- a/jni/android_api.h +++ b/jni/android_api.h @@ -10,24 +10,15 @@ #include "boost/shared_ptr.hpp" +#include "main_code.h" + +#include "include/Engine.h" + using namespace SE; - -class TAndroidApplication; -extern boost::shared_ptr App; - - -extern "C" { +extern "C" +{ JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_StopSounds(JNIEnv * env, jobject obj); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Update(JNIEnv * env, jobject obj, long dt); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Destroy(JNIEnv * env, jobject obj); - JNIEXPORT int JNICALL Java_fishrungames_doublehitballs_JniWrapper_IsInited(JNIEnv * env, jobject obj); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time); - JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time); }; diff --git a/jni/main_code.cpp b/jni/main_code.cpp index 8019bc7..5c06b18 100644 --- a/jni/main_code.cpp +++ b/jni/main_code.cpp @@ -127,8 +127,6 @@ void TAndroidApplication::InnerDeinit() } -#ifdef TARGET_WIN32 - void TAndroidApplication::InnerOnTapDown(vec2 p) { OnTapDownSignal(vec2(p.v[0], p.v[1])); @@ -148,30 +146,6 @@ void TAndroidApplication::OnFling(vec2 v) { } -#endif - -#ifdef TARGET_IOS - -void TAndroidApplication::InnerOnTapDown(vec2 p) -{ - OnTapDownSignal(vec2(p.v[0], p.v[1])); -} - -void TAndroidApplication::InnerOnTapUp(vec2 p) -{ - OnTapUpSignal(vec2(p.v[0], p.v[1])); -} - -void TAndroidApplication::InnerOnMove(vec2 shift) -{ - OnScrollSignal(shift); -} - -void TAndroidApplication::OnFling(vec2 v) -{ -} - -#endif void TAndroidApplication::ApplySignalsToMenu() { diff --git a/jni/main_code.h b/jni/main_code.h index 8ec5933..cf95069 100644 --- a/jni/main_code.h +++ b/jni/main_code.h @@ -1,5 +1,5 @@ -#ifndef GL_CODE_H_INCLUDED -#define GL_CODE_H_INCLUDED +#ifndef MAIN_CODE_H_INCLUDED +#define MAIN_CODE_H_INCLUDED #ifdef TARGET_ANDROID #include "android_api.h" @@ -32,10 +32,6 @@ using namespace SE; -class TAndroidApplication; -extern TAndroidApplication* Application; - - extern boost::signal OnTapUpSignal; extern boost::signal OnTapDownSignal; extern boost::signal OnFlingSignal; @@ -150,5 +146,8 @@ public: }; +extern TAndroidApplication* Application; + + #endif diff --git a/src/fishrungames/doublehitballs/GL2JNIActivity.java b/src/fishrungames/doublehitballs/GL2JNIActivity.java index 8c49f27..5ae46e0 100644 --- a/src/fishrungames/doublehitballs/GL2JNIActivity.java +++ b/src/fishrungames/doublehitballs/GL2JNIActivity.java @@ -1,6 +1,6 @@ package fishrungames.doublehitballs; -import fishrungames.engine.FileWrapper; +import fishrungames.engine.EngineWrapper; //Deprecated //import fishrungames.doublehitballs.R; @@ -11,6 +11,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.view.GestureDetector; +import android.view.KeyEvent; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; @@ -23,40 +24,15 @@ public class GL2JNIActivity extends Activity GLView mView; - boolean IsScrolling = false; - - private GestureDetector gestureDetector; - @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - gestureDetector = new GestureDetector(new MyGestureListener()); - - FileWrapper.LoadHalibutEngineLibrary(); - FileWrapper.SetActivityInstance(this); - FileWrapper.SetupEnviroment(); - /* - * Deprecated - try - - { - for (Field f : R.raw.class.getFields()) - { - FileWrapper.AddToFileMap(f.getName(), f.getInt(null)); - } - - } catch (IllegalArgumentException e) - { - FileWrapper.ConsoleOut("IllegalArgumentException\n"); - onStop(); - } catch (IllegalAccessException e) - { - FileWrapper.ConsoleOut("IllegalAccessException\n"); - onStop(); - }*/ + EngineWrapper.LoadSalmonEngineLibrary(); + EngineWrapper.SetActivityInstance(this); + EngineWrapper.SetupEnviroment(); String apkFilePath = null; ApplicationInfo appInfo = null; @@ -66,23 +42,25 @@ public class GL2JNIActivity extends Activity } catch (NameNotFoundException e) { e.printStackTrace(); + throw new RuntimeException("Unable to locate assets, aborting..."); } apkFilePath = appInfo.sourceDir; - FileWrapper.SetupApkFilePath(apkFilePath); + EngineWrapper.SetupApkFilePath(apkFilePath); mView = new GLView(getApplication()); setContentView(mView); + EngineWrapper.SetView(mView); + } @Override protected void onPause() { - FileWrapper.ConsoleOut("OnPause\n"); - JniWrapper.StopSounds(); + EngineWrapper.CallDestroy(); super.onPause(); mView.onPause(); } @@ -97,82 +75,18 @@ public class GL2JNIActivity extends Activity @Override protected void onStop() { - - //FileWrapper.ConsoleOut("OnStop\n"); - //StopSounds(); super.onStop(); } public boolean onTouchEvent (MotionEvent event) { - if (gestureDetector.onTouchEvent(event)) - { - return true; - } - - /* - if (event.getAction() == MotionEvent.ACTION_MOVE) - { - float x = event.getX(); - float y = (float)mView.getHeight()-event.getY(); - - - - float shiftX = x - event.getHistoricalX(0, event.getHistorySize()-2); - - if(IsScrolling) - { - IsScrolling = false; - } - - JniWrapper.OnScroll(x, y, event.getEventTime()); - - }*/ - - - if (event.getAction() == MotionEvent.ACTION_UP) - { - float x = event.getX(); - float y = (float)mView.getHeight()-event.getY(); - - if(IsScrolling) - { - IsScrolling = false; - } - - JniWrapper.OnTapUp(x, y, event.getEventTime()); - - } + EngineWrapper.ProcessTouchEvent(event); return true; } - class MyGestureListener extends SimpleOnGestureListener + public boolean onKeyDown(int keyCode, KeyEvent event) { - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) - { - JniWrapper.OnFling(velocityX, velocityY, e2.getEventTime()); - return true; - } - - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) - { - JniWrapper.OnScroll(distanceX, distanceY, e2.getEventTime()); - IsScrolling = true; - return true; - } - - public boolean onDown(MotionEvent event) - { - - float x = event.getX(); - float y = (float)mView.getHeight()-event.getY(); - - JniWrapper.OnTapDown(x, y, event.getEventTime()); - - return true; - } - + EngineWrapper.ProcessKeyDown(keyCode, event); + return super.onKeyDown(keyCode, event); } - } \ No newline at end of file diff --git a/src/fishrungames/doublehitballs/GLView.java b/src/fishrungames/doublehitballs/GLView.java index d56efea..0e07f13 100644 --- a/src/fishrungames/doublehitballs/GLView.java +++ b/src/fishrungames/doublehitballs/GLView.java @@ -11,6 +11,8 @@ import javax.microedition.khronos.opengles.GL10; import fishrungames.engine.GLViewAncestor; +import fishrungames.engine.EngineWrapper; + class GLView extends GLViewAncestor { static long lastTimeStamp; @@ -49,7 +51,7 @@ class GLView extends GLViewAncestor long currentTimeStamp = c.getTimeInMillis(); - JniWrapper.Update(currentTimeStamp - lastTimeStamp); + EngineWrapper.Update(currentTimeStamp - lastTimeStamp); lastTimeStamp = currentTimeStamp; } @@ -57,13 +59,9 @@ class GLView extends GLViewAncestor public void onSurfaceChanged(GL10 gl, int width, int height) { - if (JniWrapper.IsInited() == 1) - { - JniWrapper.Destroy(); - } JniWrapper.Init(width,height); } - + public void onSurfaceCreated(GL10 gl, EGLConfig config) { //Do nothing. diff --git a/src/fishrungames/doublehitballs/JniWrapper.java b/src/fishrungames/doublehitballs/JniWrapper.java index 7c7dd5c..30fea95 100644 --- a/src/fishrungames/doublehitballs/JniWrapper.java +++ b/src/fishrungames/doublehitballs/JniWrapper.java @@ -8,14 +8,5 @@ public class JniWrapper public static native void Init(int width, int height); - public static native void Update(long dt); - public static native void StopSounds(); - public static native void Destroy(); - public static native int IsInited(); - public static native void OnTapDown(float x, float y, long time); - public static native void OnTapUp(float x, float y, long time); - public static native void OnTapMove(float x, float y, long time); - - public static native void OnFling(float velocityX, float velocityY, long time); - public static native void OnScroll(float distanceX, float distanceY, long time); + } \ No newline at end of file