This commit is contained in:
Vladislav Khorev 2013-02-10 12:48:17 +00:00
parent 521f440d16
commit 5929980e9b
4 changed files with 13 additions and 179 deletions

View File

@ -6,7 +6,6 @@
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height) JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
{ {
JniInitApp<TMyApplication>(width, height, 320.f, 480.f); JniInitApp<TMyApplication>(width, height, 320.f, 480.f);
} }

View File

@ -17,18 +17,6 @@ using namespace SE;
extern "C" { 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_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_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);
*/
}; };

View File

@ -10,7 +10,7 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import fishrungames.engine.GLViewAncestor; import fishrungames.engine.GLViewAncestor;
import fishrungames.engine.FileWrapper; import fishrungames.engine.EngineWrapper;
class GLView extends GLViewAncestor class GLView extends GLViewAncestor
@ -18,8 +18,6 @@ class GLView extends GLViewAncestor
static long lastTimeStamp; static long lastTimeStamp;
static boolean gameIsInited = false; static boolean gameIsInited = false;
static boolean callDestroy = false;
public GLView(Context context) public GLView(Context context)
{ {
//Change this method? Don't forget to change method below! //Change this method? Don't forget to change method below!
@ -55,7 +53,7 @@ class GLView extends GLViewAncestor
long currentTimeStamp = c.getTimeInMillis(); long currentTimeStamp = c.getTimeInMillis();
FileWrapper.Update(currentTimeStamp - lastTimeStamp); EngineWrapper.Update(currentTimeStamp - lastTimeStamp);
lastTimeStamp = currentTimeStamp; lastTimeStamp = currentTimeStamp;
} }
@ -63,9 +61,6 @@ class GLView extends GLViewAncestor
public void onSurfaceChanged(GL10 gl, int width, int height) public void onSurfaceChanged(GL10 gl, int width, int height)
{ {
//JniWrapper.Destroy();
JniWrapper.Init(width,height); JniWrapper.Init(width,height);
} }

View File

@ -1,6 +1,6 @@
package fishrungames.salmonjnitemplate; package fishrungames.salmonjnitemplate;
import fishrungames.engine.FileWrapper; import fishrungames.engine.EngineWrapper;
//Deprecated //Deprecated
//import fishrungames.androidjnitemplate.R; //import fishrungames.androidjnitemplate.R;
@ -36,46 +36,18 @@ public class MainActivity extends Activity
GLView mView; GLView mView;
boolean IsScrolling = false;
float PrevMovePosX = 0;
float PrevMovePosY = 0;
private GestureDetector gestureDetector;
@Override @Override
protected void onCreate(Bundle icicle) protected void onCreate(Bundle icicle)
{ {
super.onCreate(icicle); super.onCreate(icicle);
gestureDetector = new GestureDetector(new MyGestureListener()); EngineWrapper.LoadSalmonEngineLibrary();
FileWrapper.LoadSalmonEngineLibrary(); EngineWrapper.SetActivityInstance(this);
EngineWrapper.SetupEnviroment();
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();
}*/
String apkFilePath = null; String apkFilePath = null;
ApplicationInfo appInfo = null; ApplicationInfo appInfo = null;
PackageManager packMgmr = this.getPackageManager(); PackageManager packMgmr = this.getPackageManager();
@ -88,28 +60,23 @@ public class MainActivity extends Activity
} }
apkFilePath = appInfo.sourceDir; apkFilePath = appInfo.sourceDir;
FileWrapper.SetupApkFilePath(apkFilePath); EngineWrapper.SetupApkFilePath(apkFilePath);
mView = new GLView(getApplication()); mView = new GLView(getApplication());
setContentView(mView); setContentView(mView);
EngineWrapper.SetView(mView);
} }
class JniDestroyRunnable implements Runnable
{
public void run ()
{
FileWrapper.Destroy();
}
}
@Override @Override
protected void onPause() protected void onPause()
{ {
mView.queueEvent(new JniDestroyRunnable()); EngineWrapper.CallDestroy();
super.onPause(); super.onPause();
mView.onPause(); mView.onPause();
} }
@ -131,130 +98,15 @@ public class MainActivity extends Activity
public boolean onKeyDown(int keyCode, KeyEvent event) public boolean onKeyDown(int keyCode, KeyEvent event)
{ {
int ascii_keycode = keyCode; EngineWrapper.ProcessKeyDown(keyCode, event);
if (keyCode == KeyEvent.KEYCODE_DEL)
{
ascii_keycode = 8; //Hack - getUnicodeChar does not recognize backspace
}
else
{
ascii_keycode = event.getUnicodeChar();
}
FileWrapper.OnKeyPress(ascii_keycode);
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public boolean onTouchEvent(MotionEvent event) public boolean onTouchEvent(MotionEvent event)
{ {
/* EngineWrapper.ProcessTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP)
{
if (IsScrolling)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
JniWrapper.OnTapUpAfterShift(x, y, event.getEventTime());
}
}
*/
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
float oldX = PrevMovePosX;
float oldY = (float) mView.getHeight() - PrevMovePosY;
float shiftX = x - oldX;
float shiftY = y - oldY;
if (Math.abs(shiftX) > 0.001f || Math.abs(shiftY) > 0.001f)
{
FileWrapper.OnScroll(-shiftX, -shiftY, event.getEventTime());
}
PrevMovePosX = event.getX();
PrevMovePosY = event.getY();
IsScrolling = true;
}
/*
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;
FileWrapper.OnTapUpAfterMove(x, y, event.getEventTime());
}
else
{
FileWrapper.OnTapUp(x, y, event.getEventTime());
}
}
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
PrevMovePosX = event.getX();
PrevMovePosY = event.getY();
FileWrapper.OnTapDown(x, y, event.getEventTime());
}
return true; return true;
} }
class MyGestureListener extends SimpleOnGestureListener
{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY)
{
FileWrapper.OnFling(velocityX, velocityY, e2.getEventTime());
return true;
}
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY)
{
FileWrapper.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();
FileWrapper.OnTapDown(x, y, event.getEventTime());
return true;
}
}
} }