Browse Source

Modified input manager to do more than just return quit flag.

angel 7 years ago
parent
commit
981f5e591f

+ 6 - 6
include/inputManager.h

@@ -2,7 +2,8 @@
 #define INPUTMANAGER_H
 
 //Headers
-#include"SDL.h"
+#include "sceneManager.h"
+#include "SDL.h"
 
 class InputManager{
 
@@ -12,15 +13,14 @@ class InputManager{
         InputManager();
         ~InputManager();
 
-        bool startUp();
+        bool startUp(SceneManager &sceneManager);
         void shutDown();
 
         //Processes all the SDL events that have ocurred in the given frame
-        //For now only listens to the SDL_QUIT event that signifies the window was 
-        //closed.
-        bool processInput();
+        void processInput(bool &done);
     private:
-        bool handleEvent(SDL_Event * event);
+    SceneManager *sceneController;
+    void handleEvent(SDL_Event * event);
 };
 
 

+ 1 - 1
include/renderManager.h

@@ -17,7 +17,7 @@ class RenderManager{
         ~RenderManager();
 
         //Gets scene and display info. Will be used to build render Queue
-        bool startUp(DisplayManager &displayManager,SceneManager &sceneManager );
+        bool startUp(DisplayManager &displayManager, SceneManager &sceneManager );
         void shutDown();
 
         //Performs all high level prep operations that the graphics library

+ 1 - 0
include/sceneManager.h

@@ -27,6 +27,7 @@ class SceneManager{
         bool loadScene(std::string sceneID);
         bool closeScene();
 
+        std::string currentSceneID;
         Scene *currentScene;
 };
 

BIN
scenes/teapot/.teapot_mesh.obj.swp


+ 7 - 7
src/engine.cpp

@@ -21,13 +21,13 @@ bool Engine::startUp(){
         else{
             //Initializes renderer and connects it to the window manager
             //Also gets pointer to current scene
-            if( !gRenderManager.startUp(gDisplayManager,gSceneManager) ){
+            if( !gRenderManager.startUp(gDisplayManager, gSceneManager) ){
             success = false;
             printf("Failed to initialize render manager.\n");
             
             }
             else{
-                if ( !gInputManager.startUp() ){
+                if ( !gInputManager.startUp(gSceneManager) ){
                     success = false;
                     printf("Failed to initialize input manager.\n");
                 }
@@ -70,7 +70,8 @@ void Engine::run(){
         start = SDL_GetTicks();
         ++count;
         
-        //If scene switching has been called you break out of the current loop 
+        //If scene switching is invoked it will attempt to switch to target scene
+        //If for whatever reason it can't it will quit out of the whole engine
         if( switchScene ){
             if( !gSceneManager.switchScene("teapot") ){
                 printf("Failed to switch scene! Quitting.\n");
@@ -82,9 +83,8 @@ void Engine::run(){
         }
 
         //Handle all user input
-        done = gInputManager.processInput();
+        gInputManager.processInput(done);
         
-
         //Update all models, camera and lighting in the current scene
         gSceneManager.update();
 
@@ -96,11 +96,11 @@ void Engine::run(){
         printf("%2.1d: Loop elapsed time (ms):%d\n",count,end - start);
         total += end - start;
         if (count == 500) break;
-        //if (count == 100) switchScene = true;
+        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);
+    printf("Average frame time over %2.1d frames:%2.fms.\n", count,total/(float)count);
     
 }

+ 19 - 13
src/inputManager.cpp

@@ -3,8 +3,9 @@
 InputManager::InputManager(){}
 InputManager::~InputManager(){}
 
-bool InputManager::startUp(){
-    //Nothing to do yet
+bool InputManager::startUp(SceneManager &sceneManager){
+
+    sceneController = &sceneManager;
     return true;
 }
 
@@ -12,19 +13,24 @@ void InputManager::shutDown(){
     //Nothing to do yet
 }
 
-bool InputManager::processInput(){
-    bool done = false;
-    SDL_Event Event;
-    while(SDL_PollEvent(&Event)){
-       done = handleEvent(&Event);
+void InputManager::processInput(bool &done){
+    SDL_Event event;
+    while(SDL_PollEvent(&event)){
+
+        //First check if user requests an exit
+        if(event.type == SDL_QUIT){
+            done = true;
+            return;       
+        }
+        //Handle any other relevant input data 
+        //Keypresses, mouse etc
+        else{
+            handleEvent(&event);
+        }
     }
-    return done;
 }
 
 //TODO all input handling will go here
-bool InputManager::handleEvent(SDL_Event * event){
-    if(event->type == SDL_QUIT){
-        return true;
-    }
-    return false;
+void InputManager::handleEvent(SDL_Event * event){
+
 }

+ 12 - 5
src/sceneManager.cpp

@@ -5,7 +5,8 @@ SceneManager::SceneManager(){}
 SceneManager::~SceneManager(){}
 
 bool SceneManager::startUp(){
-    if (!loadScene("teapot")){
+    currentSceneID = "teapot";
+    if (!loadScene(currentSceneID)){
         printf("Could not load scene. No models succesfully loaded!\n");
         return false;
     }
@@ -16,10 +17,16 @@ void SceneManager::shutDown(){
     delete currentScene;
 }
 
-//Not implemented yet, but I will want to do this in the future
-bool SceneManager::switchScene(std::string sceneID){
-    delete currentScene;
-    return loadScene(sceneID);
+bool SceneManager::switchScene(std::string newSceneID){
+    if( newSceneID != currentSceneID ){
+        currentSceneID = newSceneID;
+        delete currentScene;
+        return loadScene(newSceneID);
+    }
+    else{
+        printf("Selected already loaded scene.\n");
+        return true;
+    }
 }
 
 //Loads the given scene and all related textures