X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmain.cpp;h=3907d4e66ab17f7cbcfb62a5f0ad114f51867d68;hb=eb87b07de097463cf91cf76be9bbc6b9fc0cad98;hp=c1364da12cb53cb4173b1c7cf791dc6de540a306;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/main.cpp b/src/main.cpp index c1364da12..3907d4e66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #include +#include #include "main.h" @@ -31,25 +31,33 @@ #include #include #include +#include #ifndef WIN32 #include #endif #include #include #include +#include #include "gameconfig.h" #include "resources.h" -#include "app/globals.h" -#include "app/setup.h" -#include "app/gettext.h" +#include "gettext.h" #include "audio/sound_manager.h" +#include "video/surface.h" #include "control/joystickkeyboardcontroller.h" #include "misc.h" +#include "title.h" #include "game_session.h" +#include "file_system.h" + +#ifdef WIN32 +#define mkdir(dir, mode) mkdir(dir) +#endif SDL_Surface* screen = 0; JoystickKeyboardController* main_controller = 0; +TinyGetText::DictionaryManager dictionary_manager; static void init_config() { @@ -76,12 +84,6 @@ static void find_directories() user_dir = home; user_dir += "/.supertux"; - // Remove .supertux config file from old versions - if(FileSystem::faccessible(user_dir)) { - std::cerr << "Removing old config file " << user_dir << "\n"; - remove(user_dir.c_str()); - } - // create directories std::string savedir = user_dir + "/save"; mkdir(user_dir.c_str(), 0755); @@ -168,6 +170,18 @@ static void parse_commandline(int argc, char** argv) } } else if(arg == "--show-fps") { config->show_fps = true; + } else if(arg == "--play-demo") { + if(i+1 >= argc) { + print_usage(argv[0]); + throw std::runtime_error("Need to specify a demo filename"); + } + config->start_demo = argv[++i]; + } else if(arg == "--record-demo") { + if(i+1 >= argc) { + print_usage(argv[0]); + throw std::runtime_error("Need to specify a demo filename"); + } + config->record_demo = argv[++i]; } else if(arg == "--help") { print_usage(argv[0]); throw std::runtime_error(""); @@ -194,6 +208,13 @@ static void init_sdl() } SDL_EnableUNICODE(1); + + // wait 100ms and clear SDL event queue because sometimes we have random + // joystick events in the queue on startup... + SDL_Delay(100); + SDL_Event dummy; + while(SDL_PollEvent(&dummy)) + ; } static void check_gl_error() @@ -324,6 +345,40 @@ static void quit_audio() } } +void wait_for_event(float min_delay, float max_delay) +{ + assert(min_delay <= max_delay); + + Uint32 min = (Uint32) (min_delay * 1000); + Uint32 max = (Uint32) (max_delay * 1000); + + SDL_Delay(min); + + // clear even queue + SDL_Event event; + while (SDL_PollEvent(&event)) + {} + + /* Handle events: */ + bool running = false; + Uint32 ticks = SDL_GetTicks(); + while(running) { + while(SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_QUIT: + throw std::runtime_error("received window close"); + case SDL_KEYDOWN: + case SDL_JOYBUTTONDOWN: + case SDL_MOUSEBUTTONDOWN: + running = false; + } + } + if(SDL_GetTicks() - ticks >= (max - min)) + running = false; + SDL_Delay(10); + } +} + int main(int argc, char** argv) { #ifndef DEBUG // we want backtraces in debug mode so don't catch exceptions @@ -343,6 +398,10 @@ int main(int argc, char** argv) load_shared(); if(config->start_level != "") { GameSession session(config->start_level, ST_GL_LOAD_LEVEL_FILE); + if(config->start_demo != "") + session.play_demo(config->start_demo); + if(config->record_demo != "") + session.record_demo(config->record_demo); session.run(); } else { // normal game