Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dev/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion dev/src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 31 additions & 9 deletions dev/src/host_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
}
Expand Down
67 changes: 57 additions & 10 deletions olcPixelGameEngine3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
Loading