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