Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1.  
  2. /////////////////////////////////////////////////////////
  3. /// Pops a Scene off from the stack
  4. /////////////////////////////////////////////////////////
  5. void SceneManager::popScene()
  6. {
  7.     if(scenes.size() > 0)
  8.     {
  9.         Debugger &debugger = Debugger::GetSharedInstance();
  10.  
  11.         if(currentScene != 0)
  12.         {
  13.             debugger.log("Releasing Scene: " + std::string(typeid(*currentScene).name()));
  14.  
  15.             currentScene->sceneWillBePoppedOff(); // notify the scene
  16.             currentScene->release(); // release any memory that the scene may contain.
  17.             delete currentScene;
  18.  
  19.             debugger.log("Popping off Scene: " + std::string(typeid(*currentScene).name()));
  20.         }
  21.  
  22.         scenes.pop(); // HERE IS EXCEPTION!!
  23.  
  24.         if(scenes.size() > 0)
  25.         {
  26.             setCurrentScene(scenes.top());
  27.         }
  28.         else
  29.         {
  30.             setCurrentScene(0);
  31.         }
  32.     }
  33. }
  34.  
  35.  
  36. /////////////////////////////////////////////////////////
  37. /// Pops of every Scene in the SceneManager.
  38. /////////////////////////////////////////////////////////
  39. void SceneManager::popAllScenes()
  40. {
  41.     while(!scenes.empty())
  42.     {
  43.         popScene();
  44.     }
  45. }
  46.  
  47.  
  48. /////////////////////////////////////////////////////////
  49. /// Pushes a Scene off from the Stack.
  50. /// \param scene A pointer to a Scene, this must be allocated from the heap.
  51. /////////////////////////////////////////////////////////
  52. void SceneManager::pushScene(Scene *scene)
  53. {
  54.     if(scene == 0)
  55.     {
  56.         throw AnaxNullPointerDereferenceException(__FUNCTION__);
  57.     }
  58.  
  59.     // Since all priorities push on the stack... Won't push in the switch case
  60.     switch(scene->getPriorityLevel())
  61.     {
  62.         /// A <i>Low</i> priority implies that the last Scene will be <i>kept</i> on the Stack
  63.         /// and this Scene will be pushed on.
  64.     case Priority::Low:
  65.         break;
  66.  
  67.         /// A <i>Medium</i> priority implies that only the last Scene on the stack should be popped off and this
  68.         /// Scene pushed on.
  69.     case Priority::Medium:
  70.         popScene(); // Pop the current scene
  71.         break;
  72.  
  73.         /// A <i>High</i> priority implies that all the Scene's on the stack should be popped off
  74.         /// and this Scene will be pushed on.
  75.     case Priority::High:
  76.         // Pop of all the scenes
  77.         popAllScenes();
  78.         break;
  79.     }
  80.  
  81.     // Instead we'll push here
  82.     scenes.push(scene);
  83.     setCurrentScene(scenes.top());
  84.  
  85.  
  86.    
  87.     Debugger::GetSharedInstance().log("Starting up Current Scene: " + std::string(typeid(*currentScene).name()));
  88.  
  89.     // Setup the Scene
  90.     currentScene->start();
  91. }
Add Comment
Please, Sign In to add comment