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