ios application lifecycle

edited July 2011 in Help request
right now a game on the ios platform will not do anything by default once the focus is lost.
once it will go into the background a event handler will inhibit the game from rendering. according to the docs:
http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/ImplementingaMultitasking-awareOpenGLESApplication/ImplementingaMultitasking-awareOpenGLESApplication.html#//apple_ref/doc/uid/TP40008793-CH5-SW1
we should also also call glFinish at some point to make sure that the command buffer is emptied, shoudln't we?

more importantly: if one pushes the power button, while an app is running, this app will loose focus, but however it will still keep running. shouldn't we also stop rendering in that case, in order to not drain the battery that much?
so my question: shouldn't we already stop rendering when we lose focus?

also the app will go into background when there are calls incoming. wouldn't we still be playing back any kinds of sounds still? I only got an ipad so I don't care that much and I have no means of testing, but I was just wondering.

Comments

  • edited July 2011
    I guess we should also think about lowering the FPS in that case or suspending the main thread.
  • edited July 2011
    Yes, we should definitely do all this.

    Actually, I've already written some code in that direction but never had the opportunity to test it on device.

    In code/src/main/orxiPhone.m there's this code:
    
    - (void) applicationWillTerminate:(UIApplication *)_poApplication
    {
      /* Sends event */
      orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_CLOSE);
    }
    
    - (void) applicationDidEnterBackground:(UIApplication *)_poApplication
    {
      /* Sends event */
      if(orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_BACKGROUND) != orxSTATUS_FAILURE)
      {
        /* Adds render inhibiter */
        orxEvent_AddHandler(orxEVENT_TYPE_RENDER, RenderInhibiter);
      }
    }
    
    - (void) applicationWillEnterForeground:(UIApplication *)_poApplication
    {
      /* Sends event */
      if(orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOREGROUND) != orxSTATUS_FAILURE)
      {
        /* Removes render inhibiter */
        orxEvent_RemoveHandler(orxEVENT_TYPE_RENDER, RenderInhibiter);
      }
    }
    
    - (void) applicationWillResignActive:(UIApplication *)_poApplication
    {
      /* Sends event */
      orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_LOST);
    }
    
    - (void) applicationDidBecomeActive:(UIApplication *)_poApplication
    {
      static orxBOOL sbFirstActivation = orxTRUE;
    
      /* First activation? */
      if(sbFirstActivation != orxFALSE)
      {
        /* Updates status */
        sbFirstActivation = orxFALSE;
      }
      else
      {
        /* Sends event */
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_GAINED);
      }
    }
    

    So as you can see we send some orxEVENT to synchronize with the info we get from iOS. We also force to inhibit the redering unless the user handles the event and asks us not to do it (not sure someone would want to do that anytime but at least the option's there ^^).

    I didn't think of sound though and I only did the render part as Apple's doc says it'd crash the app if any OpenGL call were to be made while the app is in background.

    As you can see, the user can listen to those events and do whatever he wants like pausing his game and disabling his objects (which would then mute the sound) when needed. :)
Sign In or Register to comment.