diff --git a/dev/src/core.cpp b/dev/src/core.cpp index c3af8ab..e7ea895 100644 --- a/dev/src/core.cpp +++ b/dev/src/core.cpp @@ -107,6 +107,22 @@ namespace olc return true; } +#if OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS + void PGEWindow::OnUserSaveState() + { + return; + } + + void PGEWindow::OnUserResume() + { + return; + } + + void PGEWindow::OnUserLowMemory() + { + return; + } +#endif // OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS bool PGEWindow::olc_WindowUpdate(const float fElapsedTime, const float fTotalElapsedTime) { float fDT = fElapsedTime; diff --git a/dev/src/core.h b/dev/src/core.h index 43e1a76..af2136c 100644 --- a/dev/src/core.h +++ b/dev/src/core.h @@ -90,8 +90,17 @@ namespace olc virtual bool OnUserUpdate(float fElapsedTime); // Return true if window is to close virtual bool OnUserDestroy(); - + // Apple iOS and Android only +#if OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS + // Called when the application is requested to save its state + virtual void OnUserSaveState(); + // Called when the application is requested to resume its state + virtual void OnUserResume(); + // Called when the application is running low on memory + virtual void OnUserLowMemory(); +#endif + public: // olc::Image Handling // These are the preferred methods to create olc::Image objects diff --git a/dev/src/host_android.cpp b/dev/src/host_android.cpp index 1e2c7ac..9fafe41 100644 --- a/dev/src/host_android.cpp +++ b/dev/src/host_android.cpp @@ -239,7 +239,7 @@ namespace olc::host if (!host->pgeWindow) return; switch (cmd) { - case APP_CMD_WINDOW_RESIZED: + case APP_CMD_WINDOW_RESIZED:{ host->pgeWindow->olc_OnWindowSize({ ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window) @@ -248,25 +248,47 @@ namespace olc::host ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window)); break; - case APP_CMD_INIT_WINDOW: + } + case APP_CMD_INIT_WINDOW:{ if (app->window) { host->initialized = true; LOGD("APP_CMD_INIT_WINDOW received with Window"); } break; + } case APP_CMD_TERM_WINDOW: { - host->pgeWindow->olc_OnWindowClose(); - host->initialized = false; LOGD("APP_CMD_TERM_WINDOW received"); - } break; + if(host){ + host->pgeWindow->olc_OnWindowClose(); + host->initialized = false; + } + break; + } + case APP_CMD_SAVE_STATE: { + LOGD("APP_CMD_SAVE_STATE received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserSaveState(); + break; + } + case APP_CMD_RESUME: { + LOGD("APP_CMD_RESUME received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserResume(); + break; + } case APP_CMD_GAINED_FOCUS: { LOGD("APP_CMD_GAINED_FOCUS received"); - host->pgeWindow->olc_OnFocus(true); - } break; + if(host)host->pgeWindow->olc_OnFocus(true); + break; + } case APP_CMD_LOST_FOCUS: { LOGD("APP_CMD_LOST_FOCUS received"); - host->pgeWindow->olc_OnFocus(false); - } break; + if(host) host->pgeWindow->olc_OnFocus(false); + break; + } + case APP_CMD_LOW_MEMORY: { + LOGD("APP_CMD_LOW_MEMORY received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserLowMemory(); + break; + } default: break; } } diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h index 2a0e918..4bf822e 100644 --- a/olcPixelGameEngine3.h +++ b/olcPixelGameEngine3.h @@ -4435,8 +4435,17 @@ namespace olc virtual bool OnUserUpdate(float fElapsedTime); // Return true if window is to close virtual bool OnUserDestroy(); - + // Apple iOS and Android only +#if OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS + // Called when the application is requested to save its state + virtual void OnUserSaveState(); + // Called when the application is requested to resume its state + virtual void OnUserResume(); + // Called when the application is running low on memory + virtual void OnUserLowMemory(); +#endif + public: // olc::Image Handling // These are the preferred methods to create olc::Image objects @@ -15051,7 +15060,7 @@ namespace olc::host if (!host->pgeWindow) return; switch (cmd) { - case APP_CMD_WINDOW_RESIZED: + case APP_CMD_WINDOW_RESIZED:{ host->pgeWindow->olc_OnWindowSize({ ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window) @@ -15060,25 +15069,47 @@ namespace olc::host ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window)); break; - case APP_CMD_INIT_WINDOW: + } + case APP_CMD_INIT_WINDOW:{ if (app->window) { host->initialized = true; LOGD("APP_CMD_INIT_WINDOW received with Window"); } break; + } case APP_CMD_TERM_WINDOW: { - host->pgeWindow->olc_OnWindowClose(); - host->initialized = false; LOGD("APP_CMD_TERM_WINDOW received"); - } break; + if(host){ + host->pgeWindow->olc_OnWindowClose(); + host->initialized = false; + } + break; + } + case APP_CMD_SAVE_STATE: { + LOGD("APP_CMD_SAVE_STATE received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserSaveState(); + break; + } + case APP_CMD_RESUME: { + LOGD("APP_CMD_RESUME received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserResume(); + break; + } case APP_CMD_GAINED_FOCUS: { LOGD("APP_CMD_GAINED_FOCUS received"); - host->pgeWindow->olc_OnFocus(true); - } break; + if(host)host->pgeWindow->olc_OnFocus(true); + break; + } case APP_CMD_LOST_FOCUS: { LOGD("APP_CMD_LOST_FOCUS received"); - host->pgeWindow->olc_OnFocus(false); - } break; + if(host) host->pgeWindow->olc_OnFocus(false); + break; + } + case APP_CMD_LOW_MEMORY: { + LOGD("APP_CMD_LOW_MEMORY received"); + if(pPrimaryPGE) pPrimaryPGE->OnUserLowMemory(); + break; + } default: break; } } @@ -20054,6 +20085,22 @@ namespace olc return true; } +#if OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS + void PGEWindow::OnUserSaveState() + { + return; + } + + void PGEWindow::OnUserResume() + { + return; + } + + void PGEWindow::OnUserLowMemory() + { + return; + } +#endif // OLC_HOST == OLC_HOST_ANDROID || OLC_HOST == OLC_HOST_IOS bool PGEWindow::olc_WindowUpdate(const float fElapsedTime, const float fTotalElapsedTime) { float fDT = fElapsedTime;