XashActivity: Better use onPause for saving configs only, as this method is unkillable. onStop will just stop engine.

This commit is contained in:
Alibek Omarov (a1batross) 2017-03-04 00:56:51 +03:00
parent 323e314714
commit 3b5e5462b4

View file

@ -232,6 +232,13 @@ public class XashActivity extends Activity {
@Override @Override
protected void onPause() { protected void onPause() {
Log.v(TAG, "onPause()"); Log.v(TAG, "onPause()");
// let engine save all configs before exiting.
nativeOnPause();
// wait until Xash will save all configs
mSurface.engineThreadWait();
super.onPause(); super.onPause();
} }
@ -246,11 +253,11 @@ public class XashActivity extends Activity {
Log.v(TAG, "onStop()"); Log.v(TAG, "onStop()");
// let engine properly exit, instead of killing it's thread // let engine properly exit, instead of killing it's thread
nativeQuitEvent(); nativeOnStop();
// wait until Xash will exit // wait until Xash will exit
mSurface.engineThreadJoin(); mSurface.engineThreadJoin();
super.onStop(); super.onStop();
} }
@ -279,7 +286,8 @@ public class XashActivity extends Activity {
public static native void nativeBall(int id, byte ball, short xrel, short yrel); public static native void nativeBall(int id, byte ball, short xrel, short yrel);
public static native void nativeJoyAdd( int id ); public static native void nativeJoyAdd( int id );
public static native void nativeJoyDel( int id ); public static native void nativeJoyDel( int id );
public static native void nativeQuitEvent(); public static native void nativeOnStop();
public static native void nativeOnPause();
public static native int setenv(String key, String value, boolean overwrite); public static native int setenv(String key, String value, boolean overwrite);
@ -292,6 +300,10 @@ public class XashActivity extends Activity {
public static void swapBuffers() { public static void swapBuffers() {
mSurface.SwapBuffers(); mSurface.SwapBuffers();
} }
public static void engineThreadNotify() {
mSurface.engineThreadNotify();
}
public static Surface getNativeSurface() { public static Surface getNativeSurface() {
return XashActivity.mSurface.getNativeSurface(); return XashActivity.mSurface.getNativeSurface();
@ -649,7 +661,24 @@ View.OnKeyListener {
catch(InterruptedException e) catch(InterruptedException e)
{ {
} }
}
public void engineThreadWait()
{
Log.v(TAG, "engineThreadWait()");
try
{
mEngThread.wait(); // wait until Xash will quit
}
catch(InterruptedException e)
{
}
}
public void engineThreadNotify()
{
Log.v(TAG, "engineThreadNotify()");
mEngThread.notify(); // unblock
} }
// unused // unused