2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "User/Settings.hpp"
24 #include "Utils/Folders.hpp"
25 #include "Utils/Input.hpp"
29 void DefaultSettings()
33 usermousesensitivity = 1;
34 newscreenwidth = kContextWidth = 1024;
35 newscreenheight = kContextHeight = 768;
57 crouchkey = SDL_SCANCODE_LSHIFT;
58 jumpkey = SDL_SCANCODE_SPACE;
59 leftkey = SDL_SCANCODE_A;
60 forwardkey = SDL_SCANCODE_W;
61 backkey = SDL_SCANCODE_S;
62 rightkey = SDL_SCANCODE_D;
63 drawkey = SDL_SCANCODE_E;
64 throwkey = SDL_SCANCODE_Q;
65 attackkey = MOUSEBUTTON_LEFT;
66 consolekey = SDL_SCANCODE_GRAVE;
79 if (newscreenwidth < minscreenwidth || newscreenwidth > maxscreenwidth) {
80 newscreenwidth = screenwidth;
82 if (newscreenheight < minscreenheight || newscreenheight > maxscreenheight) {
83 newscreenheight = screenheight;
86 ofstream opstream(Folders::getConfigFilePath());
87 if (opstream.fail()) {
88 perror(("Couldn't save config file " + Folders::getConfigFilePath()).c_str());
91 opstream << "Screenwidth:\n";
92 opstream << newscreenwidth;
93 opstream << "\nScreenheight:\n";
94 opstream << newscreenheight;
95 opstream << "\nFullscreen:\n";
96 opstream << fullscreen;
97 opstream << "\nMouse sensitivity:\n";
98 opstream << usermousesensitivity;
99 opstream << "\nBlur(0,1):\n";
100 opstream << ismotionblur;
101 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
102 opstream << newdetail;
103 opstream << "\nFloating jump:\n";
104 opstream << floatjump;
105 opstream << "\nMouse jump:\n";
106 opstream << mousejump;
107 opstream << "\nAmbient sound:\n";
108 opstream << ambientsound;
109 opstream << "\nBlood (0,1,2):\n";
110 opstream << bloodtoggle;
111 opstream << "\nAuto slomo:\n";
112 opstream << autoslomo;
113 opstream << "\nFoliage:\n";
115 opstream << "\nMusic:\n";
116 opstream << musictoggle;
117 opstream << "\nTrilinear:\n";
118 opstream << trilinear;
119 opstream << "\nDecals(shadows,blood puddles,etc):\n";
120 opstream << decalstoggle;
121 opstream << "\nInvert mouse:\n";
122 opstream << invertmouse;
123 opstream << "\nGamespeed:\n";
124 if (oldgamespeed == 0) {
127 opstream << oldgamespeed;
128 opstream << "\nDamage effects(blackout, doublevision):\n";
129 opstream << damageeffects;
130 opstream << "\nText:\n";
131 opstream << texttoggle;
132 opstream << "\nShow Points:\n";
133 opstream << showpoints;
134 opstream << "\nAlways Blur:\n";
135 opstream << alwaysblur;
136 opstream << "\nImmediate mode (turn on on G5):\n";
137 opstream << immediate;
138 opstream << "\nVelocity blur:\n";
139 opstream << velocityblur;
140 opstream << "\nVolume:\n";
142 opstream << "\nForward key:\n";
143 opstream << forwardkey;
144 opstream << "\nBack key:\n";
146 opstream << "\nLeft key:\n";
148 opstream << "\nRight key:\n";
149 opstream << rightkey;
150 opstream << "\nJump key:\n";
152 opstream << "\nCrouch key:\n";
153 opstream << crouchkey;
154 opstream << "\nDraw key:\n";
156 opstream << "\nThrow key:\n";
157 opstream << throwkey;
158 opstream << "\nAttack key:\n";
159 opstream << attackkey;
160 opstream << "\nConsole key:\n";
161 opstream << consolekey;
162 opstream << "\nDamage bar:\n";
163 opstream << showdamagebar;
164 opstream << "\nStereoMode:\n";
165 opstream << stereomode;
166 opstream << "\nStereoSeparation:\n";
167 opstream << stereoseparation;
168 opstream << "\nStereoReverse:\n";
169 opstream << stereoreverse;
177 ifstream ipstream(Folders::getConfigFilePath(), std::ios::in);
178 if (ipstream.fail()) {
179 perror(("Couldn't read config file " + Folders::getConfigFilePath()).c_str());
185 printf("Loading config\n");
186 while (!ipstream.eof()) {
187 ipstream.getline(setting, sizeof(setting));
190 // assume lines starting with spaces are all blank
191 if (strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t') {
194 //~ printf("setting : %s\n",setting);
196 if (ipstream.eof() || ipstream.fail()) {
197 fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);
202 if (!strncmp(setting, "Screenwidth", 11)) {
203 ipstream >> kContextWidth;
204 if (kContextWidth < (int)minscreenwidth || kContextWidth > (int)maxscreenwidth) {
205 kContextWidth = (int)minscreenwidth;
207 } else if (!strncmp(setting, "Screenheight", 12)) {
208 ipstream >> kContextHeight;
209 if (kContextHeight < (int)minscreenheight || kContextHeight > (int)maxscreenheight) {
210 kContextHeight = (int)minscreenheight;
212 } else if (!strncmp(setting, "Fullscreen", 10)) {
213 ipstream >> fullscreen;
214 } else if (!strncmp(setting, "Mouse sensitivity", 17)) {
215 ipstream >> usermousesensitivity;
216 } else if (!strncmp(setting, "Blur", 4)) {
217 ipstream >> ismotionblur;
218 } else if (!strncmp(setting, "Overall Detail", 14)) {
220 } else if (!strncmp(setting, "Floating jump", 13)) {
221 ipstream >> floatjump;
222 } else if (!strncmp(setting, "Mouse jump", 10)) {
223 ipstream >> mousejump;
224 } else if (!strncmp(setting, "Ambient sound", 13)) {
225 ipstream >> ambientsound;
226 } else if (!strncmp(setting, "Blood", 5)) {
227 ipstream >> bloodtoggle;
228 } else if (!strncmp(setting, "Auto slomo", 10)) {
229 ipstream >> autoslomo;
230 } else if (!strncmp(setting, "Foliage", 7)) {
232 } else if (!strncmp(setting, "Music", 5)) {
233 ipstream >> musictoggle;
234 } else if (!strncmp(setting, "Trilinear", 9)) {
235 ipstream >> trilinear;
236 } else if (!strncmp(setting, "Decals", 6)) {
237 ipstream >> decalstoggle;
238 } else if (!strncmp(setting, "Invert mouse", 12)) {
239 ipstream >> invertmouse;
240 } else if (!strncmp(setting, "Gamespeed", 9)) {
241 ipstream >> gamespeed;
242 oldgamespeed = gamespeed;
243 if (oldgamespeed == 0) {
247 } else if (!strncmp(setting, "Damage effects", 14)) {
248 ipstream >> damageeffects;
249 } else if (!strncmp(setting, "Text", 4)) {
250 ipstream >> texttoggle;
251 } else if (!strncmp(setting, "Devtools", 8)) {
252 ipstream >> devtools;
253 } else if (!strncmp(setting, "Show Points", 11)) {
254 ipstream >> showpoints;
255 } else if (!strncmp(setting, "Always Blur", 11)) {
256 ipstream >> alwaysblur;
257 } else if (!strncmp(setting, "Immediate mode ", 15)) {
258 ipstream >> immediate;
259 } else if (!strncmp(setting, "Velocity blur", 13)) {
260 ipstream >> velocityblur;
261 } else if (!strncmp(setting, "Volume", 6)) {
263 } else if (!strncmp(setting, "Forward key", 11)) {
264 ipstream >> forwardkey;
265 } else if (!strncmp(setting, "Back key", 8)) {
267 } else if (!strncmp(setting, "Left key", 8)) {
269 } else if (!strncmp(setting, "Right key", 9)) {
270 ipstream >> rightkey;
271 } else if (!strncmp(setting, "Jump key", 8)) {
273 } else if (!strncmp(setting, "Crouch key", 10)) {
274 ipstream >> crouchkey;
275 } else if (!strncmp(setting, "Draw key", 8)) {
277 } else if (!strncmp(setting, "Throw key", 9)) {
278 ipstream >> throwkey;
279 } else if (!strncmp(setting, "Attack key", 10)) {
280 ipstream >> attackkey;
281 } else if (!strncmp(setting, "Console key", 11)) {
282 ipstream >> consolekey;
283 } else if (!strncmp(setting, "Damage bar", 10)) {
284 ipstream >> showdamagebar;
285 } else if (!strncmp(setting, "StereoMode", 10)) {
288 stereomode = (StereoMode)i;
289 } else if (!strncmp(setting, "StereoSeparation", 16)) {
290 ipstream >> stereoseparation;
291 } else if (!strncmp(setting, "StereoReverse", 13)) {
292 ipstream >> stereoreverse;
295 fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string);
298 if (ipstream.fail()) {
299 fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting);
304 if (ipstream.bad()) {
305 fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting);
319 if (screenwidth < minscreenwidth || screenwidth > maxscreenwidth) {
322 if (screenheight < minscreenheight || screenheight > maxscreenheight) {