From 56e1e5d247aabab4f3d6cf0a830ecfee4773610b Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 22 Mar 2022 17:48:16 +0100 Subject: [PATCH] Game pausing using Oculus button improved --- .../app/src/main/cpp/code/client/cl_console.c | 2 +- android/app/src/main/cpp/main.cpp | 22 +++++++++++++++++++ .../com/drbeef/ioq3quest/MainActivity.java | 6 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/cpp/code/client/cl_console.c b/android/app/src/main/cpp/code/client/cl_console.c index a009d13a..cf633626 100644 --- a/android/app/src/main/cpp/code/client/cl_console.c +++ b/android/app/src/main/cpp/code/client/cl_console.c @@ -790,7 +790,7 @@ Scroll it up or down void Con_RunConsole (void) { // decide on the destination height of the console if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) - con.finalFrac = 0.5; // half screen + con.finalFrac = 0.4; // half screen else con.finalFrac = 0; // none visible diff --git a/android/app/src/main/cpp/main.cpp b/android/app/src/main/cpp/main.cpp index 6de0f2ed..205f87ba 100644 --- a/android/app/src/main/cpp/main.cpp +++ b/android/app/src/main/cpp/main.cpp @@ -9,6 +9,7 @@ #include extern "C" { + #include #include #include #include @@ -28,6 +29,7 @@ extern "C" { static JNIEnv* g_Env = NULL; static JavaVM* g_JavaVM = NULL; static jobject g_ActivityObject = NULL; +static bool g_HasFocus = true; extern "C" @@ -37,6 +39,11 @@ extern "C" g_ActivityObject = env->NewGlobalRef(thisObject); } + JNIEXPORT void JNICALL Java_com_drbeef_ioq3quest_MainActivity_nativeFocusChanged(JNIEnv *env, jclass clazz, jboolean focus) + { + g_HasFocus = focus; + } + JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { g_JavaVM = vm; @@ -83,7 +90,22 @@ int main(int argc, char* argv[]) { VR_EnterVR(engine, java); + bool hasFocus = true; + bool paused = false; while (1) { + if (hasFocus != g_HasFocus) { + hasFocus = g_HasFocus; + if (!hasFocus && !Cvar_VariableValue ("cl_paused")) { + Com_QueueEvent( Sys_Milliseconds(), SE_KEY, K_ESCAPE, qtrue, 0, NULL ); + Com_QueueEvent( Sys_Milliseconds(), SE_KEY, K_CONSOLE, qtrue, 0, NULL ); + paused = true; + } else if (hasFocus && paused) { + Com_QueueEvent( Sys_Milliseconds(), SE_KEY, K_CONSOLE, qtrue, 0, NULL ); + Com_QueueEvent( Sys_Milliseconds(), SE_KEY, K_ESCAPE, qtrue, 0, NULL ); + paused = false; + } + } + SDL_Event event; while (SDL_PollEvent(&event)) { LOGI("Received SDL Event: %d", event.type); diff --git a/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java b/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java index cfe89302..0459be6f 100644 --- a/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java +++ b/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java @@ -82,6 +82,11 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback } } + @Override + public void onWindowFocusChanged(boolean hasFocus) { + nativeFocusChanged(hasFocus); + } + public void create() throws IOException { //Make the directories new File("/sdcard/ioquake3Quest/baseq3").mkdirs(); @@ -188,6 +193,7 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback } public static native void nativeCreate(MainActivity thisObject); + public static native void nativeFocusChanged(boolean focus); static { System.loadLibrary("main");