int main (int argc, char* argv[]) { CGame Game; Uint32 frameStart; Uint32 frameTime; Game.Init(); // load the intro Game.ChangeState( CMainMenuState::Instance() ); // main loop while ( Game.Running() ) { frameStart = SDL_GetTicks(); Game.HandleEvents(); Game.Update(); Game.Render(); frameTime = SDL_GetTicks() - frameStart; if (frameTime < DELAY_TIME) { SDL_Delay((int) (DELAY_TIME - frameTime)); } } // cleanup the engine Game.Cleanup(); return 0; }
// ----------------------------------------------------------------------------- // CGameController::StartGameL // Intializes the Game and Starts the game loop. // ----------------------------------------------------------------------------- // void CGameController::StartGameL( CGame& aGame ) { iGame = &aGame; // Allow the game to initialize itself. // The opengl es state intialization is done here. aGame.Initialize( iWindow->Size().iWidth, iWindow->Size().iHeight ); TTime currentTime; TTime lastTimeVisited; lastTimeVisited.HomeTime(); while( 1 ) // Loop until the Game wants to exit. { // Process any pending tasks. // This runs any Active objects that are waiting for // some processing. // The CWsEventReceiver Active Object gets a chance to // run here (on a key event for example). ProcessBackgroundTasks( EFalse ); // If the application is not in focus or is not visible. // Block until it regains focus. while( EFalse == iIsAppInFocus || EFalse == iIsVisible ) ProcessBackgroundTasks( ETrue ); // Get the current time. currentTime.HomeTime(); TTimeIntervalMicroSeconds dur = currentTime.MicroSecondsFrom( lastTimeVisited ); // The game renders itself using opengl es apis. // A return value of EFalse signifies an exit from the game. // Pass in the time (in micro secs) elapsed since last call. if( EFalse == aGame.RenderFrame( dur.Int64() ) ) { break; } // Call eglSwapBuffers, which blits the graphics to the window. eglSwapBuffers( iEglDisplay, iEglSurface ); // To keep the background light on. if( !( ( iGame->GetCurrentFrame() )%100 ) ) { User::ResetInactivityTime(); } // Store the last time the Game was rendered. lastTimeVisited = currentTime; } // Cleanup. aGame.Cleanup(); }