src/supertux/gameconfig.cpp

Go to the documentation of this file.
00001 //  SuperTux -  A Jump'n Run
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "supertux/gameconfig.hpp"
00018 
00019 #include <stdexcept>
00020 
00021 #include "addon/addon_manager.hpp"
00022 #include "control/joystickkeyboardcontroller.hpp"
00023 #include "lisp/writer.hpp"
00024 #include "lisp/parser.hpp"
00025 #include "util/reader.hpp"
00026 #include "supertux/globals.hpp"
00027 
00028 Config::Config() :
00029   profile(1),
00030   fullscreen_size(800, 600),
00031   window_size(800, 600),
00032   aspect_size(0, 0), // auto detect
00033   magnification(0.0f),
00034   use_fullscreen(false),
00035   video(VideoSystem::AUTO_VIDEO),
00036   try_vsync(true),
00037   show_fps(false),
00038   sound_enabled(true),
00039   music_enabled(true),
00040   console_enabled(false),
00041   random_seed(0),          // set by time(), by default (unless in config)
00042   start_level(),
00043   enable_script_debugger(false),
00044   start_demo(),
00045   record_demo(),
00046   locale()
00047 {
00048 }
00049 
00050 Config::~Config()
00051 {}
00052 
00053 void
00054 Config::load()
00055 {
00056   lisp::Parser parser;
00057   const lisp::Lisp* root = parser.parse("config");
00058 
00059   const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
00060   if(!config_lisp)
00061     throw std::runtime_error("File is not a supertux-config file");
00062 
00063   config_lisp->get("show_fps", show_fps);
00064   config_lisp->get("console", console_enabled);
00065   config_lisp->get("locale", locale);
00066   config_lisp->get("random_seed", random_seed);
00067 
00068   const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
00069   if(config_video_lisp) {
00070     config_video_lisp->get("fullscreen", use_fullscreen);
00071     std::string video_string;
00072     config_video_lisp->get("video", video_string);
00073     video = VideoSystem::get_video_system(video_string);
00074     config_video_lisp->get("vsync", try_vsync);
00075 
00076     config_video_lisp->get("fullscreen_width",  fullscreen_size.width);
00077     config_video_lisp->get("fullscreen_height", fullscreen_size.height);
00078 
00079     config_video_lisp->get("window_width",  window_size.width);
00080     config_video_lisp->get("window_height", window_size.height);
00081 
00082     config_video_lisp->get("aspect_width",  aspect_size.width);
00083     config_video_lisp->get("aspect_height", aspect_size.height);
00084     
00085     config_video_lisp->get("magnification", magnification);
00086   }
00087 
00088   const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
00089   if(config_audio_lisp) {
00090     config_audio_lisp->get("sound_enabled", sound_enabled);
00091     config_audio_lisp->get("music_enabled", music_enabled);
00092   }
00093 
00094   const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
00095   if(config_control_lisp && g_jk_controller) {
00096     g_jk_controller->read(*config_control_lisp);
00097   }
00098 
00099   const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
00100   if(config_addons_lisp) {
00101     AddonManager::get_instance().read(*config_addons_lisp);
00102   }
00103 }
00104 
00105 void
00106 Config::save()
00107 {
00108   lisp::Writer writer("config");
00109 
00110   writer.start_list("supertux-config");
00111 
00112   writer.write("show_fps", show_fps);
00113   writer.write("console", console_enabled);
00114   writer.write("locale", locale);
00115 
00116   writer.start_list("video");
00117   writer.write("fullscreen", use_fullscreen);
00118   writer.write("video", VideoSystem::get_video_string(video));
00119   writer.write("vsync", try_vsync);
00120 
00121   writer.write("fullscreen_width",  fullscreen_size.width);
00122   writer.write("fullscreen_height", fullscreen_size.height);
00123 
00124   writer.write("window_width",  window_size.width);
00125   writer.write("window_height", window_size.height);
00126 
00127   writer.write("aspect_width",  aspect_size.width);
00128   writer.write("aspect_height", aspect_size.height);
00129   
00130   writer.write("magnification", magnification);
00131 
00132   writer.end_list("video");
00133 
00134   writer.start_list("audio");
00135   writer.write("sound_enabled", sound_enabled);
00136   writer.write("music_enabled", music_enabled);
00137   writer.end_list("audio");
00138 
00139   if(g_jk_controller) {
00140     writer.start_list("control");
00141     g_jk_controller->write(writer);
00142     writer.end_list("control");
00143   }
00144 
00145   writer.start_list("addons");
00146   AddonManager::get_instance().write(writer);
00147   writer.end_list("addons");
00148 
00149   writer.end_list("supertux-config");
00150 }
00151 
00152 /* EOF */

Generated on Mon Apr 21 03:38:17 2014 for SuperTux by  doxygen 1.5.1