diff --git a/Android_Salmon_Engine.mk b/Android_Salmon_Engine.mk index 9db4a19..56b0ea4 100644 --- a/Android_Salmon_Engine.mk +++ b/Android_Salmon_Engine.mk @@ -305,6 +305,7 @@ LOCAL_SRC_FILES := src/Utils/DataTypes/DataTypes.cpp LOCAL_SRC_FILES += src/Utils/DataTypes/NewDataTypes.cpp LOCAL_SRC_FILES += src/Utils/FileUtils/FileUtils.cpp LOCAL_SRC_FILES += src/Utils/JniApi/JniApi.cpp +LOCAL_SRC_FILES += src/Utils/JniApi/JniApplication.cpp LOCAL_SRC_FILES += src/Utils/Console/Console.cpp LOCAL_SRC_FILES += src/Utils/SerializeInterface/SerializeInterface.cpp LOCAL_SRC_FILES += src/Utils/PngHelper.cpp diff --git a/include/SalmonEngineAndroid.h b/include/SalmonEngineAndroid.h index 3677d7f..61df4c3 100644 --- a/include/SalmonEngineAndroid.h +++ b/include/SalmonEngineAndroid.h @@ -27,4 +27,6 @@ void DestroyEngine(); #include "include/GUIManager/WidgetTemplatesImpl.h" #include "include/Utils/ThreadUtilsImpl.h" +#include "include/Utils/JniApi/JniApplication.h" + #endif diff --git a/include/Utils/JniApi/JniApplication.h b/include/Utils/JniApi/JniApplication.h new file mode 100644 index 0000000..4a0829e --- /dev/null +++ b/include/Utils/JniApi/JniApplication.h @@ -0,0 +1,76 @@ +#ifndef JNI_APPLICATION_H_INCLUDED +#define JNI_APPLICATION_H_INCLUDED + + +#include +#include + +#include +#include +#include + +#include "boost/thread.hpp" + + +namespace SE +{ + +extern TApplication* App; + +extern boost::mutex InitLock; + +extern bool Inited; + + +template +void JniInitApp(int width, int height, float matrixWidth, float matrixHeight) +{ + InitLock.lock(); + + try + { + + if (Inited) + { + App->OuterDeinit(); + delete App; + App = NULL; + Inited = false; + + DestroyEngine(); + } + + CreateEngine(); + + App = new APPTYPE; + + App->OuterInit(width, height, matrixWidth, matrixHeight); + + Inited = true; + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +extern "C" { + //JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height); + + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_Update(JNIEnv * env, jobject obj, long dt); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_Destroy(JNIEnv * env, jobject obj); + JNIEXPORT int JNICALL Java_fishrungames_engine_FileWrapper_IsInited(JNIEnv * env, jobject obj); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapDown(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapUp(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapUpAfterMove(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time); + JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode); +}; + + +} // namespace SE + +#endif \ No newline at end of file diff --git a/src/Utils/JniApi/JniApplication.cpp b/src/Utils/JniApi/JniApplication.cpp new file mode 100644 index 0000000..ab55daf --- /dev/null +++ b/src/Utils/JniApi/JniApplication.cpp @@ -0,0 +1,188 @@ + +#include "include/Engine.h" + +namespace SE +{ + +TApplication* App = NULL; + +boost::mutex InitLock; + +bool Inited = false; + + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_Update(JNIEnv * env, jobject obj, long dt) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterDraw(); + App->OuterUpdate(dt); + } + + + } + catch (...) + { + throw; + } + InitLock.unlock(); + +} + +JNIEXPORT int JNICALL Java_fishrungames_engine_FileWrapper_IsInited(JNIEnv * env, jobject obj) +{ + if (Inited) + { + return 1; + } + else + { + return 0; + } + +} + + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_Destroy(JNIEnv * env, jobject obj) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterDeinit(); + + delete App; + + App = NULL; + + DestroyEngine(); + + Inited = false; + } + + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +void DestroyThreaded() +{ + +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapDown(JNIEnv * env, jobject obj, float x, float y, long time) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterOnTapDown(vec2(x,y)); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapUp(JNIEnv * env, jobject obj, float x, float y, long time) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterOnTapUp(vec2(x,y)); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapUpAfterMove(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterOnTapUpAfterMove(vec2(x,y)); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterOnMove(vec2(x,y)); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time) +{ + +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OuterOnMove(vec2(distanceX,distanceY)); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +JNIEXPORT void JNICALL Java_fishrungames_engine_FileWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode) +{ + InitLock.lock(); + try + { + if (Inited) + { + App->OnKeyPress(keyCode); + } + } + catch (...) + { + throw; + } + InitLock.unlock(); +} + +} // namespace SE