Android code stuff

This commit is contained in:
Vladislav Khorev 2013-02-08 06:23:46 +00:00
parent 1c9300c1ba
commit 9c85ebd1f8
4 changed files with 267 additions and 0 deletions

View File

@ -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

View File

@ -27,4 +27,6 @@ void DestroyEngine();
#include "include/GUIManager/WidgetTemplatesImpl.h"
#include "include/Utils/ThreadUtilsImpl.h"
#include "include/Utils/JniApi/JniApplication.h"
#endif

View File

@ -0,0 +1,76 @@
#ifndef JNI_APPLICATION_H_INCLUDED
#define JNI_APPLICATION_H_INCLUDED
#include <jni.h>
#include <android/log.h>
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "boost/thread.hpp"
namespace SE
{
extern TApplication* App;
extern boost::mutex InitLock;
extern bool Inited;
template<typename APPTYPE>
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

View File

@ -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