Fix for coverity #29386
[supertux.git] / src / supertux / game_session.cpp
index 8b0794c..57e48e4 100644 (file)
@@ -30,6 +30,8 @@
 #include "object/endsequence_walkright.hpp"
 #include "object/level_time.hpp"
 #include "object/player.hpp"
+#include "scripting/scripting.hpp"
+#include "scripting/squirrel_util.hpp"
 #include "scripting/squirrel_util.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
@@ -247,6 +249,7 @@ GameSession::toggle_pause()
     speed_before_pause = ScreenManager::current()->get_speed();
     ScreenManager::current()->set_speed(0);
     MenuManager::instance().set_menu(MenuStorage::GAME_MENU);
+    SoundManager::current()->pause_music();
     game_pause = true;
   }
 
@@ -417,12 +420,14 @@ void
 GameSession::update(float elapsed_time)
 {
   // handle controller
-  if(InputManager::current()->get_controller()->pressed(Controller::PAUSE_MENU))
+  if(InputManager::current()->get_controller()->pressed(Controller::ESCAPE) ||
+     InputManager::current()->get_controller()->pressed(Controller::START))
   {
     on_escape_press();
   }
 
-  if(InputManager::current()->get_controller()->pressed(Controller::CHEAT_MENU))
+  if(InputManager::current()->get_controller()->pressed(Controller::CHEAT_MENU) &&
+     g_config->developer_mode)
   {
     if (!MenuManager::instance().is_active())
     {
@@ -436,6 +441,7 @@ GameSession::update(float elapsed_time)
   // Unpause the game if the menu has been closed
   if (game_pause && !MenuManager::instance().is_active()) {
     ScreenManager::current()->set_speed(speed_before_pause);
+    SoundManager::current()->resume_music();
     game_pause = false;
   }
 
@@ -474,8 +480,11 @@ GameSession::update(float elapsed_time)
     }
   }
 
+  if(currentsector == NULL)
+    return;
+  
   // update sounds
-  if (currentsector && currentsector->camera) SoundManager::current()->set_listener_position(currentsector->camera->get_center());
+  if (currentsector->camera) SoundManager::current()->set_listener_position(currentsector->camera->get_center());
 
   /* Handle music: */
   if (end_sequence)
@@ -563,12 +572,12 @@ GameSession::start_sequence(const std::string& sequencename)
 
   if (sequencename == "endsequence") {
     if (currentsector->get_players()[0]->get_physic().get_velocity_x() < 0) {
-      end_sequence = new EndSequenceWalkLeft();
+      end_sequence = std::make_shared<EndSequenceWalkLeft>();
     } else {
-      end_sequence = new EndSequenceWalkRight();
+      end_sequence = std::make_shared<EndSequenceWalkRight>();
     }
   } else if (sequencename == "fireworks") {
-    end_sequence = new EndSequenceFireworks();
+    end_sequence = std::make_shared<EndSequenceFireworks>();
   } else {
     log_warning << "Unknown sequence '" << sequencename << "'. Ignoring." << std::endl;
     return;
@@ -584,12 +593,12 @@ GameSession::start_sequence(const std::string& sequencename)
   currentsector->player->set_winning();
 
   // Stop all clocks.
-  for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
+  for(auto i = currentsector->gameobjects.begin();
       i != currentsector->gameobjects.end(); ++i)
   {
-    GameObject* obj = *i;
+    GameObjectPtr obj = *i;
 
-    LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+    auto lt = std::dynamic_pointer_cast<LevelTime>(obj);
     if(lt)
       lt->stop();
   }