[Super-tux-commit] supertux/src gameloop.cpp,1.209,1.210 level_subset.cpp,1.19,1.20 level_subset.h,1
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-12-02 00:25:39
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15164/src Modified Files: gameloop.cpp level_subset.cpp level_subset.h title.cpp worldmap.cpp worldmap.h Log Message: changed worldmap to be stored inside the same directory as the levelsubset, fixed badguys writing out their current position instead of their startposition when saving levelfile Index: level_subset.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- level_subset.cpp 28 Nov 2004 14:56:49 -0000 1.19 +++ level_subset.cpp 2 Dec 2004 00:25:27 -0000 1.20 @@ -102,6 +102,14 @@ throw new std::runtime_error(msg.str()); } + // test is a worldmap exists + has_worldmap = false; + std::string worldmap = get_resource_filename( + std::string("levels/") + subset + "/worldmap.stwm"); + if(worldmap != "") { + has_worldmap = true; + } + if (levels.empty()) { // Level info file doesn't define any levels, so read the // directory to see what we can find @@ -175,6 +183,12 @@ return levels[num]; } +std::string +LevelSubset::get_worldmap_filename() +{ + return std::string("/levels/" + name + "/worldmap.stwm"); +} + int LevelSubset::get_num_levels() const { Index: level_subset.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- level_subset.h 28 Nov 2004 14:56:49 -0000 1.9 +++ level_subset.h 2 Dec 2004 00:25:27 -0000 1.10 @@ -46,12 +46,14 @@ void add_level(const std::string& name); std::string get_level_filename(unsigned int i); + std::string get_worldmap_filename(); int get_num_levels() const; std::string name; std::string title; std::string description; bool hide_from_contribs; + bool has_worldmap; private: void read_info_file(const std::string& info_file); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.135 retrieving revision 1.136 diff -u -d -r1.135 -r1.136 --- title.cpp 28 Nov 2004 14:56:50 -0000 1.135 +++ title.cpp 2 Dec 2004 00:25:27 -0000 1.136 @@ -75,9 +75,6 @@ static std::vector<LevelSubset*> contrib_subsets; static LevelSubset* current_contrib_subset = 0; -static int first_level_index; - -static std::set<std::string> worldmap_list; static FrameRate frame_rate(100); @@ -126,28 +123,17 @@ contrib_menu->additem(MN_LABEL,_("Contrib Levels"),0,0); contrib_menu->additem(MN_HL,"",0,0); + int i = 0; - - for(std::set<std::string>::iterator it = worldmap_list.begin(); - it != worldmap_list.end(); ++it) { - WorldMapNS::WorldMap worldmap; - worldmap.loadmap((*it).c_str()); - contrib_menu->additem(MN_ACTION, worldmap.get_world_title(),0,0, i); - ++i; - } - - contrib_menu->additem(MN_HL,"",0,0); - - first_level_index = i; - for (std::set<std::string>::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it) + for (std::set<std::string>::iterator it = level_subsets.begin(); + it != level_subsets.end(); ++it) { LevelSubset* subset = new LevelSubset(); subset->load(*it); - if(subset->hide_from_contribs) - { + if(subset->hide_from_contribs) { delete subset; continue; - } + } contrib_menu->additem(MN_GOTO, subset->title, 0, contrib_subset_menu, i); contrib_subsets.push_back(subset); ++i; @@ -186,68 +172,52 @@ if (index == -1) return; - if((unsigned)index < worldmap_list.size()) - { + LevelSubset& subset = * (contrib_subsets[index]); + + if(subset.has_worldmap) { WorldMapNS::WorldMap worldmap; - std::set<std::string>::iterator it = worldmap_list.begin(); - for(int i = index; i > 0; --i) - ++it; - - std::string map_filename = *it; + worldmap.set_map_filename(subset.get_worldmap_filename()); // some fading fadeout(256); DrawingContext context; - context.draw_text(white_text, "Loading...", - Vector(screen->w/2, screen->h/2), CENTER_ALLIGN, LAYER_FOREGROUND1); - context.do_drawing(); - - worldmap.set_map_filename(map_filename); - - // hack to erase the extension - unsigned int ext_pos = it->find_last_of("."); - if(ext_pos != std::string::npos) - map_filename.erase(ext_pos, map_filename.size() - ext_pos); + context.draw_text(white_text, "Loading...", + Vector(screen->w/2, screen->h/2), CENTER_ALLIGN, LAYER_FOREGROUND1); + context.do_drawing(); // TODO: slots should be available for contrib maps - worldmap.loadgame(st_save_dir + "/" + map_filename + "-slot1.stsg"); + worldmap.loadgame(st_save_dir + "/" + subset.name + "-slot1.stsg"); worldmap.display(); // run the map Menu::set_current(main_menu); resume_demo(); - } - else if (index < (int)contrib_subsets.size() + first_level_index) - { - index -= first_level_index; - if (current_subset != index) - { - current_subset = index; - // FIXME: This shouln't be busy looping - LevelSubset& subset = * (contrib_subsets[index]); + } else if (current_subset != index) { + current_subset = index; + // FIXME: This shouln't be busy looping + LevelSubset& subset = * (contrib_subsets[index]); - current_contrib_subset = ⊂ + current_contrib_subset = ⊂ - contrib_subset_menu->clear(); + contrib_subset_menu->clear(); - contrib_subset_menu->additem(MN_LABEL, subset.title, 0,0); - contrib_subset_menu->additem(MN_HL,"",0,0); + contrib_subset_menu->additem(MN_LABEL, subset.title, 0,0); + contrib_subset_menu->additem(MN_HL,"",0,0); - for (int i = 0; i < subset.get_num_levels(); ++i) - { - /** get level's title */ - std::string filename = subset.get_level_filename(i); - std::string title = get_level_name(filename); - contrib_subset_menu->additem(MN_ACTION, title, 0, 0, i); - } + for (int i = 0; i < subset.get_num_levels(); ++i) + { + /** get level's title */ + std::string filename = subset.get_level_filename(i); + std::string title = get_level_name(filename); + contrib_subset_menu->additem(MN_ACTION, title, 0, 0, i); + } - contrib_subset_menu->additem(MN_HL,"",0,0); - contrib_subset_menu->additem(MN_BACK, _("Back"), 0, 0); + contrib_subset_menu->additem(MN_HL,"",0,0); + contrib_subset_menu->additem(MN_BACK, _("Back"), 0, 0); - titlesession->get_current_sector()->activate(); - titlesession->set_current(); - } - } + titlesession->get_current_sector()->activate(); + titlesession->set_current(); + } } void check_contrib_subset_menu() @@ -327,9 +297,6 @@ logo = new Surface(datadir + "/images/title/logo.png", true); img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", true); - /* Generating contrib maps by only using a string_list */ - worldmap_list = FileSystem::dfiles("levels/worldmap", "", "icyisland.stwm"); - titlesession->get_current_sector()->activate(); titlesession->set_current(); @@ -474,7 +441,6 @@ /* Free surfaces: */ free_contrib_menu(); - worldmap_list.clear(); delete titlesession; delete bkg_title; delete logo; Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.136 retrieving revision 1.137 diff -u -d -r1.136 -r1.137 --- worldmap.cpp 28 Nov 2004 14:56:50 -0000 1.136 +++ worldmap.cpp 2 Dec 2004 00:25:27 -0000 1.137 @@ -368,17 +368,22 @@ void WorldMap::load_map() { + std::string::size_type p = map_filename.find_last_of('/'); + if(p == std::string::npos) + levels_path = ""; + else + levels_path = map_filename.substr(0, p+1); + try { lisp::Parser parser; - std::string filename - = get_resource_filename("/levels/worldmap/" + map_filename); + std::string filename = get_resource_filename(map_filename); std::auto_ptr<lisp::Lisp> root (parser.parse(filename)); const lisp::Lisp* lisp = root->get_lisp("supertux-worldmap"); if(!lisp) throw new std::runtime_error("file isn't a supertux-worldmap file."); - lisp::ListIterator iter(lisp->get_cdr()); + lisp::ListIterator iter(lisp); while(iter.next()) { if(iter.item() == "tilemap") { if(tilemap.size() > 0) @@ -498,7 +503,7 @@ try { lisp::Parser parser; std::auto_ptr<lisp::Lisp> root ( - parser.parse(get_resource_filename("levels/" + level.name))); + parser.parse(get_resource_filename(levels_path + level.name))); const lisp::Lisp* level_lisp = root->get_lisp("supertux-level"); if(!level_lisp) @@ -718,8 +723,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( - get_resource_filename(std::string("levels/" + level->name)), + GameSession session(get_resource_filename(levels_path + level->name), ST_GL_LOAD_LEVEL_FILE, &level->statistics); switch (session.run()) Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.209 retrieving revision 1.210 diff -u -d -r1.209 -r1.210 --- gameloop.cpp 1 Dec 2004 15:58:38 -0000 1.209 +++ gameloop.cpp 2 Dec 2004 00:25:27 -0000 1.210 @@ -978,7 +978,7 @@ WorldMapNS::WorldMap worldmap; - worldmap.set_map_filename("icyisland.stwm"); + worldmap.set_map_filename("/levels/world1/worldmap.stwm"); // Load the game or at least set the savegame_file variable worldmap.loadgame(slotfile); Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- worldmap.h 28 Nov 2004 14:56:50 -0000 1.52 +++ worldmap.h 2 Dec 2004 00:25:27 -0000 1.53 @@ -185,6 +185,7 @@ private: std::string map_filename; + std::string levels_path; typedef std::vector<SpecialTile> SpecialTiles; SpecialTiles special_tiles; |