This commit is contained in:
Vladislav Khorev 2013-02-10 12:46:44 +00:00
parent 87f4d81238
commit 287ab26da1
5 changed files with 13 additions and 247 deletions

View File

@ -1,128 +1,10 @@
#include "android_api.h"
#include "main_code.h"
#include "boost\thread.hpp"
boost::shared_ptr<TMyApplication> App(new TMyApplication);
boost::mutex m;
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
{
m.lock();
try
{
if (App->IsInited())
{
App->OuterDeinit(); //Clean up what is left at previous launch (if applicable)
}
App->OuterInit(width, height, 480.f, 320.f);
App->Inited = true;
}
catch (...)
{
throw;
}
m.unlock();
}
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_StopSounds(JNIEnv * env, jobject obj)
{
JniInitApp<TMyApplication>(width, height, 480.f, 320.f);
}
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Update(JNIEnv * env, jobject obj, long dt)
{
m.lock();
try
{
if (App->IsInited())
{
App->OuterDraw();
App->OuterUpdate(dt);
}
}
catch (...)
{
throw;
}
m.unlock();
}
JNIEXPORT int JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_IsInited(JNIEnv * env, jobject obj)
{
if (App->IsInited())
{
return 1;
}
else
{
return 0;
}
}
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Destroy(JNIEnv * env, jobject obj)
{
m.lock();
try
{
if (App->IsInited())
{
App->OuterDeinit();
App->Inited = false;
}
}
catch (...)
{
throw;
}
m.unlock();
}
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, float x, float y, long time)
{
m.lock();
try
{
Renderer->MoveDist(1.0f);
}
catch (...)
{
throw;
}
m.unlock();
}
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, float x, float 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)
{
//App->OnKeyPress(keyCode);
}

View File

@ -12,21 +12,13 @@
#include "main_code.h"
#include "include/Engine.h"
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_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_OnTapMove(JNIEnv * env, jobject obj, jfloat x, jfloat 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);
};

View File

@ -10,6 +10,7 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import fishrungames.engine.GLViewAncestor;
import fishrungames.engine.EngineWrapper;
class GLView extends GLViewAncestor
{
@ -49,7 +50,7 @@ class GLView extends GLViewAncestor
long currentTimeStamp = c.getTimeInMillis();
JniWrapper.Update(currentTimeStamp - lastTimeStamp);
EngineWrapper.Update(currentTimeStamp - lastTimeStamp);
lastTimeStamp = currentTimeStamp;
}

View File

@ -8,16 +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);
public static native void OnKeyPress(int keyCode);
}

View File

@ -1,6 +1,6 @@
package fishrungames.salmonjnitemplate;
import fishrungames.engine.FileWrapper;
import fishrungames.engine.EngineWrapper;
//Deprecated
//import fishrungames.androidjnitemplate.R;
@ -15,19 +15,7 @@ import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
/*
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Xml;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
*/
//Deprecated
//import java.lang.reflect.Field;
public class MainActivity extends Activity
@ -35,42 +23,16 @@ public class MainActivity extends Activity
GLView mView;
boolean IsScrolling = false;
private GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
gestureDetector = new GestureDetector(new MyGestureListener());
EngineWrapper.LoadSalmonEngineLibrary();
FileWrapper.LoadSalmonEngineLibrary();
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.SetActivityInstance(this);
EngineWrapper.SetupEnviroment();
String apkFilePath = null;
ApplicationInfo appInfo = null;
@ -84,7 +46,7 @@ public class MainActivity extends Activity
}
apkFilePath = appInfo.sourceDir;
FileWrapper.SetupApkFilePath(apkFilePath);
EngineWrapper.SetupApkFilePath(apkFilePath);
mView = new GLView(getApplication());
@ -95,7 +57,7 @@ public class MainActivity extends Activity
@Override
protected void onPause()
{
JniWrapper.Destroy();
EngineWrapper.Destroy();
super.onPause();
mView.onPause();
}
@ -117,75 +79,15 @@ public class MainActivity extends Activity
public boolean onKeyDown(int keyCode, KeyEvent event)
{
int ascii_keycode = keyCode;
if (keyCode == KeyEvent.KEYCODE_DEL)
{
ascii_keycode = 8; //Hack - getUnicodeChar does not recognize backspace
}
else
{
ascii_keycode = event.getUnicodeChar();
}
JniWrapper.OnKeyPress(ascii_keycode);
EngineWrapper.ProcessKeyDown(keyCode, event);
return super.onKeyDown(keyCode, event);
}
public boolean onTouchEvent(MotionEvent event)
{
if (gestureDetector.onTouchEvent(event))
{
return true;
}
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
{
@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;
}
}
}