[Super-tux-commit] supertux/src gameloop.cpp,1.201,1.202 gameloop.h,1.64,1.65 level.cpp,1.108,1.109
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12128/src Modified Files: gameloop.cpp gameloop.h level.cpp level.h level_subset.cpp resources.cpp resources.h title.cpp worldmap.cpp Log Message: make supertux accepts normal paths on the commandline Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.201 retrieving revision 1.202 diff -u -d -r1.201 -r1.202 --- gameloop.cpp 24 Nov 2004 18:29:26 -0000 1.201 +++ gameloop.cpp 25 Nov 2004 19:48:25 -0000 1.202 @@ -80,11 +80,11 @@ return false; } -GameSession::GameSession(const std::string& levelname_, int mode, +GameSession::GameSession(const std::string& levelfile_, int mode, bool flip_level_, Statistics* statistics) : level(0), currentsector(0), st_gl_mode(mode), - end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_), - best_level_statistics(statistics) + end_sequence(NO_ENDSEQUENCE), levelfile(levelfile_), + flip_level(flip_level_), best_level_statistics(statistics) { current_ = this; @@ -124,7 +124,7 @@ currentsector = 0; level = new Level; - level->load(levelname); + level->load(levelfile); if(flip_level) level->do_vertical_flip(); @@ -726,7 +726,8 @@ while (exit_status == ES_NONE) { Uint32 ticks = SDL_GetTicks(); float elapsed_time = float(ticks - lastticks) / 1000.; - global_time += elapsed_time; + if(!game_pause) + global_time += elapsed_time; lastticks = ticks; // 40fps is minimum Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.108 retrieving revision 1.109 diff -u -d -r1.108 -r1.109 --- level.cpp 23 Nov 2004 16:28:03 -0000 1.108 +++ level.cpp 25 Nov 2004 19:48:25 -0000 1.109 @@ -62,20 +62,8 @@ } void -Level::load(const std::string& filename) +Level::load(const std::string& filepath) { - std::string filepath; - filepath = st_dir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - filepath = datadir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - std::cerr << "Error: Level: couldn't find level: " << filename << std::endl; - return; - } - } - LispReader* level = LispReader::load(filepath, "supertux-level"); int version = 1; Index: level_subset.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- level_subset.cpp 20 Nov 2004 22:14:38 -0000 1.17 +++ level_subset.cpp 25 Nov 2004 19:48:26 -0000 1.18 @@ -20,10 +20,13 @@ #include <config.h> +#include <sstream> +#include <stdexcept> #include <assert.h> #include <unistd.h> #include "app/setup.h" #include "level.h" +#include "resources.h" #include "app/globals.h" #include "video/surface.h" #include "level_subset.h" @@ -89,14 +92,13 @@ // Check in which directory our subset is located (ie. ~/.supertux/ // or SUPERTUX_DATADIR) - std::string filename; - filename = st_dir + "/levels/" + subset + "/info"; - if (access(filename.c_str(), R_OK) != 0) - { - filename = datadir + "/levels/" + subset + "/info"; - if (access(filename.c_str(), R_OK) != 0) - std::cout << "Error: LevelSubset: couldn't find subset: " << subset << std::endl; - } + std::string filename = get_resource_filename( + std::string("levels/") + subset + "/info"); + if(filename == "") { + std::stringstream msg; + msg << "Couldn't find level subset '" << subset << "'."; + throw new std::runtime_error(msg.str()); + } read_info_file(filename); @@ -115,7 +117,8 @@ for(std::set<std::string>::iterator i = files.begin(); i != files.end(); ++i) { if (has_suffix(*i, ".stl")) - levels.push_back(subset+ "/" + *i); + levels.push_back(get_resource_filename( + std::string("levels/" + subset+ "/" + *i))); } } } @@ -177,5 +180,3 @@ { return levels.size(); } - -/* EOF */ Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- level.h 20 Nov 2004 22:14:38 -0000 1.67 +++ level.h 25 Nov 2004 19:48:26 -0000 1.68 @@ -51,6 +51,7 @@ Level(); ~Level(); + // loads a levelfile void load(const std::string& filename); void save(const std::string& filename); static void create(const std::string& filename); Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- gameloop.h 23 Nov 2004 02:00:33 -0000 1.64 +++ gameloop.h 25 Nov 2004 19:48:25 -0000 1.65 @@ -78,7 +78,7 @@ bool game_pause; - std::string levelname; + std::string levelfile; bool flip_level; // the sector and spawnpoint we shoudl spawn after this frame @@ -93,7 +93,8 @@ DrawingContext* context; Timer2 time_left; - GameSession(const std::string& level, int mode, bool flip_level_ = false, Statistics* statistics = NULL); + GameSession(const std::string& levelfile, int mode, bool flip_level_ = false, + Statistics* statistics = 0); ~GameSession(); /** Enter the busy loop */ Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.132 retrieving revision 1.133 diff -u -d -r1.132 -r1.133 --- title.cpp 23 Nov 2004 02:00:51 -0000 1.132 +++ title.cpp 25 Nov 2004 19:48:36 -0000 1.133 @@ -322,7 +322,8 @@ Ticks::pause_init(); - titlesession = new GameSession("misc/menu.stl", ST_GL_DEMO_GAME); + titlesession = new GameSession(get_resource_filename("levels/misc/menu.stl"), + ST_GL_DEMO_GAME); /* Load images: */ bkg_title = new Surface(datadir + "/images/background/arctis.jpg", false); @@ -483,6 +484,3 @@ delete img_choose_subset; } - -// EOF // - Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.133 retrieving revision 1.134 diff -u -d -r1.133 -r1.134 --- worldmap.cpp 23 Nov 2004 02:00:51 -0000 1.133 +++ worldmap.cpp 25 Nov 2004 19:48:36 -0000 1.134 @@ -863,7 +863,8 @@ // do a shriking fade to the level shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),(level->pos.y*32 + 16 + offset.y)), 500); - GameSession session(level->name, + GameSession session( + get_resource_filename(std::string("levels/" + level->name)), ST_GL_LOAD_LEVEL_FILE, level->vertical_flip, &level->statistics); Index: resources.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- resources.h 20 Nov 2004 22:14:39 -0000 1.17 +++ resources.h 25 Nov 2004 19:48:36 -0000 1.18 @@ -93,6 +93,10 @@ extern Font* white_big_text; extern Font* yellow_nums; +// maps a virtual resource path to a real path (ie. levels/bla is mapped to +// $DATADIR/levels/bla or $HOME/.supertux/levels/bla) +std::string get_resource_filename(const std::string& resource); + void loadshared(); void unloadshared(); Index: resources.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- resources.cpp 21 Nov 2004 03:21:25 -0000 1.57 +++ resources.cpp 25 Nov 2004 19:48:26 -0000 1.58 @@ -304,3 +304,16 @@ sprite_manager = 0; } +std::string get_resource_filename(const std::string& resource) +{ + std::string filepath = st_dir + resource; + if(access(filepath.c_str(), R_OK) == 0) + return filepath; + + filepath = datadir + resource; + if(access(filepath.c_str(), R_OK) == 0) + return filepath; + + std::cerr << "Couldn't find resource: '" << resource << "'." << std::endl; + return ""; +} |