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