Add guard against render event when in the background

This commit is contained in:
Joshua Granick
2016-11-18 14:49:45 -08:00
parent c9526b2e43
commit d9f5900685

View File

@@ -17,8 +17,10 @@ namespace lime {
AutoGCRoot* Application::callback = 0; AutoGCRoot* Application::callback = 0;
SDLApplication* SDLApplication::currentApplication = 0; SDLApplication* SDLApplication::currentApplication = 0;
const int analogAxisDeadZone = 1000; const int analogAxisDeadZone = 1000;
std::map<int, std::map<int, int> > gamepadsAxisMap; std::map<int, std::map<int, int> > gamepadsAxisMap;
bool suspendRender = false;
SDLApplication::SDLApplication () { SDLApplication::SDLApplication () {
@@ -112,25 +114,32 @@ namespace lime {
case SDL_USEREVENT: case SDL_USEREVENT:
currentUpdate = SDL_GetTicks (); if (!suspendRender) {
applicationEvent.type = UPDATE;
applicationEvent.deltaTime = currentUpdate - lastUpdate; currentUpdate = SDL_GetTicks ();
lastUpdate = currentUpdate; applicationEvent.type = UPDATE;
applicationEvent.deltaTime = currentUpdate - lastUpdate;
nextUpdate += framePeriod; lastUpdate = currentUpdate;
while (nextUpdate <= currentUpdate) {
nextUpdate += framePeriod; nextUpdate += framePeriod;
while (nextUpdate <= currentUpdate) {
nextUpdate += framePeriod;
}
ApplicationEvent::Dispatch (&applicationEvent);
RenderEvent::Dispatch (&renderEvent);
} }
ApplicationEvent::Dispatch (&applicationEvent);
RenderEvent::Dispatch (&renderEvent);
break; break;
case SDL_APP_WILLENTERBACKGROUND: case SDL_APP_WILLENTERBACKGROUND:
suspendRender = true;
windowEvent.type = WINDOW_DEACTIVATE; windowEvent.type = WINDOW_DEACTIVATE;
WindowEvent::Dispatch (&windowEvent); WindowEvent::Dispatch (&windowEvent);
break; break;
@@ -139,6 +148,8 @@ namespace lime {
windowEvent.type = WINDOW_ACTIVATE; windowEvent.type = WINDOW_ACTIVATE;
WindowEvent::Dispatch (&windowEvent); WindowEvent::Dispatch (&windowEvent);
suspendRender = false;
break; break;
case SDL_CONTROLLERAXISMOTION: case SDL_CONTROLLERAXISMOTION:
@@ -227,13 +238,24 @@ namespace lime {
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
RenderEvent::Dispatch (&renderEvent); if (!suspendRender) {
RenderEvent::Dispatch (&renderEvent);
}
break; break;
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
ProcessWindowEvent (event); ProcessWindowEvent (event);
RenderEvent::Dispatch (&renderEvent);
if (!suspendRender) {
RenderEvent::Dispatch (&renderEvent);
}
break; break;
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE: