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