new android code
This commit is contained in:
parent
272882d796
commit
521f440d16
@ -1,156 +1,12 @@
|
||||
#include "android_api.h"
|
||||
|
||||
#include "boost/thread.hpp"
|
||||
|
||||
#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();
|
||||
JniInitApp<TMyApplication>(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);
|
||||
}
|
||||
|
@ -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);
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
@ -10,12 +10,16 @@ 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)
|
||||
{
|
||||
//Change this method? Don't forget to change method below!
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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<TMyApplication>(320, 480);
|
||||
|
||||
Application.Width = 320;
|
||||
Application.Height = 480;
|
||||
|
||||
//Start application
|
||||
return MainLoop(Application);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user