[Super-tux-commit] supertux/src title.cpp,1.107,1.108 worldmap.cpp,1.96,1.97
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-07-17 13:14:29
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29075/src Modified Files: title.cpp worldmap.cpp Log Message: Optmized code for reading level's name. Instead of loading the all levels, just parses now the title. Both worldmap loading and contrib menu generating were optmized. I couldn't time the worldmap loading speedup, since it was already instantaneously in my machine. But the contrib menu takes less than 1 sec versus the 4 seconds (and a few ms) of the old code. Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.107 retrieving revision 1.108 diff -u -d -r1.107 -r1.108 --- title.cpp 14 Jul 2004 09:46:19 -0000 1.107 +++ title.cpp 17 Jul 2004 13:14:20 -0000 1.108 @@ -144,10 +144,20 @@ for (int i = 0; i < subset.get_num_levels(); ++i) { - Level* level = new Level; - level->load(subset.get_level_filename(i)); - contrib_subset_menu->additem(MN_ACTION, level->get_name(), 0, 0, i); - delete level; + /** get level's title */ + std::string level_title = "<no title>"; + + LispReader* reader = LispReader::load(subset.get_level_filename(i), "supertux-level"); + if(!reader) + { + std::cerr << "Error: Could not open level file. Ignoring...\n"; + return; + } + + reader->read_string("name", level_title, true); + delete reader; + + contrib_subset_menu->additem(MN_ACTION, level_title, 0, 0, i); } contrib_subset_menu->additem(MN_HL,"",0,0); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.96 retrieving revision 1.97 diff -u -d -r1.96 -r1.97 --- worldmap.cpp 16 Jul 2004 19:22:26 -0000 1.96 +++ worldmap.cpp 17 Jul 2004 13:14:20 -0000 1.97 @@ -489,33 +489,15 @@ /** get level's title */ level.title = "<no title>"; - FILE * fi; - lisp_object_t* root_obj = 0; - fi = fopen((datadir + "/levels/" + level.name).c_str(), "r"); - if (fi == NULL) - { - perror((datadir + "/levels/" + level.name).c_str()); + LispReader* reader = LispReader::load(datadir + "/levels/" + level.name, "supertux-level"); + if(!reader) + { + std::cerr << "Error: Could not open level file. Ignoring...\n"; return; - } - - lisp_stream_t stream; - lisp_stream_init_file (&stream, fi); - root_obj = lisp_read (&stream); - - if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) - { - printf("World: Parse Error in file %s", level.name.c_str()); - } - - if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0) - { - LispReader reader(lisp_cdr(root_obj)); - reader.read_string("name", level.title, true); - } - - lisp_free(root_obj); + } - fclose(fi); + reader->read_string("name", level.title, true); + delete reader; } void |