[Super-tux-commit] supertux/src level.cpp,1.104,1.105 level_subset.cpp,1.14,1.15 level_subset.h,1.7,
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-10-25 03:33:00
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20402/src Modified Files: level.cpp level_subset.cpp level_subset.h leveleditor.cpp title.cpp worldmap.cpp Log Message: - committed patch from Richard Smith - fixed some warnings Index: level_subset.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- level_subset.cpp 23 Oct 2004 21:16:21 -0000 1.14 +++ level_subset.cpp 25 Oct 2004 03:32:50 -0000 1.15 @@ -88,42 +88,32 @@ // Check in which directory our subset is located (ie. ~/.supertux/ // or SUPERTUX_DATADIR) std::string filename; - filename = st_dir + "/levels/" + subset + "/"; - if (access(filename.c_str(), R_OK) == 0) - { - directory = filename; - } - else + filename = st_dir + "/levels/" + subset + "/info"; + if (access(filename.c_str(), R_OK) != 0) { - filename = datadir + "/levels/" + subset + "/"; - if (access(filename.c_str(), R_OK) == 0) - directory = filename; - else + filename = datadir + "/levels/" + subset + "/info"; + if (access(filename.c_str(), R_OK) != 0) std::cout << "Error: LevelSubset: couldn't find subset: " << subset << std::endl; } - read_info_file(directory + "info"); + read_info_file(filename); if (levels.empty()) { // Level info file doesn't define any levels, so read the // directory to see what we can find std::set<std::string> files; + filename = datadir + "/levels/" + subset + "/"; + files = FileSystem::read_directory(filename); + filename = st_dir + "/levels/" + subset + "/"; - if(access(filename.c_str(), R_OK) == 0) - { - files = FileSystem::read_directory(filename); - } - else - { - filename = datadir + "/levels/" + subset + "/"; - files = FileSystem::read_directory(filename); - } + std::set<std::string> user_files = FileSystem::read_directory(filename); + files.insert(user_files.begin(), user_files.end()); for(std::set<std::string>::iterator i = files.begin(); i != files.end(); ++i) { if (has_suffix(*i, ".stl")) - levels.push_back(*i); + levels.push_back(subset+ "/" + *i); } } } @@ -177,7 +167,7 @@ LevelSubset::get_level_filename(unsigned int num) { assert(num < levels.size()); - return directory + levels[num]; + return levels[num]; } int Index: level_subset.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- level_subset.h 9 Oct 2004 21:27:30 -0000 1.7 +++ level_subset.h 25 Oct 2004 03:32:50 -0000 1.8 @@ -32,9 +32,6 @@ class LevelSubset { private: - /** Directory in which the level subset is stored */ - std::string directory; - /** Level filenames without the leading path ("level1.stl", "level3.stl", ...) */ std::vector<std::string> levels; Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.104 retrieving revision 1.105 diff -u -d -r1.104 -r1.105 --- level.cpp 24 Sep 2004 21:19:25 -0000 1.104 +++ level.cpp 25 Oct 2004 03:32:50 -0000 1.105 @@ -52,7 +52,19 @@ void Level::load(const std::string& filename) { - LispReader* level = LispReader::load(filename, "supertux-level"); + 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; level->read_int("version", version); @@ -102,7 +114,11 @@ void Level::save(const std::string& filename) { - ofstream file(filename.c_str(), ios::out); + std::string filepath = "levels/" + filename; + int last_slash = filepath.find_last_of('/'); + FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str()); + filepath = st_dir + "/" + filepath; + ofstream file(filepath.c_str(), ios::out); LispWriter* writer = new LispWriter(file); writer->write_comment("Level made using SuperTux's built-in Level Editor"); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.126 retrieving revision 1.127 diff -u -d -r1.126 -r1.127 --- worldmap.cpp 24 Oct 2004 23:29:06 -0000 1.126 +++ worldmap.cpp 25 Oct 2004 03:32:50 -0000 1.127 @@ -169,7 +169,7 @@ std::cerr << "Warning: no image specified for tile " << id << ".\nIgnoring...\n" << std::endl; - for(int i = 0; i < filenames.size(); i++) + for(int i = 0; static_cast<unsigned int>(i) < filenames.size(); i++) { Surface* image = new Surface( datadir + "/images/worldmap/" + filenames[i], true); @@ -879,7 +879,7 @@ // 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(datadir + "/levels/" + level->name, + GameSession session(level->name, ST_GL_LOAD_LEVEL_FILE, level->vertical_flip, &level->statistics); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.128 retrieving revision 1.129 diff -u -d -r1.128 -r1.129 --- title.cpp 24 Oct 2004 23:29:06 -0000 1.128 +++ title.cpp 25 Oct 2004 03:32:50 -0000 1.129 @@ -218,7 +218,20 @@ /** get level's title */ std::string level_title = "<no title>"; - LispReader* reader = LispReader::load(subset.get_level_filename(i), "supertux-level"); + std::string filename = subset.get_level_filename(i); + 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; + continue; + } + } + + LispReader* reader = LispReader::load(filepath, "supertux-level"); if(!reader) { std::cerr << "Error: Could not open level file. Ignoring...\n"; @@ -314,7 +327,7 @@ random_timer.init(true); Ticks::pause_init(); - titlesession = new GameSession(datadir + "/levels/misc/menu.stl", ST_GL_DEMO_GAME); + titlesession = new GameSession("misc/menu.stl", ST_GL_DEMO_GAME); /* Load images: */ bkg_title = new Surface(datadir + "/images/background/arctis.jpg", false); Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.162 retrieving revision 1.163 diff -u -d -r1.162 -r1.163 --- leveleditor.cpp 21 Oct 2004 22:04:48 -0000 1.162 +++ leveleditor.cpp 25 Oct 2004 03:32:50 -0000 1.163 @@ -840,7 +840,8 @@ GameSession session(level_filename, ST_GL_TEST); session.run(); // player_status.reset(); -sound_manager->halt_music(); +if(sound_manager) + sound_manager->halt_music(); } void LevelEditor::change(int x, int y, int newtile, int layer) |