2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - 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/>.
24 #include "Utils/Folders.h"
28 void DefaultSettings()
32 usermousesensitivity = 1;
33 newscreenwidth = kContextWidth = 1024;
34 newscreenheight = kContextHeight = 768;
56 crouchkey = SDL_SCANCODE_LSHIFT;
57 jumpkey = SDL_SCANCODE_SPACE;
58 leftkey = SDL_SCANCODE_A;
59 forwardkey = SDL_SCANCODE_W;
60 backkey = SDL_SCANCODE_S;
61 rightkey = SDL_SCANCODE_D;
62 drawkey = SDL_SCANCODE_E;
63 throwkey = SDL_SCANCODE_Q;
64 attackkey = MOUSEBUTTON1;
65 consolekey = SDL_SCANCODE_GRAVE;
74 if (newscreenwidth > 3000)
75 newscreenwidth = screenwidth;
76 if (newscreenwidth < 0)
77 newscreenwidth = screenwidth;
78 if (newscreenheight > 3000)
79 newscreenheight = screenheight;
80 if (newscreenheight < 0)
81 newscreenheight = screenheight;
83 ofstream opstream(Folders::getConfigFilePath());
84 if (opstream.fail()) {
85 perror(("Couldn't save config file " + Folders::getConfigFilePath()).c_str());
88 opstream << "Screenwidth:\n";
89 opstream << newscreenwidth;
90 opstream << "\nScreenheight:\n";
91 opstream << newscreenheight;
92 opstream << "\nFullscreen:\n";
93 opstream << fullscreen;
94 opstream << "\nMouse sensitivity:\n";
95 opstream << usermousesensitivity;
96 opstream << "\nBlur(0,1):\n";
97 opstream << ismotionblur;
98 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
99 opstream << newdetail;
100 opstream << "\nFloating jump:\n";
101 opstream << floatjump;
102 opstream << "\nMouse jump:\n";
103 opstream << mousejump;
104 opstream << "\nAmbient sound:\n";
105 opstream << ambientsound;
106 opstream << "\nBlood (0,1,2):\n";
107 opstream << bloodtoggle;
108 opstream << "\nAuto slomo:\n";
109 opstream << autoslomo;
110 opstream << "\nFoliage:\n";
112 opstream << "\nMusic:\n";
113 opstream << musictoggle;
114 opstream << "\nTrilinear:\n";
115 opstream << trilinear;
116 opstream << "\nDecals(shadows,blood puddles,etc):\n";
118 opstream << "\nInvert mouse:\n";
119 opstream << invertmouse;
120 opstream << "\nGamespeed:\n";
121 if (oldgamespeed == 0)
123 opstream << oldgamespeed;
124 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
125 opstream << difficulty;
126 opstream << "\nDamage effects(blackout, doublevision):\n";
127 opstream << damageeffects;
128 opstream << "\nText:\n";
129 opstream << texttoggle;
130 opstream << "\nShow Points:\n";
131 opstream << showpoints;
132 opstream << "\nAlways Blur:\n";
133 opstream << alwaysblur;
134 opstream << "\nImmediate mode (turn on on G5):\n";
135 opstream << immediate;
136 opstream << "\nVelocity blur:\n";
137 opstream << velocityblur;
138 opstream << "\nVolume:\n";
140 opstream << "\nForward key:\n";
141 opstream << forwardkey;
142 opstream << "\nBack key:\n";
144 opstream << "\nLeft key:\n";
146 opstream << "\nRight key:\n";
147 opstream << rightkey;
148 opstream << "\nJump key:\n";
150 opstream << "\nCrouch key:\n";
151 opstream << crouchkey;
152 opstream << "\nDraw key:\n";
154 opstream << "\nThrow key:\n";
155 opstream << throwkey;
156 opstream << "\nAttack key:\n";
157 opstream << attackkey;
158 opstream << "\nConsole key:\n";
159 opstream << consolekey;
160 opstream << "\nDamage bar:\n";
161 opstream << showdamagebar;
162 opstream << "\nStereoMode:\n";
163 opstream << stereomode;
164 opstream << "\nStereoSeparation:\n";
165 opstream << stereoseparation;
166 opstream << "\nStereoReverse:\n";
167 opstream << stereoreverse;
174 ifstream ipstream(Folders::getConfigFilePath(), std::ios::in);
175 if ( ipstream.fail() ) {
176 perror(("Couldn't read config file " + Folders::getConfigFilePath()).c_str());
182 printf("Loading config\n");
183 while (!ipstream.eof()) {
184 ipstream.getline( setting, sizeof(setting) );
187 // assume lines starting with spaces are all blank
188 if ( strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t')
190 //~ printf("setting : %s\n",setting);
192 if ( ipstream.eof() || ipstream.fail() ) {
193 fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);
199 if ( !strncmp(setting, "Screenwidth", 11) ) {
200 ipstream >> kContextWidth;
201 } else if ( !strncmp(setting, "Screenheight", 12) ) {
202 ipstream >> kContextHeight;
203 } else if ( !strncmp(setting, "Fullscreen", 10) ) {
204 ipstream >> fullscreen;
205 } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) {
206 ipstream >> usermousesensitivity;
207 } else if ( !strncmp(setting, "Blur", 4) ) {
208 ipstream >> ismotionblur;
209 } else if ( !strncmp(setting, "Overall Detail", 14) ) {
211 } else if ( !strncmp(setting, "Floating jump", 13) ) {
212 ipstream >> floatjump;
213 } else if ( !strncmp(setting, "Mouse jump", 10) ) {
214 ipstream >> mousejump;
215 } else if ( !strncmp(setting, "Ambient sound", 13) ) {
216 ipstream >> ambientsound;
217 } else if ( !strncmp(setting, "Blood ", 6) ) {
218 ipstream >> bloodtoggle;
219 } else if ( !strncmp(setting, "Auto slomo", 10) ) {
220 ipstream >> autoslomo;
221 } else if ( !strncmp(setting, "Foliage", 7) ) {
223 } else if ( !strncmp(setting, "Music", 5) ) {
224 ipstream >> musictoggle;
225 } else if ( !strncmp(setting, "Trilinear", 9) ) {
226 ipstream >> trilinear;
227 } else if ( !strncmp(setting, "Decals", 6) ) {
229 } else if ( !strncmp(setting, "Invert mouse", 12) ) {
230 ipstream >> invertmouse;
231 } else if ( !strncmp(setting, "Gamespeed", 9) ) {
232 ipstream >> gamespeed;
233 oldgamespeed = gamespeed;
234 if (oldgamespeed == 0) {
238 } else if ( !strncmp(setting, "Difficulty", 10) ) {
239 ipstream >> difficulty;
240 } else if ( !strncmp(setting, "Damage effects", 14) ) {
241 ipstream >> damageeffects;
242 } else if ( !strncmp(setting, "Text", 4) ) {
243 ipstream >> texttoggle;
244 } else if ( !strncmp(setting, "Show Points", 11) ) {
245 ipstream >> showpoints;
246 } else if ( !strncmp(setting, "Always Blur", 11) ) {
247 ipstream >> alwaysblur;
248 } else if ( !strncmp(setting, "Immediate mode ", 15) ) {
249 ipstream >> immediate;
250 } else if ( !strncmp(setting, "Velocity blur", 13) ) {
251 ipstream >> velocityblur;
252 } else if ( !strncmp(setting, "Volume", 6) ) {
254 } else if ( !strncmp(setting, "Forward key", 11) ) {
255 ipstream >> forwardkey;
256 } else if ( !strncmp(setting, "Back key", 8) ) {
258 } else if ( !strncmp(setting, "Left key", 8) ) {
260 } else if ( !strncmp(setting, "Right key", 9) ) {
261 ipstream >> rightkey;
262 } else if ( !strncmp(setting, "Jump key", 8) ) {
264 } else if ( !strncmp(setting, "Crouch key", 10) ) {
265 ipstream >> crouchkey;
266 } else if ( !strncmp(setting, "Draw key", 8) ) {
268 } else if ( !strncmp(setting, "Throw key", 9) ) {
269 ipstream >> throwkey;
270 } else if ( !strncmp(setting, "Attack key", 10) ) {
271 ipstream >> attackkey;
272 } else if ( !strncmp(setting, "Console key", 11) ) {
273 ipstream >> consolekey;
274 } else if ( !strncmp(setting, "Damage bar", 10) ) {
275 ipstream >> showdamagebar;
276 } else if ( !strncmp(setting, "StereoMode", 10) ) {
279 stereomode = (StereoMode)i;
280 } else if ( !strncmp(setting, "StereoSeparation", 16) ) {
281 ipstream >> stereoseparation;
282 } else if ( !strncmp(setting, "StereoReverse", 13) ) {
283 ipstream >> stereoreverse;
286 fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string);
289 if ( ipstream.fail() ) {
290 fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting);
295 if ( ipstream.bad() ) {
296 fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting);
310 if (screenheight < 0)