| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "engine.h"
- //Dummy constructors and destructors
- Engine::Engine(){}
- Engine::~Engine(){}
- //Starts up subsystems in an order that satifies their dependencies
- bool Engine::startUp(){
- bool success = true;
- //Start up of all SDL related content
- if( !gDisplayManager.startUp() ){
- success = false;
- printf("Failed to initialize window manager.\n");
- }
- else{
- //Loads default scene
- if( !gSceneManager.startUp() ){
- success = false;
- printf("Failed to initialize scene manager.\n");
- }
- else{
- //Initializes renderer and connects it to the window manager
- //Also gets pointer to current scene
- if( !gRenderManager.startUp(gDisplayManager,gSceneManager) ){
- success = false;
- printf("Failed to initialize render manager.\n");
-
- }
- else{
- if ( !gInputManager.startUp() ){
- success = false;
- printf("Failed to initialize input manager.\n");
- }
- }
- }
- }
- return success;
- }
- //Closing in opposite order to avoid dangling pointers
- void Engine::shutDown(){
- gInputManager.shutDown();
- printf("Closed input manager.\n");
- gRenderManager.shutDown();
- printf("Closed renderer manager.\n");
-
- gSceneManager.shutDown();
- printf("Closed Scene manager.\n");
-
- gDisplayManager.shutDown();
- printf("Closed display manager.\n");
- }
- //Runs main application loop and allows for scene changes
- void Engine::run(){
- //Main flags
- bool done = false;
- bool switchScene = false;
- //Iteration and time keeping counters
- int count = 0;
- unsigned int end = 0;
- unsigned int start = 0;;
- unsigned int total = 0;
- printf("Entered Main Loop!\n");
- while(!done){
- start = SDL_GetTicks();
- ++count;
-
- //If scene switching has been called you break out of the current loop
- if( switchScene ){
- if( !gSceneManager.switchScene("teapot") ){
- printf("Failed to switch scene! Quitting.\n");
- break;
- }
- else{
- switchScene = false;
- }
- }
- //Handle all user input
- done = gInputManager.processInput();
-
- //Update all models, camera and lighting in the current scene
- gSceneManager.update();
- //Update Rendering Queue and draw each item
- gRenderManager.render();
- //Stats about frame
- end = SDL_GetTicks();
- printf("%2.1d: Loop elapsed time (ms):%d\n",count,end - start);
- total += end - start;
- if (count == 500) break;
- //if (count == 100) switchScene = true;
- }
- printf("Closing down engine.\n");
- printf("Average frame time over %2.1d frames: %2.fms.\n", count,total/(float)count);
-
- }
|