From 0c8a4a23f06aaa461d51c0ba21e5db5cd3427d8a Mon Sep 17 00:00:00 2001 From: grumbel Date: Thu, 19 Nov 2009 16:50:58 +0000 Subject: [PATCH] Renamed MainLoop to ScreenManager git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6050 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/supertux/game_session.cpp | 20 ++++++------- src/supertux/levelintro.cpp | 4 +-- src/supertux/main.cpp | 18 ++++++------ src/supertux/menu/contrib_world_menu.cpp | 4 +-- src/supertux/{mainloop.cpp => screen_manager.cpp} | 36 +++++++++++------------ src/supertux/{mainloop.hpp => screen_manager.hpp} | 8 ++--- src/supertux/textscroller.cpp | 6 ++-- src/supertux/title_screen.cpp | 12 ++++---- src/supertux/world.cpp | 4 +-- 9 files changed, 55 insertions(+), 57 deletions(-) rename src/supertux/{mainloop.cpp => screen_manager.cpp} (90%) rename src/supertux/{mainloop.hpp => screen_manager.hpp} (95%) diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 001b5e7ed..94eedd53b 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -34,7 +34,7 @@ #include "supertux/gameconfig.hpp" #include "supertux/levelintro.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/menu/menu_storage.hpp" #include "supertux/menu/game_menu.hpp" #include "supertux/menu/options_menu.hpp" @@ -71,7 +71,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) currentsector = NULL; game_pause = false; - speed_before_pause = g_main_loop->get_speed(); + speed_before_pause = g_screen_manager->get_speed(); statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png")); @@ -122,7 +122,7 @@ GameSession::restart_level() } } catch(std::exception& e) { log_fatal << "Couldn't start level: " << e.what() << std::endl; - g_main_loop->exit_screen(); + g_screen_manager->exit_screen(); } sound_manager->stop_music(); @@ -236,8 +236,8 @@ GameSession::toggle_pause() { // pause if(!game_pause) { - speed_before_pause = g_main_loop->get_speed(); - g_main_loop->set_speed(0); + speed_before_pause = g_screen_manager->get_speed(); + g_screen_manager->set_speed(0); MenuManager::set_current(game_menu.get()); game_menu->set_active_item(MNID_CONTINUE); game_pause = true; @@ -393,7 +393,7 @@ GameSession::process_menu() break; case MNID_ABORTLEVEL: MenuManager::set_current(0); - g_main_loop->exit_screen(); + g_screen_manager->exit_screen(); break; } } @@ -415,7 +415,7 @@ GameSession::setup() if (!levelintro_shown) { levelintro_shown = true; - g_main_loop->push_screen(new LevelIntro(level.get(), best_level_statistics)); + g_screen_manager->push_screen(new LevelIntro(level.get(), best_level_statistics)); } } @@ -431,7 +431,7 @@ GameSession::update(float elapsed_time) // Unpause the game if the menu has been closed if (game_pause && !MenuManager::current()) { - g_main_loop->set_speed(speed_before_pause); + g_screen_manager->set_speed(speed_before_pause); game_pause = false; } @@ -504,7 +504,7 @@ GameSession::finish(bool win) WorldMap::current()->finished_level(level.get()); } - g_main_loop->exit_screen(); + g_screen_manager->exit_screen(); } void @@ -564,7 +564,7 @@ GameSession::start_sequence(const std::string& sequencename) } /* slow down the game for end-sequence */ - g_main_loop->set_speed(0.5f); + g_screen_manager->set_speed(0.5f); currentsector->add_object(end_sequence); end_sequence->start(); diff --git a/src/supertux/levelintro.cpp b/src/supertux/levelintro.cpp index 821699576..f7cb7d8da 100644 --- a/src/supertux/levelintro.cpp +++ b/src/supertux/levelintro.cpp @@ -21,7 +21,7 @@ #include "sprite/sprite_manager.hpp" #include "supertux/fadeout.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/resources.hpp" #include "util/gettext.hpp" @@ -56,7 +56,7 @@ LevelIntro::update(float elapsed_time) || g_main_controller->pressed(Controller::ACTION) || g_main_controller->pressed(Controller::MENU_SELECT) || g_main_controller->pressed(Controller::PAUSE_MENU)) { - g_main_loop->exit_screen(new FadeOut(0.1)); + g_screen_manager->exit_screen(new FadeOut(0.1)); } player_sprite_py += player_sprite_vy * elapsed_time; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 10744f3a3..0314797eb 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -42,7 +42,7 @@ namespace supertux_apple { #include "scripting/squirrel_util.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/resources.hpp" #include "supertux/title_screen.hpp" #include "util/file_system.hpp" @@ -499,7 +499,7 @@ Main::wait_for_event(float min_delay, float max_delay) while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: - g_main_loop->quit(); + g_screen_manager->quit(); break; case SDL_KEYDOWN: case SDL_JOYBUTTONDOWN: @@ -583,7 +583,7 @@ Main::main(int argc, char** argv) timelog(0); - g_main_loop = new MainLoop(); + g_screen_manager = new ScreenManager(); if(g_config->start_level != "") { // we have a normal path specified at commandline, not a physfs path. // So we simply mount that path here... @@ -594,7 +594,7 @@ Main::main(int argc, char** argv) if(g_config->start_level.size() > 4 && g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) { init_rand(); - g_main_loop->push_screen(new WorldMapNS::WorldMap( + g_screen_manager->push_screen(new WorldMapNS::WorldMap( FileSystem::basename(g_config->start_level))); } else { init_rand();//If level uses random eg. for @@ -610,15 +610,15 @@ Main::main(int argc, char** argv) if(g_config->record_demo != "") session->record_demo(g_config->record_demo); - g_main_loop->push_screen(session.release()); + g_screen_manager->push_screen(session.release()); } } else { init_rand(); - g_main_loop->push_screen(new TitleScreen()); + g_screen_manager->push_screen(new TitleScreen()); } //init_rand(); PAK: this call might subsume the above 3, but I'm chicken! - g_main_loop->run(context); + g_screen_manager->run(context); } catch(std::exception& e) { log_fatal << "Unexpected exception: " << e.what() << std::endl; result = 1; @@ -627,8 +627,8 @@ Main::main(int argc, char** argv) result = 1; } - delete g_main_loop; - g_main_loop = NULL; + delete g_screen_manager; + g_screen_manager = NULL; Resources::unload_shared(); quit_audio(); diff --git a/src/supertux/menu/contrib_world_menu.cpp b/src/supertux/menu/contrib_world_menu.cpp index fdb84c589..b3e0fe116 100644 --- a/src/supertux/menu/contrib_world_menu.cpp +++ b/src/supertux/menu/contrib_world_menu.cpp @@ -18,7 +18,7 @@ #include "audio/sound_manager.hpp" #include "gui/menu_item.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/title_screen.hpp" #include "supertux/world.hpp" #include "util/gettext.hpp" @@ -50,7 +50,7 @@ ContribWorldMenu::check_menu() { sound_manager->stop_music(); GameSession* session = new GameSession(m_current_world.get_level_filename(index)); - g_main_loop->push_screen(session); + g_screen_manager->push_screen(session); } } } diff --git a/src/supertux/mainloop.cpp b/src/supertux/screen_manager.cpp similarity index 90% rename from src/supertux/mainloop.cpp rename to src/supertux/screen_manager.cpp index c5ac1f64d..2b4478ecc 100644 --- a/src/supertux/mainloop.cpp +++ b/src/supertux/screen_manager.cpp @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" @@ -42,9 +42,9 @@ static const int MAX_FRAME_SKIP = 2; float g_game_speed = 1.0f; -MainLoop* g_main_loop = NULL; +ScreenManager* g_screen_manager = NULL; -MainLoop::MainLoop() : +ScreenManager::ScreenManager() : waiting_threads(), running(), speed(1.0), @@ -62,7 +62,7 @@ MainLoop::MainLoop() : TimeScheduler::instance = new TimeScheduler(); } -MainLoop::~MainLoop() +ScreenManager::~ScreenManager() { using namespace Scripting; delete TimeScheduler::instance; @@ -75,7 +75,7 @@ MainLoop::~MainLoop() } void -MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade) +ScreenManager::push_screen(Screen* screen, ScreenFade* screen_fade) { this->next_screen.reset(screen); this->screen_fade.reset(screen_fade); @@ -85,7 +85,7 @@ MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade) } void -MainLoop::exit_screen(ScreenFade* screen_fade) +ScreenManager::exit_screen(ScreenFade* screen_fade) { next_screen.reset(NULL); this->screen_fade.reset(screen_fade); @@ -94,13 +94,13 @@ MainLoop::exit_screen(ScreenFade* screen_fade) } void -MainLoop::set_screen_fade(ScreenFade* screen_fade) +ScreenManager::set_screen_fade(ScreenFade* screen_fade) { this->screen_fade.reset(screen_fade); } void -MainLoop::quit(ScreenFade* screen_fade) +ScreenManager::quit(ScreenFade* screen_fade) { for(std::vector::iterator i = screen_stack.begin(); i != screen_stack.end(); ++i) @@ -111,25 +111,25 @@ MainLoop::quit(ScreenFade* screen_fade) } void -MainLoop::set_speed(float speed) +ScreenManager::set_speed(float speed) { this->speed = speed; } float -MainLoop::get_speed() const +ScreenManager::get_speed() const { return speed; } bool -MainLoop::has_no_pending_fadeout() const +ScreenManager::has_no_pending_fadeout() const { return screen_fade.get() == NULL || screen_fade->done(); } void -MainLoop::draw_fps(DrawingContext& context, float fps_fps) +ScreenManager::draw_fps(DrawingContext& context, float fps_fps) { char str[60]; snprintf(str, sizeof(str), "%3.1f", fps_fps); @@ -141,7 +141,7 @@ MainLoop::draw_fps(DrawingContext& context, float fps_fps) } void -MainLoop::draw(DrawingContext& context) +ScreenManager::draw(DrawingContext& context) { static Uint32 fps_ticks = SDL_GetTicks(); static int frame_count = 0; @@ -178,7 +178,7 @@ MainLoop::draw(DrawingContext& context) } void -MainLoop::update_gamelogic(float elapsed_time) +ScreenManager::update_gamelogic(float elapsed_time) { Scripting::update_debugger(); Scripting::TimeScheduler::instance->update(game_time); @@ -191,7 +191,7 @@ MainLoop::update_gamelogic(float elapsed_time) } void -MainLoop::process_events() +ScreenManager::process_events() { g_main_controller->update(); Uint8* keystate = SDL_GetKeyState(NULL); @@ -244,7 +244,7 @@ MainLoop::process_events() } void -MainLoop::handle_screen_switch() +ScreenManager::handle_screen_switch() { while( (next_screen.get() != NULL || nextpop) && has_no_pending_fadeout()) { @@ -279,7 +279,7 @@ MainLoop::handle_screen_switch() } void -MainLoop::run(DrawingContext &context) +ScreenManager::run(DrawingContext &context) { Uint32 last_ticks = 0; Uint32 elapsed_ticks = 0; @@ -334,7 +334,7 @@ MainLoop::run(DrawingContext &context) } void -MainLoop::take_screenshot() +ScreenManager::take_screenshot() { screenshot_requested = true; } diff --git a/src/supertux/mainloop.hpp b/src/supertux/screen_manager.hpp similarity index 95% rename from src/supertux/mainloop.hpp rename to src/supertux/screen_manager.hpp index 7f7b78fe4..09acd6afd 100644 --- a/src/supertux/mainloop.hpp +++ b/src/supertux/screen_manager.hpp @@ -29,11 +29,11 @@ class DrawingContext; /** * Manages, updates and draws all Screens, Controllers, Menus and the Console. */ -class MainLoop +class ScreenManager { public: - MainLoop(); - ~MainLoop(); + ScreenManager(); + ~ScreenManager(); void run(DrawingContext &context); void exit_screen(ScreenFade* fade = NULL); @@ -76,7 +76,7 @@ private: bool screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */ }; -extern MainLoop* g_main_loop; +extern ScreenManager* g_screen_manager; #endif diff --git a/src/supertux/textscroller.cpp b/src/supertux/textscroller.cpp index 48725fb7c..8d5db1ace 100644 --- a/src/supertux/textscroller.cpp +++ b/src/supertux/textscroller.cpp @@ -22,7 +22,7 @@ #include "supertux/fadeout.hpp" #include "supertux/info_box_line.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/resources.hpp" #include "util/reader.hpp" #include "video/drawing_context.hpp" @@ -102,7 +102,7 @@ TextScroller::update(float elapsed_time) || g_main_controller->pressed(Controller::MENU_SELECT)) scroll += SCROLL; if(g_main_controller->pressed(Controller::PAUSE_MENU)) { - g_main_loop->exit_screen(new FadeOut(0.5)); + g_screen_manager->exit_screen(new FadeOut(0.5)); } scroll += speed * elapsed_time; @@ -129,7 +129,7 @@ TextScroller::draw(DrawingContext& context) if(y < 0 && !fading ) { fading = true; - g_main_loop->exit_screen(new FadeOut(0.5)); + g_screen_manager->exit_screen(new FadeOut(0.5)); } } diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index afbc71730..df3ab3ccf 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -15,10 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include "supertux/title_screen.hpp" - #include "audio/sound_manager.hpp" #include "gui/menu_manager.hpp" #include "lisp/parser.hpp" @@ -27,7 +25,7 @@ #include "supertux/fadeout.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/menu/addon_menu.hpp" #include "supertux/menu/contrib_world_menu.hpp" #include "supertux/menu/contrib_menu.hpp" @@ -189,7 +187,7 @@ TitleScreen::draw(DrawingContext& context) void TitleScreen::update(float elapsed_time) { - g_main_loop->set_speed(0.6f); + g_screen_manager->set_speed(0.6f); Sector* sector = titlesession->get_current_sector(); sector->update(elapsed_time); @@ -223,12 +221,12 @@ TitleScreen::update(float elapsed_time) case MNID_CREDITS: MenuManager::set_current(NULL); - g_main_loop->push_screen(new TextScroller("credits.txt"), + g_screen_manager->push_screen(new TextScroller("credits.txt"), new FadeOut(0.5)); break; case MNID_QUITMAINMENU: - g_main_loop->quit(new FadeOut(0.25)); + g_screen_manager->quit(new FadeOut(0.25)); sound_manager->stop_music(0.25); break; } @@ -243,7 +241,7 @@ TitleScreen::update(float elapsed_time) // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) - if(MenuManager::current() == 0 && g_main_loop->has_no_pending_fadeout()) { + if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout()) { generate_main_menu(); MenuManager::set_current(main_menu.get()); } diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index a8fda6ba7..07de751ba 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -19,7 +19,7 @@ #include "physfs/ifile_stream.hpp" #include "scripting/serialize.hpp" #include "scripting/squirrel_util.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/player_status.hpp" #include "supertux/world.hpp" #include "util/file_system.hpp" @@ -151,7 +151,7 @@ World::run() } catch(std::exception& ) { // fallback: try to load worldmap worldmap.stwm using namespace WorldMapNS; - g_main_loop->push_screen(new WorldMap(basedir + "worldmap.stwm")); + g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm")); } } -- 2.11.0