From: Tobias Gläßer Date: Tue, 27 Jul 2004 19:31:39 +0000 (+0000) Subject: - Cleanups X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6ed1900da4edf7d7922f7a4626f95a83e34dff82;p=supertux.git - Cleanups - Got rid of string_list_type (caution! Bugs with the replacement solutions are likely to happen, that will be fixed) SVN-Revision: 1640 --- diff --git a/lib/app/globals.cpp b/lib/app/globals.cpp index 251fc29b8..e731b29fa 100644 --- a/lib/app/globals.cpp +++ b/lib/app/globals.cpp @@ -50,7 +50,6 @@ bool use_joystick; bool use_fullscreen; bool debug_mode; bool show_fps; -float game_speed = 1.0f; int joystick_num = 0; char* level_startup_file = 0; diff --git a/lib/app/globals.h b/lib/app/globals.h index 6f727b768..6de62d678 100644 --- a/lib/app/globals.h +++ b/lib/app/globals.h @@ -74,7 +74,6 @@ namespace SuperTux extern char* st_dir; extern char* st_save_dir; - extern float game_speed; extern SDL_Joystick * js; int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); diff --git a/lib/app/setup.cpp b/lib/app/setup.cpp index 1a56682fa..22a23a6c1 100644 --- a/lib/app/setup.cpp +++ b/lib/app/setup.cpp @@ -119,15 +119,14 @@ int FileSystem::fcreatedir(const char* relative_dir) /* Get all names of sub-directories in a certain directory. */ /* Returns the number of sub-directories found. */ /* Note: The user has to free the allocated space. */ -string_list_type FileSystem::dsubdirs(const char *rel_path,const char* expected_file) +std::set FileSystem::dsubdirs(const char *rel_path,const char* expected_file) { DIR *dirStructP; struct dirent *direntp; - string_list_type sdirs; + std::set sdirs; char filename[1024]; char path[1024]; - string_list_init(&sdirs); sprintf(path,"%s/%s",st_dir,rel_path); if((dirStructP = opendir(path)) != NULL) { @@ -147,7 +146,7 @@ string_list_type FileSystem::dsubdirs(const char *rel_path,const char* expected continue; } - string_list_add_item(&sdirs,direntp->d_name); + sdirs.insert(direntp->d_name); } } closedir(dirStructP); @@ -180,7 +179,7 @@ string_list_type FileSystem::dsubdirs(const char *rel_path,const char* expected } } - string_list_add_item(&sdirs,direntp->d_name); + sdirs.insert(direntp->d_name); } } closedir(dirStructP); @@ -189,14 +188,13 @@ string_list_type FileSystem::dsubdirs(const char *rel_path,const char* expected return sdirs; } -string_list_type FileSystem::dfiles(const char *rel_path, const char* glob, const char* exception_str) +std::set FileSystem::dfiles(const char *rel_path, const char* glob, const char* exception_str) { DIR *dirStructP; struct dirent *direntp; - string_list_type sdirs; + std::set sdirs; char path[1024]; - string_list_init(&sdirs); sprintf(path,"%s/%s",st_dir,rel_path); if((dirStructP = opendir(path)) != NULL) { @@ -218,7 +216,7 @@ string_list_type FileSystem::dfiles(const char *rel_path, const char* glob, con if(strstr(direntp->d_name,glob) == NULL) continue; - string_list_add_item(&sdirs,direntp->d_name); + sdirs.insert(direntp->d_name); } } closedir(dirStructP); @@ -245,7 +243,7 @@ string_list_type FileSystem::dfiles(const char *rel_path, const char* glob, con if(strstr(direntp->d_name,glob) == NULL) continue; - string_list_add_item(&sdirs,direntp->d_name); + sdirs.insert(direntp->d_name); } } closedir(dirStructP); @@ -844,9 +842,9 @@ void usage(char * prog, int ret) exit(ret); } -std::vector FileSystem::read_directory(const std::string& pathname) +std::set FileSystem::read_directory(const std::string& pathname) { - std::vector dirnames; + std::set dirnames; DIR* dir = opendir(pathname.c_str()); if (dir) @@ -855,7 +853,7 @@ std::vector FileSystem::read_directory(const std::string& pathname) while((direntp = readdir(dir))) { - dirnames.push_back(direntp->d_name); + dirnames.insert(direntp->d_name); } closedir(dir); diff --git a/lib/app/setup.h b/lib/app/setup.h index 2eebb380f..4c9146402 100644 --- a/lib/app/setup.h +++ b/lib/app/setup.h @@ -21,6 +21,7 @@ #define SUPERTUX_SETUP_H #include +#include #include #include "../gui/menu.h" #include "../special/base.h" @@ -33,9 +34,9 @@ struct FileSystem static int faccessible(const char *filename); static int fcreatedir(const char* relative_dir); static int fwriteable(const char *filename); - static std::vector read_directory(const std::string& pathname); - static string_list_type dsubdirs(const char *rel_path, const char* expected_file); - static string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str); + static std::set read_directory(const std::string& pathname); + static std::set dsubdirs(const char *rel_path, const char* expected_file); + static std::set dfiles(const char *rel_path, const char* glob, const char* exception_str); }; /// All you need to get an application up and running diff --git a/lib/gui/menu.cpp b/lib/gui/menu.cpp index 5e899a884..7e273d665 100644 --- a/lib/gui/menu.cpp +++ b/lib/gui/menu.cpp @@ -171,16 +171,10 @@ MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* pnew_item->input = (char*) malloc(sizeof(char)); pnew_item->input[0] = '\0'; - if(kind_ == MN_STRINGSELECT) - { - pnew_item->list = (string_list_type*) malloc(sizeof(string_list_type)); - string_list_init(pnew_item->list); - } - else - pnew_item->list = NULL; - pnew_item->id = id; pnew_item->int_p = int_p_; + + pnew_item->list.second = 0; pnew_item->input_flickering = false; pnew_item->input_flickering_timer.init(true); @@ -306,7 +300,7 @@ Menu::~Menu() { free(item[i].text); free(item[i].input); - string_list_free(item[i].list); + item[i].list.first.clear(); } } } @@ -379,23 +373,23 @@ Menu::action() case MENU_ACTION_LEFT: if(item[active_item].kind == MN_STRINGSELECT - && item[active_item].list->num_items != 0) + && item[active_item].list.first.size() != 0) { - if(item[active_item].list->active_item > 0) - --item[active_item].list->active_item; + if(item[active_item].list.second != item[active_item].list.first.begin()) + --item[active_item].list.second; else - item[active_item].list->active_item = item[active_item].list->num_items-1; + item[active_item].list.second = item[active_item].list.first.end(); } break; case MENU_ACTION_RIGHT: if(item[active_item].kind == MN_STRINGSELECT - && item[active_item].list->num_items != 0) + && item[active_item].list.first.size() != 0) { - if(item[active_item].list->active_item < item[active_item].list->num_items-1) - ++item[active_item].list->active_item; + if(item[active_item].list.second != item[active_item].list.first.end()) + ++item[active_item].list.second; else - item[active_item].list->active_item = 0; + item[active_item].list.second = item[active_item].list.first.begin(); } break; @@ -526,9 +520,10 @@ Menu::draw_item(DrawingContext& context, int shadow_size = 2; int text_width = int(text_font->get_text_width(pitem.text)); int input_width = int(text_font->get_text_width(pitem.input) + 10); - int list_width = - int(text_font->get_text_width(string_list_active(pitem.list))); - + int list_width = 0; + if(pitem.list.second != 0) + list_width = int(text_font->get_text_width((*pitem.list.second))); + if (arrange_left) x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2; @@ -637,7 +632,7 @@ Menu::draw_item(DrawingContext& context, Vector(list_pos_2, 18), Color(0,0,0,128), LAYER_GUI - 5); - context.draw_text_center(text_font, string_list_active(pitem.list), + context.draw_text_center(text_font, (*pitem.list.second), Vector(text_pos, y_pos - int(text_font->get_height()/2)), LAYER_GUI); context.draw_text_center(text_font, pitem.text, @@ -693,7 +688,7 @@ int Menu::get_width() const int menu_width = 0; for(unsigned int i = 0; i < item.size(); ++i) { - int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list)); + int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0); //+ ((item[i].list.second != item[i].list.first.end()) ? (strlen((*(item[i].list.second)).c_str())) : 0); if( w > menu_width ) { menu_width = w; @@ -714,8 +709,9 @@ int Menu::get_height() const void Menu::draw(DrawingContext& context) { + int menu_height = get_height(); - int menu_width = get_width(); + int menu_width = get_width(); /* Draw a transparent background */ context.draw_filled_rect( diff --git a/lib/gui/menu.h b/lib/gui/menu.h index 31ad4f9d5..f4a394326 100644 --- a/lib/gui/menu.h +++ b/lib/gui/menu.h @@ -21,6 +21,9 @@ #define SUPERTUX_MENU_H #include +#include +#include +#include #include "SDL.h" @@ -28,7 +31,6 @@ #include "../video/font.h" #include "../special/timer.h" #include "../special/base.h" -#include "../special/stringlist.h" #include "../gui/mousecursor.h" namespace SuperTux @@ -68,7 +70,7 @@ namespace SuperTux char *input; int *int_p; // used for setting keys (can be used for more stuff...) int id; // item id - string_list_type* list; + std::pair, std::set::iterator> list; Menu* target_menu; void change_text (const char *text); diff --git a/lib/special/stringlist.cpp b/lib/special/stringlist.cpp deleted file mode 100644 index a9f73cc3c..000000000 --- a/lib/special/stringlist.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2004 Tobias Glaesser -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. - -#include "string.h" -#include "stdlib.h" -#include "../special/stringlist.h" - -using namespace SuperTux; - -void SuperTux::string_list_init(string_list_type* pstring_list) -{ - pstring_list->num_items = 0; - pstring_list->active_item = -1; - pstring_list->item = NULL; -} - -char* SuperTux::string_list_active(string_list_type* pstring_list) -{ - if(pstring_list == NULL) - return ""; - - if(pstring_list->active_item != -1) - return pstring_list->item[pstring_list->active_item]; - else - return ""; -} - -void SuperTux::string_list_add_item(string_list_type* pstring_list,const char* str) -{ - char *pnew_string; - pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1)); - strcpy(pnew_string,str); - ++pstring_list->num_items; - pstring_list->item = (char**) realloc(pstring_list->item,sizeof(char**)*pstring_list->num_items); - pstring_list->item[pstring_list->num_items-1] = pnew_string; - if(pstring_list->active_item == -1) - pstring_list->active_item = 0; -} - -void SuperTux::string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig) -{ - int i; - string_list_free(pstring_list); - for(i = 0; i < pstring_list_orig.num_items; ++i) - string_list_add_item(pstring_list,pstring_list_orig.item[i]); -} - -int SuperTux::string_list_find(string_list_type* pstring_list,const char* str) -{ - int i; - for(i = 0; i < pstring_list->num_items; ++i) - { - if(strcmp(pstring_list->item[i],str) == 0) - { - return i; - } - } - return -1; -} - -void SuperTux::string_list_sort(string_list_type* pstring_list) -{ - int i,j,y; - - for(j = 0; j < pstring_list->num_items; ++j) - for(i = 0; i < pstring_list->num_items-1; ++i) - { - - y = strcmp(pstring_list->item[i],pstring_list->item[i+1]); - if(y == 0) - { - continue; - } - else if(y < 0) - { - continue; - } - else if(y > 0) - { - char* char_pointer; - char_pointer = pstring_list->item[i]; - pstring_list->item[i] = pstring_list->item[i+1]; - pstring_list->item[i+1] = char_pointer; - continue; - } - - } - -} - -void SuperTux::string_list_free(string_list_type* pstring_list) -{ - if(pstring_list != NULL) - { - int i; - for(i=0; i < pstring_list->num_items; ++i) - free(pstring_list->item[i]); - free(pstring_list->item); - pstring_list->item = NULL; - pstring_list->num_items = 0; - pstring_list->active_item = -1; - } -} - diff --git a/lib/special/stringlist.h b/lib/special/stringlist.h deleted file mode 100644 index 436758bad..000000000 --- a/lib/special/stringlist.h +++ /dev/null @@ -1,45 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2004 Tobias Glaesser -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. - -#ifndef SUPERTUX_STRINGLIST_H -#define SUPERTUX_STRINGLIST_H - -namespace SuperTux - { - - struct string_list_type - { - int num_items; - int active_item; - char **item; - }; - - void string_list_init(string_list_type* pstring_list); - char* string_list_active(string_list_type* pstring_list); - void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); - int string_list_find(string_list_type* pstring_list, const char* str); - void string_list_sort(string_list_type* pstring_list); - void string_list_add_item(string_list_type* pstring_list, const char* str); - void string_list_free(string_list_type* pstring_list); - -} //namespace SuperTux - -#endif /*SUPERTUX_STRINGLIST_H*/ - diff --git a/lib/utils/configfile.cpp b/lib/utils/configfile.cpp index 387a5e8b5..31a350230 100644 --- a/lib/utils/configfile.cpp +++ b/lib/utils/configfile.cpp @@ -103,7 +103,7 @@ void Config::load() if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) return; - if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-config") != 0) + if (strcmp(lisp_symbol(lisp_car(root_obj)), (package_symbol_name+"-config").c_str()) != 0) return; LispReader reader(lisp_cdr(root_obj)); @@ -148,7 +148,7 @@ void Config::save () if(config) { - fprintf(config, "(supertux-config\n"); + fprintf(config, ("("+package_symbol_name+"-config\n").c_str()); fprintf(config, "\t;; the following options can be set to #t or #f:\n"); fprintf(config, "\t(fullscreen %s)\n", use_fullscreen ? "#t" : "#f"); fprintf(config, "\t(sound %s)\n", SoundManager::get()->sound_enabled() ? "#t" : "#f"); diff --git a/src/gameloop.cpp b/src/gameloop.cpp index d04a952f5..4d7c4dd29 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -77,6 +77,9 @@ GameSession::GameSession(const std::string& levelname_, int mode, bool flip_leve context = new DrawingContext(); + if(debug_mode) + flip_level = true; + restart_level(); } diff --git a/src/level_subset.cpp b/src/level_subset.cpp index 39bc62229..5d4e24f0d 100644 --- a/src/level_subset.cpp +++ b/src/level_subset.cpp @@ -19,8 +19,6 @@ // 02111-1307, USA. #include -#include - #include "app/setup.h" #include "level.h" #include "app/globals.h" @@ -103,7 +101,7 @@ void LevelSubset::load(const char* subset) if (levels.empty()) { // Level info file doesn't define any levels, so read the // directory to see what we can find - std::vector files; + std::set files; snprintf(filename, 1024, "%s/levels/%s/", st_dir, subset); if(access(filename, R_OK) == 0) @@ -116,7 +114,7 @@ void LevelSubset::load(const char* subset) files = FileSystem::read_directory(filename); } - for(std::vector::iterator i = files.begin(); i != files.end(); ++i) + for(std::set::iterator i = files.begin(); i != files.end(); ++i) { if (has_suffix(*i, ".stl")) levels.push_back(*i); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 15b2d572c..2dab42180 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -330,7 +330,7 @@ int LevelEditor::run(char* filename) default: if(i >= 1) { - if(load_level_subset(level_subsets.item[i-1])) + if(load_level_subset(subset_load_menu->item[i+1].text)) return 1; } break; @@ -395,7 +395,7 @@ int LevelEditor::run(char* filename) return done; } -int LevelEditor::load_level_subset(char *filename) +int LevelEditor::load_level_subset(const char *filename) { le_level_subset->load(filename); leveleditor_menu->get_item_by_id(MNID_SUBSETSETTINGS).kind = MN_GOTO; @@ -411,7 +411,7 @@ int LevelEditor::load_level_subset(char *filename) void LevelEditor::init_menus() { - int i; + int i = 0; leveleditor_menu = new Menu(); subset_load_menu = new Menu(); @@ -435,9 +435,9 @@ void LevelEditor::init_menus() subset_load_menu->additem(MN_LABEL, "Load Level Subset", 0, 0); subset_load_menu->additem(MN_HL, "", 0, 0); - for(i = 0; i < level_subsets.num_items; ++i) + for(std::set::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it) { - subset_load_menu->additem(MN_ACTION,level_subsets.item[i],0,0, i+1); + subset_load_menu->additem(MN_ACTION,(*it),0,0, i+1); } subset_load_menu->additem(MN_HL,"",0,0); subset_load_menu->additem(MN_BACK,"Back",0,0); @@ -539,22 +539,22 @@ void LevelEditor::init_menus() void LevelEditor::update_level_settings_menu() { char str[80]; - int i; + std::set::iterator it; level_settings_menu->get_item_by_id(MNID_NAME).change_input(le_level->name.c_str()); level_settings_menu->get_item_by_id(MNID_AUTHOR).change_input(le_level->author.c_str()); - string_list_copy(level_settings_menu->get_item_by_id(MNID_SONG).list, FileSystem::dfiles("music/",NULL, "-fast")); - string_list_copy(level_settings_menu->get_item_by_id(MNID_BGIMG).list, FileSystem::dfiles("images/background",NULL, NULL)); - string_list_add_item(level_settings_menu->get_item_by_id(MNID_BGIMG).list,""); - string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,""); - string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,"snow"); - string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,"clouds"); - - if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_SONG).list,le_level->get_sector("main")->song_title.c_str())) != -1) - level_settings_menu->get_item_by_id(MNID_SONG).list->active_item = i; - if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_BGIMG).list,le_level->get_sector("main")->background->get_image().c_str())) != -1) - level_settings_menu->get_item_by_id(MNID_BGIMG).list->active_item = i; + level_settings_menu->get_item_by_id(MNID_SONG).list.first = FileSystem::dfiles("music/",NULL, "-fast"); + level_settings_menu->get_item_by_id(MNID_BGIMG).list.first = FileSystem::dfiles("images/background",NULL, NULL); + level_settings_menu->get_item_by_id(MNID_BGIMG).list.first.insert(""); + level_settings_menu->get_item_by_id(MNID_PARTICLE).list.first.insert(""); + level_settings_menu->get_item_by_id(MNID_PARTICLE).list.first.insert("snow"); + level_settings_menu->get_item_by_id(MNID_PARTICLE).list.first.insert("clouds"); + + if((it = level_settings_menu->get_item_by_id(MNID_SONG).list.first.find(le_level->get_sector("main")->song_title)) != level_settings_menu->get_item_by_id(MNID_SONG).list.first.end()) + level_settings_menu->get_item_by_id(MNID_SONG).list.second = it; + if((it = level_settings_menu->get_item_by_id(MNID_BGIMG).list.first.find(le_level->get_sector("main")->background->get_image())) != level_settings_menu->get_item_by_id(MNID_BGIMG).list.first.end()) + level_settings_menu->get_item_by_id(MNID_BGIMG).list.second = it; /* if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,le_level->get_sector("main")->particlesystem.c_str())) != -1) level_settings_menu->get_item_by_id(MNID_PARTICLE).list->active_item = i;*/ @@ -597,9 +597,9 @@ void LevelEditor::apply_level_settings_menu() le_level->name = level_settings_menu->get_item_by_id(MNID_NAME).input; le_level->author = level_settings_menu->get_item_by_id(MNID_AUTHOR).input; - if(le_level->get_sector("main")->background->get_image().compare(string_list_active(level_settings_menu->get_item_by_id(MNID_BGIMG).list)) != 0) + if(le_level->get_sector("main")->background->get_image().compare((*level_settings_menu->get_item_by_id(MNID_BGIMG).list.second)) != 0) { - le_level->get_sector("main")->background->set_image(string_list_active(level_settings_menu->get_item_by_id(MNID_BGIMG).list), atoi(level_settings_menu->get_item_by_id(MNID_BGSPEED).input)); + le_level->get_sector("main")->background->set_image((*level_settings_menu->get_item_by_id(MNID_BGIMG).list.second), atoi(level_settings_menu->get_item_by_id(MNID_BGSPEED).input)); i = true; } @@ -613,7 +613,7 @@ void LevelEditor::apply_level_settings_menu() le_level->load_gfx(); }*/ - le_level->get_sector("main")->song_title = string_list_active(level_settings_menu->get_item_by_id(MNID_SONG).list); + le_level->get_sector("main")->song_title = (*level_settings_menu->get_item_by_id(MNID_SONG).list.second); le_level->get_sector("main")->solids->resize( atoi(level_settings_menu->get_item_by_id(MNID_LENGTH).input), @@ -950,10 +950,10 @@ void LevelEditor::change_object_properties(GameObject *pobj) object_properties_menu->additem(MN_STRINGSELECT,"Kind",0,0,1); for(int i = 0; i < NUM_BadGuyKinds; ++i) { - string_list_add_item(object_properties_menu->get_item_by_id(1).list, - badguykind_to_string(static_cast(i)).c_str()); + object_properties_menu->get_item_by_id(1).list.first.insert( + badguykind_to_string(static_cast(i))); if(pbad->kind == i) - object_properties_menu->get_item_by_id(1).list->active_item = i; + object_properties_menu->get_item_by_id(1).list.second = object_properties_menu->get_item_by_id(1).list.first.find(badguykind_to_string(static_cast(i))); } object_properties_menu->additem(MN_TOGGLE,"StayOnPlatform",pbad->stay_on_platform,0,2); } @@ -984,7 +984,7 @@ void LevelEditor::change_object_properties(GameObject *pobj) BadGuy* pbad = dynamic_cast(pobj); if(pbad != 0) { BadGuy* pbad = dynamic_cast(pobj); - pbad->kind = badguykind_from_string(string_list_active(object_properties_menu->get_item_by_id(1).list)); + pbad->kind = badguykind_from_string((*object_properties_menu->get_item_by_id(1).list.second)); pbad->stay_on_platform = object_properties_menu->get_item_by_id(2).toggled; } loop = false; diff --git a/src/leveleditor.h b/src/leveleditor.h index c51411bdf..a63f78b70 100644 --- a/src/leveleditor.h +++ b/src/leveleditor.h @@ -94,7 +94,7 @@ void unload_level(); /* own declerations */ /* crutial ones (main loop) */ void init_menus(); -int load_level_subset(char *filename); +int load_level_subset(const char *filename); void drawlevel(DrawingContext& context); void drawinterface(DrawingContext& context); void change(float x, float y, int tm, unsigned int c); @@ -142,7 +142,7 @@ enum SelectionMode { CURSOR, SQUARE, NONE }; // variables /* leveleditor internals */ -string_list_type level_subsets; +std::set level_subsets; bool le_level_changed; /* if changes, ask for saving, when quiting*/ bool show_minimap; bool show_selections; diff --git a/src/title.cpp b/src/title.cpp index ddb0c0138..dd720b284 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -74,7 +74,7 @@ static GameSession* titlesession; static std::vector contrib_subsets; static LevelSubset* current_contrib_subset = 0; -static string_list_type worldmap_list; +static std::set worldmap_list; static LevelEditor* leveleditor; @@ -102,34 +102,39 @@ void free_contrib_menu() void generate_contrib_menu() { + /** Generating contrib levels list by making use of Level Subset */ - string_list_type level_subsets = FileSystem::dsubdirs("/levels", "info"); + std::set level_subsets = FileSystem::dsubdirs("/levels", "info"); free_contrib_menu(); contrib_menu->additem(MN_LABEL,_("Contrib Levels"),0,0); contrib_menu->additem(MN_HL,"",0,0); - - for (int i = 0; i < level_subsets.num_items; ++i) + + int i = 0; + for (std::set::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it) { LevelSubset* subset = new LevelSubset(); - subset->load(level_subsets.item[i]); + subset->load((*it).c_str()); contrib_menu->additem(MN_GOTO, subset->title.c_str(), i, - contrib_subset_menu, i); + contrib_subset_menu); contrib_subsets.push_back(subset); + ++i; } - for(int i = 0; i < worldmap_list.num_items; i++) + i = 0; + for(std::set::iterator it = worldmap_list.begin(); it != worldmap_list.end(); ++it) { WorldMapNS::WorldMap worldmap; - worldmap.loadmap(worldmap_list.item[i]); - contrib_menu->additem(MN_ACTION, worldmap.get_world_title(),0,0, i + level_subsets.num_items); + worldmap.loadmap((*it).c_str()); + contrib_menu->additem(MN_ACTION, worldmap.get_world_title(),0,0, i + level_subsets.size()); + ++i; } contrib_menu->additem(MN_HL,"",0,0); contrib_menu->additem(MN_BACK,_("Back"),0,0); - string_list_free(&level_subsets); + level_subsets.clear(); } void check_levels_contrib_menu() @@ -180,10 +185,13 @@ void check_levels_contrib_menu() titlesession->set_current(); } } - else if(index < worldmap_list.num_items + (int)contrib_subsets.size()) + else if((unsigned)index < worldmap_list.size() + (int)contrib_subsets.size()) { WorldMapNS::WorldMap worldmap; - worldmap.loadmap(worldmap_list.item[index - contrib_subsets.size()]); + std::set::iterator it = worldmap_list.begin(); + for(int i = index - contrib_subsets.size(); i > 0; --i) + ++it; + worldmap.loadmap((*it)); worldmap.display(); Menu::set_current(main_menu); @@ -309,10 +317,11 @@ void title(void) if (event.type == SDL_QUIT) Menu::set_current(0); } - + /* Draw the background: */ draw_demo(frame_ratio); - + + if (Menu::current() == main_menu) context.draw_surface(logo, Vector(screen->w/2 - logo->w/2, 30), LAYER_FOREGROUND1+1); @@ -330,7 +339,7 @@ void title(void) { menu->draw(context); menu->action(); - + if(menu == main_menu) { switch (main_menu->check()) @@ -417,12 +426,13 @@ void title(void) /* Free surfaces: */ free_contrib_menu(); - string_list_free(&worldmap_list); + worldmap_list.clear(); delete titlesession; delete bkg_title; delete logo; delete img_choose_subset; } + // EOF // diff --git a/src/worldmap.cpp b/src/worldmap.cpp index d309771c6..7f87ad4ae 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -437,7 +437,7 @@ WorldMap::load_map() reader.read_int("x", level.x); reader.read_int("y", level.y); level.auto_path = true; - reader.read_bool("auto-path", &level.auto_path); + reader.read_bool("auto-path", level.auto_path); level.swap_x = level.swap_y = -1; reader.read_int("swap-x", level.swap_x); reader.read_int("swap-y", level.swap_y);