From: Ingo Ruhnke Date: Thu, 19 Nov 2009 04:51:31 +0000 (+0000) Subject: Turned main.cpp into a class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e2797515b41729a64a043cbd997be575ebc7307d;p=supertux.git Turned main.cpp into a class Switched to Renderer::instance()->apply_config() to switch video mode (which doesn't yet work as apply_config() is incomplete) SVN-Revision: 6043 --- diff --git a/TODO b/TODO index b8c522bb7..31d6cce93 100644 --- a/TODO +++ b/TODO @@ -97,6 +97,6 @@ TODO * centralize menus -* make a proper class out of supertux/resources.hpp +* Renderer::apply_config() needs to handle fullscreen switching # EOF # diff --git a/src/main.cpp b/src/main.cpp index 09924a94c..b8b8cba03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { - return supertux_main(argc, argv); + return Main().main(argc, argv); } /* EOF */ diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index cfb3d08d1..10744f3a3 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "supertux/main.hpp" + #include #include @@ -50,7 +52,8 @@ namespace supertux_apple { namespace { DrawingContext *context_pointer; } -static void init_config() +void +Main::init_config() { g_config = new Config(); try { @@ -60,7 +63,8 @@ static void init_config() } } -static void init_tinygettext() +void +Main::init_tinygettext() { tinygettext::Log::set_log_info_callback(0); dictionary_manager.set_filesystem(std::auto_ptr(new PhysFSFileSystem)); @@ -74,7 +78,8 @@ static void init_tinygettext() } } -static void init_physfs(const char* argv0) + void +Main::init_physfs(const char* argv0) { if(!PHYSFS_init(argv0)) { std::stringstream msg; @@ -196,7 +201,8 @@ static void init_physfs(const char* argv0) PHYSFS_freeList(searchpath); } -static void print_usage(const char* argv0) +void +Main::print_usage(const char* argv0) { fprintf(stderr, _("Usage: %s [OPTIONS] [LEVELFILE]\n\n"), argv0); fprintf(stderr, @@ -224,7 +230,8 @@ static void print_usage(const char* argv0) /** * Options that should be evaluated prior to any initializations at all go here */ -static bool pre_parse_commandline(int argc, char** argv) +bool +Main::pre_parse_commandline(int argc, char** argv) { for(int i = 1; i < argc; ++i) { std::string arg = argv[i]; @@ -245,7 +252,8 @@ static bool pre_parse_commandline(int argc, char** argv) /** * Options that should be evaluated after config is read go here */ -static bool parse_commandline(int argc, char** argv) +bool +Main::parse_commandline(int argc, char** argv) { for(int i = 1; i < argc; ++i) { std::string arg = argv[i]; @@ -374,7 +382,8 @@ static bool parse_commandline(int argc, char** argv) return false; } -static void init_sdl() +void +Main::init_sdl() { if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { std::stringstream msg; @@ -394,7 +403,8 @@ static void init_sdl() ; } -static void init_rand() +void +Main::init_rand() { g_config->random_seed = systemRandom.srand(g_config->random_seed); @@ -402,7 +412,8 @@ static void init_rand() //log_info << "Using random seed " << config->random_seed << how << std::endl; } -void init_video() +void +Main::init_video() { // FIXME: Add something here SCREEN_WIDTH = 800; @@ -444,7 +455,8 @@ void init_video() << " Area: " << g_config->aspect_width << "x" << g_config->aspect_height << std::endl; } -static void init_audio() +void +Main::init_audio() { sound_manager = new SoundManager(); @@ -452,7 +464,8 @@ static void init_audio() sound_manager->enable_music(g_config->music_enabled); } -static void quit_audio() +void +Main::quit_audio() { if(sound_manager != NULL) { delete sound_manager; @@ -460,7 +473,8 @@ static void quit_audio() } } -void wait_for_event(float min_delay, float max_delay) +void +Main::wait_for_event(float min_delay, float max_delay) { assert(min_delay <= max_delay); @@ -521,17 +535,8 @@ static inline void timelog(const char* ) } #endif -std::istream* physfs_open_file(const char* name) -{ - return new IFileStream(name); -} - -void physfs_free_list(char** name) -{ - PHYSFS_freeList(name); -} - -int supertux_main(int argc, char** argv) +int +Main::main(int argc, char** argv) { int result = 0; diff --git a/src/supertux/main.hpp b/src/supertux/main.hpp index e034feb3d..4f231d1de 100644 --- a/src/supertux/main.hpp +++ b/src/supertux/main.hpp @@ -17,10 +17,25 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_MAIN_HPP #define HEADER_SUPERTUX_SUPERTUX_MAIN_HPP -void init_video(); -void wait_for_event(float min_delay, float max_delay); +class Main +{ +private: + void init_config(); + void init_tinygettext(); + void init_physfs(const char* argv0); + void print_usage(const char* argv0); + bool parse_commandline(int argc, char** argv); + void init_sdl(); + void init_rand(); + void init_audio(); + void quit_audio(); + bool pre_parse_commandline(int argc, char** argv); -int supertux_main(int argc, char** argv); +public: + int main(int argc, char** argv); + void init_video(); + void wait_for_event(float min_delay, float max_delay); +}; #endif diff --git a/src/supertux/mainloop.cpp b/src/supertux/mainloop.cpp index 3fd159020..c5ac1f64d 100644 --- a/src/supertux/mainloop.cpp +++ b/src/supertux/mainloop.cpp @@ -222,7 +222,7 @@ MainLoop::process_events() if (event.key.keysym.sym == SDLK_F11) { g_config->use_fullscreen = !g_config->use_fullscreen; - init_video(); + Renderer::instance()->apply_config(); MenuManager::recalc_pos(); } else if (event.key.keysym.sym == SDLK_PRINT || diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index 46c504e49..9d5b021c2 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -214,7 +214,7 @@ OptionsMenu::menu_action(MenuItem* item) case MNID_FULLSCREEN: if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) { g_config->use_fullscreen = !g_config->use_fullscreen; - init_video(); // FIXME: Should call apply_config instead + Renderer::instance()->apply_config(); MenuManager::recalc_pos(); g_config->save(); }