fix al problema con "const char *", parece que en gcc 4.2.3 andaba, en 4.5.2 no XD
[seni.git] / src / config.cpp
blob307afa437479802f2df45a425c0d7c906e51789e
1 /*SENI, Search for Extra Nibiru Intelligence*/
3 /*
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Copyright SSW Team 2010
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <SDL/SDL.h>
26 #include "all.hpp"
28 Config::Config(void)
32 Config::Config(const sConf *s)
34 this->setConfig(s);
37 void Config::setDefault(void)
39 this->conf.resx = 1024;
40 this->conf.resy = 768;
41 this->conf.bitres = 24;
42 this->conf.sdlflags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_OPENGLBLIT;
45 void Config::setErrorMode(void)
47 this->conf.resx = 640;
48 this->conf.resy = 480;
49 this->conf.bitres = 16;
50 this->conf.sdlflags = SDL_SWSURFACE;
53 void Config::setConfig(const sConf *s)
55 this->conf.sdlflags = s->sdlflags;
56 this->conf.resx = s->resx;
57 this->conf.resy = s->resy;
58 this->conf.bitres = s->bitres;
61 void Config::getConfig(sConf *s)
63 s->sdlflags = this->conf.sdlflags;
64 s->resx = this->conf.resx;
65 s->resy = this->conf.resy;
66 s->bitres = this->conf.bitres;
69 int Config::saveConfig(const char *n)
71 FILE *f;
72 f = fopen(n, "wb");
73 if(!f)
74 return CONFIG_FILE_ERROR;
75 fwrite(&conf, sizeof(sConf), 1, f);
76 fclose(f);
77 return CONFIG_NO_ERROR;
80 int Config::loadConfig(const char *n)
82 FILE *f;
83 f = fopen(n, "rb");
84 if(!f)
85 return CONFIG_FILE_ERROR;
86 fread(&conf, sizeof(sConf), 1, f);
87 fclose(f);
88 return CONFIG_NO_ERROR;
91 int Config::doRes(const char *r, int *x, int *y)
93 char *c;
94 int i;
95 c = (char *)strchr(r, 'x');
96 if(!c)
97 c = (char *)strchr(r, 'X');
98 if(!c)
99 return -1;
100 for(i = 0; r[i]; i++){
101 if((r[i] < '0' || r[i] > '9') && r+i != c)
102 return i+1;
104 *c = 0;
105 *x = atoi(r);
106 *y = atoi(c+1);
107 return 0;