add QuitGame function for quiting or sending game to the background (depending on the platform)

This commit is contained in:
Sebastian Krzyszkowiak 2018-07-31 21:25:07 +02:00
parent 8ff2a57b64
commit a730281bb8
3 changed files with 20 additions and 0 deletions

View file

@ -39,6 +39,7 @@ struct GamestateResources;
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_video.h>
#ifdef ALLEGRO_ANDROID
#define ALLEGRO_UNSTABLE
#include <allegro5/allegro_android.h>
#endif
#ifdef __EMSCRIPTEN__

View file

@ -528,3 +528,19 @@ SYMBOL_EXPORT char* PunchNumber(struct Game* game, char* text, char ch, int numb
};
return AddGarbage(game, txt);
}
SYMBOL_EXPORT void QuitGame(struct Game* game, bool allow_pausing) {
#ifdef ALLEGRO_ANDROID
if (allow_pausing) {
JNIEnv* env = al_android_get_jni_env();
jclass class_id = (*env)->GetObjectClass(env, al_android_get_activity());
jmethodID method_id = (*env)->GetMethodID(env, class_id, "moveTaskToBack",
"(Z)Z");
jvalue jdata;
jdata.z = JNI_TRUE;
(*env)->CallBooleanMethodA(env, al_android_get_activity(), method_id, &jdata);
return;
}
#endif
UnloadAllGamestates(game);
}

View file

@ -92,4 +92,7 @@ void DisableCompositor(struct Game* game);
char* PunchNumber(struct Game* game, char* text, char ch, int number);
/*! \brief Quits the game. On platforms that allow it, brings the game to the background without quiting if <allow_pausing> is true. */
void QuitGame(struct Game* game, bool allow_pausing);
#endif