From 521f440d16ca13f626c845ca294514a27e409949 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Fri, 8 Feb 2013 06:23:20 +0000 Subject: [PATCH] new android code --- jni/android_api.cpp | 150 +----------------- jni/android_api.h | 5 +- .../salmonjnitemplate/GLView.java | 7 +- .../salmonjnitemplate/JniWrapper.java | 12 -- .../salmonjnitemplate/MainActivity.java | 28 ++-- windows/SalmonTemplate/Template/main.cpp | 12 +- 6 files changed, 33 insertions(+), 181 deletions(-) diff --git a/jni/android_api.cpp b/jni/android_api.cpp index f38db27..4e8cca3 100644 --- a/jni/android_api.cpp +++ b/jni/android_api.cpp @@ -1,156 +1,12 @@ #include "android_api.h" +#include "boost/thread.hpp" + #include "main_code.h" -#include "boost\thread.hpp" - -boost::shared_ptr App; - -boost::mutex m; JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height) { - m.lock(); - try - { - - CreateEngine(); - - App = boost::shared_ptr(new TMyApplication); - - App->OuterInit(width, height, 320.f, 480.f); - - } - catch (...) - { - throw; - } - m.unlock(); + JniInitApp(width, height, 320.f, 480.f); } -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_StopSounds(JNIEnv * env, jobject obj) -{ - -} - - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Update(JNIEnv * env, jobject obj, long dt) -{ - m.lock(); - try - { - - App->OuterDraw(); - App->OuterUpdate(dt); - - - } - catch (...) - { - throw; - } - m.unlock(); - -} - -JNIEXPORT int JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_IsInited(JNIEnv * env, jobject obj) -{ - - return 0; - -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Destroy(JNIEnv * env, jobject obj) -{ - m.lock(); - try - { - - App->OuterDeinit(); - - delete App; - - App = NULL; - - DestroyEngine(); - - } - catch (...) - { - throw; - } - m.unlock(); -} - - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, float x, float y, long time) -{ - try - { - App->OuterOnTapDown(vec2(x,y)); - } - catch (...) - { - throw; - } -} - - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, float x, float y, long time) -{ - try - { - App->OuterOnTapUp(vec2(x,y)); - } - catch (...) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUpAfterShift(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time) -{ - try - { - App->OuterOnTapUpAfterShift(vec2(x,y)); - } - catch (...) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time) -{ - try - { - App->OuterOnMove(vec2(x,y)); - } - catch (...) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time) -{ - -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time) -{ - - try - { - App->OuterOnMove(vec2(distanceX,distanceY)); - } - catch (...) - { - throw; - } -} - -JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode) -{ - //App->OnKeyPress(keyCode); -} diff --git a/jni/android_api.h b/jni/android_api.h index cebc572..0b9a600 100644 --- a/jni/android_api.h +++ b/jni/android_api.h @@ -17,17 +17,18 @@ using namespace SE; extern "C" { JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height); - JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_StopSounds(JNIEnv * env, jobject obj); + /*JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_StopSounds(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Update(JNIEnv * env, jobject obj, long dt); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Destroy(JNIEnv * env, jobject obj); JNIEXPORT int JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_IsInited(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); - JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUpAfterShift(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); + JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUpAfterMove(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time); JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode); +*/ }; diff --git a/src/fishrungames/salmonjnitemplate/GLView.java b/src/fishrungames/salmonjnitemplate/GLView.java index 085f3e0..9f98926 100644 --- a/src/fishrungames/salmonjnitemplate/GLView.java +++ b/src/fishrungames/salmonjnitemplate/GLView.java @@ -10,11 +10,15 @@ import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import fishrungames.engine.GLViewAncestor; +import fishrungames.engine.FileWrapper; + class GLView extends GLViewAncestor { static long lastTimeStamp; static boolean gameIsInited = false; + + static boolean callDestroy = false; public GLView(Context context) { @@ -51,7 +55,7 @@ class GLView extends GLViewAncestor long currentTimeStamp = c.getTimeInMillis(); - JniWrapper.Update(currentTimeStamp - lastTimeStamp); + FileWrapper.Update(currentTimeStamp - lastTimeStamp); lastTimeStamp = currentTimeStamp; } @@ -60,7 +64,6 @@ class GLView extends GLViewAncestor public void onSurfaceChanged(GL10 gl, int width, int height) { - //JniWrapper.Destroy(); JniWrapper.Init(width,height); diff --git a/src/fishrungames/salmonjnitemplate/JniWrapper.java b/src/fishrungames/salmonjnitemplate/JniWrapper.java index 158b374..e7022b8 100644 --- a/src/fishrungames/salmonjnitemplate/JniWrapper.java +++ b/src/fishrungames/salmonjnitemplate/JniWrapper.java @@ -8,17 +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 OnTapUpAfterShift(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); - - public static native void OnKeyPress(int keyCode); } \ No newline at end of file diff --git a/src/fishrungames/salmonjnitemplate/MainActivity.java b/src/fishrungames/salmonjnitemplate/MainActivity.java index 74aa2f4..045d243 100644 --- a/src/fishrungames/salmonjnitemplate/MainActivity.java +++ b/src/fishrungames/salmonjnitemplate/MainActivity.java @@ -92,14 +92,24 @@ public class MainActivity extends Activity mView = new GLView(getApplication()); + setContentView(mView); } + + class JniDestroyRunnable implements Runnable + { + public void run () + { + FileWrapper.Destroy(); + } + } @Override protected void onPause() { - JniWrapper.Destroy(); + + mView.queueEvent(new JniDestroyRunnable()); super.onPause(); mView.onPause(); } @@ -132,7 +142,7 @@ public class MainActivity extends Activity ascii_keycode = event.getUnicodeChar(); } - JniWrapper.OnKeyPress(ascii_keycode); + FileWrapper.OnKeyPress(ascii_keycode); return super.onKeyDown(keyCode, event); } @@ -164,7 +174,7 @@ public class MainActivity extends Activity if (Math.abs(shiftX) > 0.001f || Math.abs(shiftY) > 0.001f) { - JniWrapper.OnScroll(-shiftX, -shiftY, event.getEventTime()); + FileWrapper.OnScroll(-shiftX, -shiftY, event.getEventTime()); } PrevMovePosX = event.getX(); @@ -189,11 +199,11 @@ public class MainActivity extends Activity if (IsScrolling) { IsScrolling = false; - JniWrapper.OnTapUpAfterShift(x, y, event.getEventTime()); + FileWrapper.OnTapUpAfterMove(x, y, event.getEventTime()); } else { - JniWrapper.OnTapUp(x, y, event.getEventTime()); + FileWrapper.OnTapUp(x, y, event.getEventTime()); } } @@ -206,7 +216,7 @@ public class MainActivity extends Activity PrevMovePosX = event.getX(); PrevMovePosY = event.getY(); - JniWrapper.OnTapDown(x, y, event.getEventTime()); + FileWrapper.OnTapDown(x, y, event.getEventTime()); } return true; @@ -219,7 +229,7 @@ public class MainActivity extends Activity public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - JniWrapper.OnFling(velocityX, velocityY, e2.getEventTime()); + FileWrapper.OnFling(velocityX, velocityY, e2.getEventTime()); return true; @@ -229,7 +239,7 @@ public class MainActivity extends Activity float distanceX, float distanceY) { - JniWrapper.OnScroll(distanceX, distanceY, e2.getEventTime()); + FileWrapper.OnScroll(distanceX, distanceY, e2.getEventTime()); IsScrolling = true; return true; } @@ -240,7 +250,7 @@ public class MainActivity extends Activity float x = event.getX(); float y = (float) mView.getHeight() - event.getY(); - JniWrapper.OnTapDown(x, y, event.getEventTime()); + FileWrapper.OnTapDown(x, y, event.getEventTime()); return true; } diff --git a/windows/SalmonTemplate/Template/main.cpp b/windows/SalmonTemplate/Template/main.cpp index 35c38e9..942d291 100644 --- a/windows/SalmonTemplate/Template/main.cpp +++ b/windows/SalmonTemplate/Template/main.cpp @@ -2,18 +2,12 @@ #include "main_code.h" + int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, LPSTR lpszCmdLine, int nCmdShow) { - //Create application - TMyApplication Application; - //Application.Width = 480; - //Application.Height = 320; + OuterMainLoop(320, 480); - Application.Width = 320; - Application.Height = 480; - - //Start application - return MainLoop(Application); + return 0; } \ No newline at end of file