Disable glbinding debug option
[supertux.git] / src / supertux / gameconfig.cpp
1 //  SuperTux -  A Jump'n Run
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "supertux/gameconfig.hpp"
18
19 #include <stdexcept>
20
21 #include "addon/addon_manager.hpp"
22 #include "control/input_manager.hpp"
23 #include "lisp/writer.hpp"
24 #include "lisp/parser.hpp"
25 #include "util/reader.hpp"
26 #include "supertux/globals.hpp"
27
28 Config::Config() :
29   profile(1),
30   fullscreen_size(0, 0),
31   fullscreen_refresh_rate(0),
32   window_size(800, 600),
33   aspect_size(0, 0), // auto detect
34   magnification(0.0f),
35   use_fullscreen(false),
36   video(VideoSystem::AUTO_VIDEO),
37   try_vsync(true),
38   show_fps(false),
39   sound_enabled(true),
40   music_enabled(true),
41   console_enabled(false),
42   random_seed(0), // set by time(), by default (unless in config)
43   start_level(),
44   enable_script_debugger(false),
45   start_demo(),
46   record_demo(),
47   locale(),
48   keyboard_config(),
49   joystick_config(),
50   disabled_addon_filenames(),
51   developer_mode(false)
52 {
53 }
54
55 Config::~Config()
56 {}
57
58 void
59 Config::load()
60 {
61   lisp::Parser parser;
62   const lisp::Lisp* root = parser.parse("config");
63
64   const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
65   if(!config_lisp)
66   {
67     throw std::runtime_error("File is not a supertux-config file");
68   }
69
70   config_lisp->get("profile", profile);
71   config_lisp->get("show_fps", show_fps);
72   config_lisp->get("console", console_enabled);
73   config_lisp->get("developer", developer_mode);
74   config_lisp->get("locale", locale);
75   config_lisp->get("random_seed", random_seed);
76
77   const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
78   if(config_video_lisp)
79   {
80     config_video_lisp->get("fullscreen", use_fullscreen);
81     std::string video_string;
82     config_video_lisp->get("video", video_string);
83     video = VideoSystem::get_video_system(video_string);
84     config_video_lisp->get("vsync", try_vsync);
85
86     config_video_lisp->get("fullscreen_width",  fullscreen_size.width);
87     config_video_lisp->get("fullscreen_height", fullscreen_size.height);
88     config_video_lisp->get("fullscreen_refresh_rate", fullscreen_refresh_rate);
89
90     config_video_lisp->get("window_width",  window_size.width);
91     config_video_lisp->get("window_height", window_size.height);
92
93     config_video_lisp->get("aspect_width",  aspect_size.width);
94     config_video_lisp->get("aspect_height", aspect_size.height);
95
96     config_video_lisp->get("magnification", magnification);
97   }
98
99   const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
100   if(config_audio_lisp) {
101     config_audio_lisp->get("sound_enabled", sound_enabled);
102     config_audio_lisp->get("music_enabled", music_enabled);
103   }
104
105   const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
106   if (config_control_lisp)
107   {
108     const lisp::Lisp* keymap_lisp = config_control_lisp->get_lisp("keymap");
109     if (keymap_lisp)
110     {
111       keyboard_config.read(*keymap_lisp);
112     }
113
114     const lisp::Lisp* joystick_lisp = config_control_lisp->get_lisp("joystick");
115     if (joystick_lisp)
116     {
117       joystick_config.read(*joystick_lisp);
118     }
119   }
120
121   const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
122   if (config_addons_lisp)
123   {
124     config_addons_lisp->get("disabled-addons", disabled_addon_filenames);
125   }
126 }
127
128 void
129 Config::save()
130 {
131   lisp::Writer writer("config");
132
133   writer.start_list("supertux-config");
134
135   writer.write("profile", profile);
136   writer.write("show_fps", show_fps);
137   writer.write("console", console_enabled);
138   writer.write("developer", developer_mode);
139   writer.write("locale", locale);
140
141   writer.start_list("video");
142   writer.write("fullscreen", use_fullscreen);
143   writer.write("video", VideoSystem::get_video_string(video));
144   writer.write("vsync", try_vsync);
145
146   writer.write("fullscreen_width",  fullscreen_size.width);
147   writer.write("fullscreen_height", fullscreen_size.height);
148   writer.write("fullscreen_refresh_rate", fullscreen_refresh_rate);
149
150   writer.write("window_width",  window_size.width);
151   writer.write("window_height", window_size.height);
152
153   writer.write("aspect_width",  aspect_size.width);
154   writer.write("aspect_height", aspect_size.height);
155
156   writer.write("magnification", magnification);
157
158   writer.end_list("video");
159
160   writer.start_list("audio");
161   writer.write("sound_enabled", sound_enabled);
162   writer.write("music_enabled", music_enabled);
163   writer.end_list("audio");
164
165   writer.start_list("control");
166   {
167     writer.start_list("keymap");
168     keyboard_config.write(writer);
169     writer.end_list("keymap");
170
171     writer.start_list("joystick");
172     joystick_config.write(writer);
173     writer.end_list("joystick");
174   }
175   writer.end_list("control");
176
177   writer.start_list("addons");
178   writer.write("disabled-addons", disabled_addon_filenames);
179   writer.end_list("addons");
180
181   writer.end_list("supertux-config");
182 }
183
184 /* EOF */