]> git.jsancho.org Git - lugaru.git/blob - Source/Settings.cpp
54bba7a0ec01fbf1ca731ac9c6e8f60c9b67f4fa
[lugaru.git] / Source / Settings.cpp
1 #include "Settings.h"
2 #include "Game.h"
3 #include "Input.h"
4
5 using namespace Game;
6
7 void DefaultSettings()
8 {
9     detail = 1;
10     ismotionblur = 0;
11     usermousesensitivity = 1;
12     newscreenwidth = kContextWidth = 640;
13     newscreenheight = kContextHeight = 480;
14     kBitsPerPixel = 32;
15     floatjump = 0;
16     autoslomo = 1;
17     decals = 1;
18     invertmouse = 0;
19     bloodtoggle = 0;
20     foliage = 1;
21     musictoggle = 1;
22     trilinear = 1;
23     gamespeed = 1;
24     difficulty = 1;
25     damageeffects = 0;
26     texttoggle = 1;
27     alwaysblur = 0;
28     showpoints = 0;
29     showdamagebar = 0;
30     immediate = 0;
31     velocityblur = 0;
32     volume = 0.8f;
33     ambientsound = 1;
34     vblsync = 1;
35     debugmode = 0;
36
37     crouchkey = SDLK_LSHIFT;
38     jumpkey = SDLK_SPACE;
39     leftkey = SDLK_a;
40     forwardkey = SDLK_w;
41     backkey = SDLK_s;
42     rightkey = SDLK_d;
43     drawkey = SDLK_e;
44     throwkey = SDLK_q;
45     attackkey = MOUSEBUTTON1;
46     consolekey = SDLK_BACKQUOTE;
47     chatkey = SDLK_t;
48 }
49
50 void SaveSettings()
51 {
52     if (newdetail < 0)
53         newdetail = 0;
54     if (newdetail > 2)
55         newdetail = 2;
56     if (newscreenwidth > 3000)
57         newscreenwidth = screenwidth;
58     if (newscreenwidth < 0)
59         newscreenwidth = screenwidth;
60     if (newscreenheight > 3000)
61         newscreenheight = screenheight;
62     if (newscreenheight < 0)
63         newscreenheight = screenheight;
64     ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
65     opstream << "Screenwidth:\n";
66     opstream << newscreenwidth;
67     opstream << "\nScreenheight:\n";
68     opstream << newscreenheight;
69     opstream << "\nMouse sensitivity:\n";
70     opstream << usermousesensitivity;
71     opstream << "\nBlur(0,1):\n";
72     opstream << ismotionblur;
73     opstream << "\nOverall Detail(0,1,2) higher=better:\n";
74     opstream << newdetail;
75     opstream << "\nFloating jump:\n";
76     opstream << floatjump;
77     opstream << "\nMouse jump:\n";
78     opstream << mousejump;
79     opstream << "\nAmbient sound:\n";
80     opstream << ambientsound;
81     opstream << "\nBlood (0,1,2):\n";
82     opstream << bloodtoggle;
83     opstream << "\nAuto slomo:\n";
84     opstream << autoslomo;
85     opstream << "\nFoliage:\n";
86     opstream << foliage;
87     opstream << "\nMusic:\n";
88     opstream << musictoggle;
89     opstream << "\nTrilinear:\n";
90     opstream << trilinear;
91     opstream << "\nDecals(shadows,blood puddles,etc):\n";
92     opstream << decals;
93     opstream << "\nInvert mouse:\n";
94     opstream << invertmouse;
95     opstream << "\nGamespeed:\n";
96     if (oldgamespeed == 0)
97         oldgamespeed = 1;
98     opstream << oldgamespeed;
99     opstream << "\nDifficulty(0,1,2) higher=harder:\n";
100     opstream << difficulty;
101     opstream << "\nDamage effects(blackout, doublevision):\n";
102     opstream << damageeffects;
103     opstream << "\nText:\n";
104     opstream << texttoggle;
105     opstream << "\nDebug:\n";
106     opstream << debugmode;
107     opstream << "\nVBL Sync:\n";
108     opstream << vblsync;
109     opstream << "\nShow Points:\n";
110     opstream << showpoints;
111     opstream << "\nAlways Blur:\n";
112     opstream << alwaysblur;
113     opstream << "\nImmediate mode (turn on on G5):\n";
114     opstream << immediate;
115     opstream << "\nVelocity blur:\n";
116     opstream << velocityblur;
117     opstream << "\nVolume:\n";
118     opstream << volume;
119     opstream << "\nForward key:\n";
120     opstream << Input::keyToChar(forwardkey);
121     opstream << "\nBack key:\n";
122     opstream << Input::keyToChar(backkey);
123     opstream << "\nLeft key:\n";
124     opstream << Input::keyToChar(leftkey);
125     opstream << "\nRight key:\n";
126     opstream << Input::keyToChar(rightkey);
127     opstream << "\nJump key:\n";
128     opstream << Input::keyToChar(jumpkey);
129     opstream << "\nCrouch key:\n";
130     opstream << Input::keyToChar(crouchkey);
131     opstream << "\nDraw key:\n";
132     opstream << Input::keyToChar(drawkey);
133     opstream << "\nThrow key:\n";
134     opstream << Input::keyToChar(throwkey);
135     opstream << "\nAttack key:\n";
136     opstream << Input::keyToChar(attackkey);
137     opstream << "\nConsole key:\n";
138     opstream << Input::keyToChar(consolekey);
139     opstream << "\nChat key:\n";
140     opstream << Input::keyToChar(chatkey);
141     opstream << "\nDamage bar:\n";
142     opstream << showdamagebar;
143     opstream << "\nStereoMode:\n";
144     opstream << stereomode;
145     opstream << "\nStereoSeparation:\n";
146     opstream << stereoseparation;
147     opstream << "\nStereoReverse:\n";
148     opstream << stereoreverse;
149     opstream.close();
150 }
151
152 bool LoadSettings()
153 {
154     ifstream ipstream(ConvertFileName(":Data:config.txt"), std::ios::in);
155     if ( !ipstream || ipstream.fail() ) {
156         printf("Config file not found\n");
157         return false;
158     }
159     char setting[256];
160     char string[256];
161
162     printf("Loading config\n");
163     while (!ipstream.eof()) {
164         ipstream.getline( setting, sizeof(setting) );
165
166         // skip blank lines
167         // assume lines starting with spaces are all blank
168         if ( strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t')
169             continue;
170         //~ printf("setting : %s\n",setting);
171
172         if ( ipstream.eof() || ipstream.fail() ) {
173             fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);
174             ipstream.close();
175             return false;
176         }
177
178
179         if ( !strncmp(setting, "Screenwidth", 11) ) {
180             ipstream >> kContextWidth;
181         } else if ( !strncmp(setting, "Screenheight", 12) ) {
182             ipstream >> kContextHeight;
183         } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) {
184             ipstream >> usermousesensitivity;
185         } else if ( !strncmp(setting, "Blur", 4) ) {
186             ipstream >> ismotionblur;
187         } else if ( !strncmp(setting, "Overall Detail", 14) ) {
188             ipstream >> detail;
189             if (detail != 0)
190                 kBitsPerPixel = 32;
191             else
192                 kBitsPerPixel = 16;
193         } else if ( !strncmp(setting, "Floating jump", 13) ) {
194             ipstream >> floatjump;
195         } else if ( !strncmp(setting, "Mouse jump", 10) ) {
196             ipstream >> mousejump;
197         } else if ( !strncmp(setting, "Ambient sound", 13) ) {
198             ipstream >> ambientsound;
199         } else if ( !strncmp(setting, "Blood ", 6) ) {
200             ipstream >> bloodtoggle;
201         } else if ( !strncmp(setting, "Auto slomo", 10) ) {
202             ipstream >> autoslomo;
203         } else if ( !strncmp(setting, "Foliage", 7) ) {
204             ipstream >> foliage;
205         } else if ( !strncmp(setting, "Music", 5) ) {
206             ipstream >> musictoggle;
207         } else if ( !strncmp(setting, "Trilinear", 9) ) {
208             ipstream >> trilinear;
209         } else if ( !strncmp(setting, "Decals", 6) ) {
210             ipstream >> decals;
211         } else if ( !strncmp(setting, "Invert mouse", 12) ) {
212             ipstream >> invertmouse;
213         } else if ( !strncmp(setting, "Gamespeed", 9) ) {
214             ipstream >> gamespeed;
215             oldgamespeed = gamespeed;
216             if (oldgamespeed == 0) {
217                 gamespeed = 1;
218                 oldgamespeed = 1;
219             }
220         } else if ( !strncmp(setting, "Difficulty", 10) ) {
221             ipstream >> difficulty;
222         } else if ( !strncmp(setting, "Damage effects", 14) ) {
223             ipstream >> damageeffects;
224         } else if ( !strncmp(setting, "Text", 4) ) {
225             ipstream >> texttoggle;
226         } else if ( !strncmp(setting, "Debug", 5) ) {
227             ipstream >> debugmode;
228         } else if ( !strncmp(setting, "VBL Sync", 8) ) {
229             ipstream >> vblsync;
230         } else if ( !strncmp(setting, "Show Points", 11) ) {
231             ipstream >> showpoints;
232         } else if ( !strncmp(setting, "Always Blur", 11) ) {
233             ipstream >> alwaysblur;
234         } else if ( !strncmp(setting, "Immediate mode ", 15) ) {
235             ipstream >> immediate;
236         } else if ( !strncmp(setting, "Velocity blur", 13) ) {
237             ipstream >> velocityblur;
238         } else if ( !strncmp(setting, "Volume", 6) ) {
239             ipstream >> volume;
240         } else if ( !strncmp(setting, "Forward key", 11) ) {
241             ipstream.getline( string, sizeof(string) );
242             forwardkey = Input::CharToKey(string);
243         } else if ( !strncmp(setting, "Back key", 8) ) {
244             ipstream.getline( string, sizeof(string) );
245             backkey = Input::CharToKey(string);
246         } else if ( !strncmp(setting, "Left key", 8) ) {
247             ipstream.getline( string, sizeof(string) );
248             leftkey = Input::CharToKey(string);
249         } else if ( !strncmp(setting, "Right key", 9) ) {
250             ipstream.getline( string, sizeof(string) );
251             rightkey = Input::CharToKey(string);
252         } else if ( !strncmp(setting, "Jump key", 8) ) {
253             ipstream.getline( string, sizeof(string) );
254             jumpkey = Input::CharToKey(string);
255         } else if ( !strncmp(setting, "Crouch key", 10) ) {
256             ipstream.getline( string, sizeof(string) );
257             crouchkey = Input::CharToKey(string);
258         } else if ( !strncmp(setting, "Draw key", 8) ) {
259             ipstream.getline( string, sizeof(string) );
260             drawkey = Input::CharToKey(string);
261         } else if ( !strncmp(setting, "Throw key", 9) ) {
262             ipstream.getline( string, sizeof(string) );
263             throwkey = Input::CharToKey(string);
264         } else if ( !strncmp(setting, "Attack key", 10) ) {
265             ipstream.getline( string, sizeof(string) );
266             attackkey = Input::CharToKey(string);
267         } else if ( !strncmp(setting, "Console key", 11) ) {
268             ipstream.getline( string, sizeof(string) );
269             consolekey = Input::CharToKey(string);
270         } else if ( !strncmp(setting, "Chat key", 8) ) {
271             ipstream.getline( string, sizeof(string) );
272             chatkey = Input::CharToKey(string);
273         } else if ( !strncmp(setting, "Damage bar", 10) ) {
274             ipstream >> showdamagebar;
275         } else if ( !strncmp(setting, "StereoMode", 10) ) {
276             int i;
277             ipstream >> i;
278             stereomode = (StereoMode)i;
279         } else if ( !strncmp(setting, "StereoSeparation", 16) ) {
280             ipstream >> stereoseparation;
281         } else if ( !strncmp(setting, "StereoReverse", 13) ) {
282             ipstream >> stereoreverse;
283         } else {
284             ipstream >> string;
285             fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string);
286         }
287
288         if ( ipstream.fail() ) {
289             fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting);
290             ipstream.close();
291             return false;
292         }
293
294         if ( ipstream.bad() ) {
295             fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting);
296             ipstream.close();
297             return false;
298         }
299     }
300
301     ipstream.close();
302
303     if (detail > 2)
304         detail = 2;
305     if (detail < 0)
306         detail = 0;
307     if (screenwidth < 0)
308         screenwidth = 640;
309     if (screenheight < 0)
310         screenheight = 480;
311
312     return true;
313 }