tunnel/jni/android_api.cpp
2013-02-05 20:44:27 +00:00

157 lines
2.7 KiB
C++

#include "android_api.h"
#include "main_code.h"
#include "boost\thread.hpp"
boost::shared_ptr<TMyApplication> 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<TMyApplication>(new TMyApplication);
App->OuterInit(width, height, 320.f, 480.f);
}
catch (...)
{
throw;
}
m.unlock();
}
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);
}