X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=6b9a79766e97280f0725dfb7ee1b9a8c211932c9;hb=07ddaed2a657e4d2a3d038fed223fc5827159caf;hp=53152b35a8edac639eed02da7d9aaf47ddf02658;hpb=cfa6a410943ae4fee8d5d8c5270f7119a82fe970;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index 53152b35a..6b9a79766 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -1,9 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2000 Bill Kendrick -// Copyright (C) 2004 Tobias Glaesser -// Copyright (C) 2004 Ingo Ruhnke +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -14,7 +12,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -35,7 +33,7 @@ #include #include "game_session.hpp" -#include "msg.hpp" +#include "log.hpp" #include "worldmap.hpp" #include "mainloop.hpp" #include "video/screen.hpp" @@ -55,7 +53,6 @@ #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "resources.hpp" -#include "worldmap.hpp" #include "misc.hpp" #include "statistics.hpp" #include "timer.hpp" @@ -67,7 +64,7 @@ #include "file_system.hpp" #include "gameconfig.hpp" #include "gettext.hpp" -#include "exceptions.hpp" +#include "console.hpp" #include "flip_level_transformer.hpp" // the engine will be run with a logical framerate of 64fps. @@ -80,11 +77,6 @@ namespace { "foo", "whereami", "camera", - "grow", - "fire", - "ice", - "coins", - "numberofthebeast", "grease", "invincible", "mortal", @@ -116,10 +108,10 @@ GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode, fps_fps = 0; for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) { - Console::registerCommand(consoleCommands[i], this); + Console::instance->registerCommand(consoleCommands[i], this); } - statistics_backdrop = new Surface("images/engine/menu/score-backdrop.png"); + statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png")); restart_level(true); } @@ -132,10 +124,9 @@ GameSession::restart_level(bool fromBeginning) main_controller->reset(); - delete level; currentsector = 0; - level = new Level; + level.reset(new Level); level->load(levelfile); global_stats.reset(); @@ -192,12 +183,6 @@ GameSession::~GameSession() delete demo_controller; delete end_sequence_controller; - delete level; - for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) { - Console::unregisterCommand(consoleCommands[i], this); - } - - delete statistics_backdrop; current_ = NULL; } @@ -351,10 +336,10 @@ GameSession::process_events() } bool -GameSession::consoleCommand(std::string command, std::vector arguments) +GameSession::consoleCommand(std::string command, std::vector) { if (command == "foo") { - msg_info << "bar" << std::endl; + log_info << "bar" << std::endl; return true; } @@ -363,30 +348,6 @@ GameSession::consoleCommand(std::string command, std::vector argume // Cheating words (the goal of this is really for debugging, // but could be used for some cheating, nothing wrong with that) - if (command == "grow") { - tux.set_bonus(GROWUP_BONUS, false); - return true; - } - if (command == "fire") { - tux.set_bonus(FIRE_BONUS, false); - return true; - } - if (command == "ice") { - tux.set_bonus(ICE_BONUS, false); - return true; - } - if (command == "coins") { - if ((arguments.size() < 1) || (!Console::string_is(arguments[0]))) { - msg_info << "Usage: coins " << std::endl; - } else { - player_status->coins = Console::string_to(arguments[0]); - } - return true; - } - if (command == "numberofthebeast") { - player_status->coins += 55; - return true; - } if (command == "grease") { tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3); return true; @@ -415,7 +376,7 @@ GameSession::consoleCommand(std::string command, std::vector argume return true; } if (command == "whereami") { - msg_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl; + log_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl; return true; } if (command == "gotoend") { @@ -436,7 +397,7 @@ GameSession::consoleCommand(std::string command, std::vector argume return true; } if (command == "camera") { - msg_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl; + log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl; return true; } if (command == "quit") { @@ -505,8 +466,6 @@ GameSession::process_menu() main_loop->exit_screen(); break; } - } else if(menu == options_menu) { - process_options_menu(); } } } @@ -539,7 +498,7 @@ GameSession::update(float elapsed_time) if(newsector != "" && newspawnpoint != "") { Sector* sector = level->get_sector(newsector); if(sector == 0) { - msg_warning << "Sector '" << newsector << "' not found" << std::endl; + log_warning << "Sector '" << newsector << "' not found" << std::endl; } sector->activate(newspawnpoint); sector->play_music(LEVEL_MUSIC); @@ -563,11 +522,17 @@ GameSession::update(float elapsed_time) sound_manager->set_listener_position(currentsector->player->get_pos()); /* Handle music: */ - if (currentsector->player->invincible_timer.started() && - currentsector->player->invincible_timer.get_timeleft() - > TUX_INVINCIBLE_TIME_WARNING && !end_sequence) { - currentsector->play_music(HERRING_MUSIC); - } else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence) { + if (end_sequence) + return; + + if(currentsector->player->invincible_timer.started()) { + if(currentsector->player->invincible_timer.get_timeleft() <= + TUX_INVINCIBLE_TIME_WARNING) { + currentsector->play_music(HERRING_WARNING_MUSIC); + } else { + currentsector->play_music(HERRING_MUSIC); + } + } else if(currentsector->get_music_type() != LEVEL_MUSIC) { currentsector->play_music(LEVEL_MUSIC); } } @@ -728,12 +693,13 @@ GameSession::display_info_box(const std::string& text) while(running) { + // TODO make a screen out of this, another mainloop is ugly main_controller->update(); SDL_Event event; while (SDL_PollEvent(&event)) { main_controller->process_event(event); if(event.type == SDL_QUIT) - throw graceful_shutdown(); + main_loop->quit(); } if(main_controller->pressed(Controller::JUMP) @@ -804,12 +770,12 @@ GameSession::start_sequence(const std::string& sequencename) } } else if(sequencename == "stoptux") { if(!end_sequence) { - msg_warning << "Final target reached without an active end sequence" << std::endl; + log_warning << "Final target reached without an active end sequence" << std::endl; this->start_sequence("endsequence"); } end_sequence = ENDSEQUENCE_WAITING; } else { - msg_warning << "Unknown sequence '" << sequencename << "'" << std::endl; + log_warning << "Unknown sequence '" << sequencename << "'" << std::endl; } } @@ -829,7 +795,7 @@ GameSession::drawstatus(DrawingContext& context) // draw level stats while end_sequence is running if (end_sequence) { - global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop); + global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get()); } }