diff android/dw.cpp @ 2514:5f711e86a211

Android: Implement dw_main_sleep() and dw_main_iteration(). Using the sort of hacky exception handler method for now.... since Google doesn't seem to want us to do this in a clean way.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 07 May 2021 19:54:05 +0000
parents 0fa54c340902
children 211044d98e86
line wrap: on
line diff
--- a/android/dw.cpp	Fri May 07 11:11:10 2021 +0000
+++ b/android/dw.cpp	Fri May 07 19:54:05 2021 +0000
@@ -512,6 +512,18 @@
  */
 void API dw_main_sleep(int milliseconds)
 {
+    JNIEnv *env;
+
+    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    {
+        // First get the class that contains the method you need to call
+        jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
+        // Get the method that you want to call
+        jmethodID mainSleep = env->GetMethodID(clazz, "mainSleep",
+                                                  "(I)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, mainSleep, milliseconds);
+    }
 }
 
 /*
@@ -519,6 +531,10 @@
  */
 void API dw_main_iteration(void)
 {
+    /* If we sleep for 0 milliseconds... we will drop out
+     * of the loop at the first idle moment
+     */
+    dw_main_sleep(0);
 }
 
 /*