Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

ExCOptions.cpp

Go to the documentation of this file.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExCOptions.cpp,v 1.7 2002/08/06 16:52:59 binny Exp $
00021  *
00022  */
00023 
00024 #include "ExCOptions.h"
00025 
00026 ExCOptions::ExCOptions () {
00027         type_of_debug = EXC_NORMAL;
00028 #ifdef UNIX_SRC
00029         std::string where = getenv ("HOME");
00030         where += EXNIHILO_REP_NAME;
00031         where += "/options";
00032         options_file = new ExCFile (where);
00033 #endif
00034         
00035         // for the resolution
00036         resolution_x = 800;
00037         resolution_y = 600;
00038         depth = 16;
00039         rate = 75;
00040         
00041         fullscreen = "yes";
00042         fps = "yes";
00043         
00044         debug_style = EXC_NORMAL;
00045 }
00046 
00047 bool ExCOptions::create_options_file (void) {
00048 #ifdef UNIX_SRC
00049         std::string where = getenv ("HOME");
00050         where += EXNIHILO_REP_NAME;
00051 
00052         // checking for the directory
00053         struct stat stbuf;
00054         if (stat (where.data (), &stbuf) == 0) {
00055                 if (! S_ISDIR (stbuf.st_mode)) {
00056                         std::cout << where << " is not a directory, please remove it !!!" 
00057                                                         << std::endl;
00058                         return false;
00059                 } else {
00060                         std::cout << where << " created" << std::endl;
00061                 }
00062         } else {
00063                 if (mkdir (where.data (), 0755) != 0) {
00064                         std::cout << "Can not create " << where << std::endl;
00065                         return false;
00066                 } else {
00067                         std::cout << where << " created" << std::endl;
00068                 }
00069         }
00070         // ok, now, we create the options file
00071         options_file->add ("# ExNihilo Options file");
00072         options_file->add ("# you can comment a line with '#'");
00073         options_file->addLine ();
00074 
00075         // DEBUG
00076         options_file->add ("# type of debug : NORMAL, DEBUG, TRACE, LOG");
00077         options_file->add ("# you need to compile ExNihilo with debug enabled to use this option");
00078         options_file->add ("debug.type: NORMAL");
00079         options_file->addLine ();
00080 
00081         // SCREEN
00082         options_file->add ("# resolution of the screen : format WidthxHeigth:bpp@frequency");
00083         options_file->add ("# WARNING: a too big frequency may damage your screen and/or video card");
00084         options_file->add ("screen.resolution: 800x600:16@75");
00085         options_file->addLine ();
00086         options_file->add ("# start in fullscreen ? [true|false]");
00087         options_file->add ("screen.fullscreen: yes");
00088         options_file->addLine ();
00089         options_file->add ("# show fps ? [true|false]");
00090         options_file->add ("screen.fps: yes");
00091         options_file->addLine ();
00092 
00093 #endif // UNIX_SRC
00094 
00095         return true;
00096 }
00097 
00098 bool ExCOptions::init (void) {
00099 #ifdef UNIX_SRC
00100         options_file->setOpenMode (RO);
00101         if (! options_file->exist ()) {
00102                 create_options_file ();
00103         }
00104 #endif
00105         load (EXC_OPTIONS_ALL);
00106 
00107         return true;
00108 }
00109 
00110 bool ExCOptions::load (int type) {
00111 #ifdef UNIX_SRC
00112         options_file->setOpenMode (RO);
00113         // we take the content of the options file
00114         std::vector<std::string> v = options_file->getContent ();
00115         // we analyse this content
00116         std::vector<std::string>::iterator i = v.begin ();
00117         std::string analyze;
00118         while (i != v.end ()) {
00119                 analyze = *i++;
00120                 if (analyze[0] == '#') 
00121                         // if line begin by # so it's a comment
00122                         continue;
00123                 else {
00124                         if (analyze.find ('.') < analyze.size ()) {
00125                                 string type = analyze.substr (0, analyze.find ('.'));
00126                                 string under_type = analyze.substr (analyze.find ('.') + 1, analyze.size ());
00127                                 under_type = analyze.substr (analyze.find ('.') + 1, analyze.find (':') - analyze.find ('.') - 1);
00128                                 string value = analyze.substr (analyze.find (':') + 2, analyze.size ());
00129                                 
00130                                 if (type == "debug") {
00131                                         if (under_type == "type") {
00132                                                 if (value == "NORMAL") 
00133                                                         debug_style = EXC_NORMAL;
00134                                                 else if (value == "DEBUG") 
00135                                                         debug_style = EXC_DEBUG;
00136                                                 else if (value == "TRACE") 
00137                                                         debug_style = EXC_TRACE;
00138                                                 else if (value == "LOG") 
00139                                                         debug_style = EXC_LOG;
00140                                         }
00141                                 } else if (type == "screen") {
00142                                         if (under_type == "resolution") {
00143                                                 resolution_x = atoi (value.substr (0, value.find ('x')).data ());
00144                                                 value.erase (0, value.find ('x') + 1);
00145                                                 resolution_y = atoi (value.substr (0, value.find (':')).data ());
00146                                                 value.erase (0, value.find (':') + 1);
00147                                                 depth = atoi (value.substr (0, value.find ('@')).data ());
00148                                                 value.erase (0, value.find ('@') + 1);
00149                                                 rate = atoi (value.data ());
00150                                         } else if (under_type == "fullscreen") {
00151                                                 fullscreen = value;
00152                                         } else if (under_type == "fps") {
00153                                                 fps = value;
00154                                         }
00155                                 }
00156                         }
00157                 }                               
00158         }
00159 #endif  
00160         return true;
00161 }
00162 
00163 bool ExCOptions::load (void) {
00164         return load (EXC_OPTIONS_ALL);
00165 }
00166 
00167 bool ExCOptions::reload (void) {
00168         return load (EXC_OPTIONS_RELOAD);
00169 }
00170 
00171 bool ExCOptions::getWindowFullscreen (void) { 
00172         return (fullscreen == "yes") ? true : false; 
00173 }
00174 
00175 bool ExCOptions::getWindowShowfps (void) { 
00176         return (fps == "yes") ? true : false; 
00177 }

Generated on Tue Dec 10 18:20:04 2002 for ExNihilo by doxygen1.3-rc1