Android: Fix immediately exiting if try to start game with invalid IP/port. Also clicking 'quit game' returns to main menu instead of exiting.

This commit is contained in:
UnknownShadow200 2020-10-13 17:05:58 +11:00
parent c5da3f42d0
commit e4d6455ffe
5 changed files with 37 additions and 26 deletions

View File

@ -670,33 +670,13 @@ static void Game_RunLoop(void) {
#endif
#ifdef CC_BUILD_ANDROID
static cc_bool winCreated;
static void OnWindowCreated(void* obj) { winCreated = true; }
extern cc_bool Window_RemakeSurface(void);
static cc_bool SwitchToGame() {
JNIEnv* env;
JavaGetCurrentEnv(env);
/* Reset components */
Platform_LogConst("undoing components");
Drawer2D_Component.Free();
//Http_Component.Free();
/* Force window to be destroyed and re-created */
/* (see comments in setupForGame for why this has to be done) */
JavaCallVoid(env, "setupForGame", "()V", NULL);
Event_Register_(&WindowEvents.Created, NULL, OnWindowCreated);
Platform_LogConst("Entering wait for window loop..");
/* Loop until window gets created async */
while (WindowInfo.Exists && !winCreated) {
Window_ProcessEvents();
Thread_Sleep(10);
}
Platform_LogConst("OK I'm starting the game..");
Event_Unregister_(&WindowEvents.Created, NULL, OnWindowCreated);
return winCreated;
return Window_RemakeSurface();
}
#endif

View File

@ -1145,9 +1145,6 @@ void Http_UrlEncodeUrl(String* dst, const String* src) {
*-----------------------------------------------------Http component------------------------------------------------------*
*#########################################################################################################################*/
static void OnInit(void) {
#ifdef CC_BUILD_ANDROID
if (workerThread) return;
#endif
Http_WorkerInit();
ScheduledTask_Add(30, Http_CleanCacheTask);
RequestList_Init(&pendingReqs);

View File

@ -308,7 +308,16 @@ void Launcher_Run(void) {
#ifdef CC_BUILD_ANDROID
extern int Program_Run(int argc, char** argv);
if (Launcher_ShouldExit) Program_Run(0, NULL);
extern cc_bool Window_RemakeSurface(void);
if (Launcher_ShouldExit) {
Launcher_ShouldExit = false;
Http_Component.Free();
Program_Run(0, NULL);
Window_RemakeSurface();
Launcher_Run();
}
#endif
if (Launcher_ShouldUpdate) {
const char* action;

View File

@ -114,6 +114,7 @@ GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) {
static void Atlas2D_Free(void) {
Mem_Free(Atlas2D.Bmp.scan0);
Atlas2D.Bmp.scan0 = NULL;
Atlas2D.RowsCount = 0;
}
static void Atlas1D_Free(void) {

View File

@ -3789,6 +3789,30 @@ void Window_Create(int width, int height) {
/* actual window creation is done when processSurfaceCreated is received */
}
static cc_bool winCreated;
static void OnWindowCreated(void* obj) { winCreated = true; }
cc_bool Window_RemakeSurface(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
winCreated = false;
/* Force window to be destroyed and re-created */
/* (see comments in setupForGame for why this has to be done) */
JavaCallVoid(env, "setupForGame", "()V", NULL);
Event_Register_(&WindowEvents.Created, NULL, OnWindowCreated);
Platform_LogConst("Entering wait for window exist loop..");
/* Loop until window gets created async */
while (WindowInfo.Exists && !winCreated) {
Window_ProcessEvents();
Thread_Sleep(10);
}
Platform_LogConst("OK window created..");
Event_Unregister_(&WindowEvents.Created, NULL, OnWindowCreated);
return winCreated;
}
void Window_SetTitle(const String* title) {
/* TODO: Implement this somehow */
/* Maybe https://stackoverflow.com/questions/2198410/how-to-change-title-of-activity-in-android */