[Super-tux-commit] supertux/lib/utils configfile.cpp,1.9,1.10 configfile.h,1.7,1.8
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-28 14:57:43
|
Update of /cvsroot/super-tux/supertux/lib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13367/lib/utils Modified Files: configfile.cpp configfile.h Log Message: move over rewritten lispreader from tuxkart (with additional fixes), generalized TileManager and Tile classes and use them for the worldmap too Index: configfile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/utils/configfile.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- configfile.h 24 Nov 2004 14:10:23 -0000 1.7 +++ configfile.h 28 Nov 2004 14:56:48 -0000 1.8 @@ -20,7 +20,7 @@ #ifndef SUPERTUX_CONFIGFILE_H #define SUPERTUX_CONFIGFILE_H -#include "lispreader.h" +#include "lisp/lisp.h" namespace SuperTux { @@ -30,7 +30,7 @@ public: void load (); void save (); - virtual void customload(LispReader& ) + virtual void customload(const lisp::Lisp* ) {}; virtual void customsave(FILE* ) {}; Index: configfile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/utils/configfile.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- configfile.cpp 24 Nov 2004 14:10:23 -0000 1.9 +++ configfile.cpp 28 Nov 2004 14:56:48 -0000 1.10 @@ -21,11 +21,13 @@ #include <cstdlib> #include <string> +#include <stdexcept> #include "configfile.h" #include "app/setup.h" #include "app/globals.h" #include "audio/sound_manager.h" +#include "lisp/parser.h" using namespace SuperTux; @@ -76,64 +78,49 @@ void Config::load() { - FILE * file = NULL; - defaults(); - /* override defaults from config file */ - - file = opendata(config_filename, "r"); - - if (file == NULL) - return; - - /* read config file */ - - lisp_stream_t stream; - lisp_object_t * root_obj = NULL; - - lisp_stream_init_file (&stream, file); - root_obj = lisp_read (&stream); - - if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) - return; - - if (strcmp(lisp_symbol(lisp_car(root_obj)), (package_symbol_name+"-config").c_str()) != 0) - return; - - LispReader reader(lisp_cdr(root_obj)); - - reader.read_bool("fullscreen", use_fullscreen); - bool temp; - reader.read_bool("sound", temp); - SoundManager::get()->enable_sound(temp); - reader.read_bool("music", temp); - SoundManager::get()->enable_music(temp); - reader.read_bool("show_fps", show_fps); + lisp::Parser parser; + try { + std::auto_ptr<lisp::Lisp> root (parser.parse(st_dir + config_filename)); - std::string video; - reader.read_string ("video", video); - if (video == "opengl") - use_gl = true; - else - use_gl = false; + const lisp::Lisp* config_lisp = root->get_lisp( + package_symbol_name + "-config"); + if(!config_lisp) + throw new std::runtime_error("Config file is not a supertux-config file"); - reader.read_int ("joystick", joystick_num); + config_lisp->get("fullscreen", use_fullscreen); + bool temp = false; + if(config_lisp->get("sound", temp)) + SoundManager::get()->enable_sound(temp); + if(config_lisp->get("music", temp)) + SoundManager::get()->enable_music(temp); + config_lisp->get("show_fps", show_fps); - if (joystick_num >= 0) - { - reader.read_int ("joystick-x", joystick_keymap.x_axis); - reader.read_int ("joystick-y", joystick_keymap.y_axis); - reader.read_int ("joystick-a", joystick_keymap.a_button); - reader.read_int ("joystick-b", joystick_keymap.b_button); - reader.read_int ("joystick-start", joystick_keymap.start_button); - reader.read_int ("joystick-deadzone", joystick_keymap.dead_zone); + std::string video; + if(config_lisp->get("video", video)) { + if (video == "opengl") + use_gl = true; + else + use_gl = false; } - customload(reader); + joystick_num = 0; + config_lisp->get("joystick", joystick_num); + + if (joystick_num >= 0) { + config_lisp->get("joystick-x", joystick_keymap.x_axis); + config_lisp->get("joystick-y", joystick_keymap.y_axis); + config_lisp->get("joystick-a", joystick_keymap.a_button); + config_lisp->get("joystick-b", joystick_keymap.b_button); + config_lisp->get("joystick-start", joystick_keymap.start_button); + config_lisp->get("joystick-deadzone", joystick_keymap.dead_zone); + } - lisp_free(root_obj); - fclose(file); + customload(config_lisp); + } catch(std::exception& e) { + std::cerr << "Couldn't load configfile: " << e.what() << "\n"; + } } void Config::save () @@ -173,4 +160,3 @@ } } -/* EOF */ |