Config Class Reference

#include <Config.h>

List of all members.

Public Member Functions

 Config (const std::string filename)
 ~Config ()
bool CheckExtensions ()
bool CheckVBO ()
int GetWinWidth ()
int GetWinHeight ()
bool CheckFullscreen ()
bool CheckSDLParachute ()
bool CheckCompressTextures ()
unsigned int GetTicksBetweenBattles ()
unsigned int GetNumberALSources ()
bool DebugLogEnabled ()
std::string GetStartingShipType ()

Static Public Member Functions

static bool OpenConfig (const std::string filename)
static void CloseConfig ()

Static Public Attributes

static Configs_config = NULL

Private Member Functions

void LogConfig ()

Private Attributes

int m_winWidth
int m_winHeight
bool m_fullscreen
bool m_useVBO
bool m_useSDLParachute
bool m_compressTextures
unsigned int m_ticksBetweenBattles
unsigned int m_numberALSources
bool m_debugLogMode
std::string m_startingShipType


Detailed Description

Definition at line 10 of file Config.h.


Constructor & Destructor Documentation

Config::Config ( const std::string  filename  ) 

Definition at line 18 of file Config.cpp.

References LogConfig(), m_compressTextures, m_debugLogMode, m_fullscreen, m_numberALSources, m_startingShipType, m_ticksBetweenBattles, m_useSDLParachute, m_useVBO, m_winHeight, m_winWidth, Log::Message(), Log::s_log, and Log::SetDebugMode().

Referenced by OpenConfig().

00018                                        {
00019   TiXmlDocument doc( filename );
00020   TiXmlElement* config;
00021   TiXmlElement* resolution;
00022   TiXmlElement* temp;
00023   TiXmlText* data;
00024   int n;
00025 
00026   m_winWidth = 640;
00027   m_winHeight = 480;
00028   m_fullscreen = false;
00029   m_useVBO = false;
00030   m_useSDLParachute = true;
00031   m_compressTextures = true;
00032   m_ticksBetweenBattles = 20000;
00033   m_numberALSources = 16;
00034   m_debugLogMode = false;
00035   m_startingShipType = "Sloop";
00036 
00037   doc.LoadFile();
00038   if (doc.Error()) {
00039     Log::s_log->Message("Warning: %s (line %d)  Using defaults", doc.ErrorDesc(), doc.ErrorRow());
00040     LogConfig();
00041     return;
00042   }
00043 
00044   config = doc.FirstChildElement("GameConfiguration"); // This gets the <GameConfiguration> tag
00045   if (config == NULL) {
00046     Log::s_log->Message("Warning: <GameConfiguration> did not parse correctly.");
00047     LogConfig();
00048     return;
00049   }
00050 
00051   try {
00052     resolution = config->FirstChildElement("Resolution"); // This gets <Resolution>
00053     if (resolution == NULL) throw 0;
00054 
00055     // Deal with Resolution
00056     temp = resolution->FirstChildElement("Width");
00057     if (temp == NULL) throw 0;
00058     data = temp->FirstChild()->ToText();
00059     if (data == NULL) throw 1;
00060     n = sscanf(data->Value(), "%d", &m_winWidth);
00061     if (n != 1) throw 1;
00062 
00063     temp = resolution->FirstChildElement("Height");
00064     if (temp == NULL) throw 0;
00065     data = temp->FirstChild()->ToText();
00066     if (data == NULL) throw 2;
00067     n = sscanf(data->Value(), "%d", &m_winHeight);
00068     if (n != 1) throw 2;
00069   } catch (int i) {
00070     switch (i) {
00071     case 0:
00072       Log::s_log->Message("Warning: <Resolution> did not parse correctly");
00073       break;
00074     case 1:
00075       Log::s_log->Message("Warning: Invalid <Width> data, using defaults");
00076       break;
00077     case 2:
00078       Log::s_log->Message("Warning: Invalid <Height> data, using defaults");
00079       break;
00080     default:
00081       // Shouldn't get here
00082       Log::s_log->Message("Warning: Unknown <Resolution> error");
00083       break;
00084     }
00085 
00086     // Set it back to the defaults
00087     m_winWidth = 640;
00088     m_winHeight = 480;
00089   }
00090 
00091   try {
00092     // Deal with Fullscreen
00093     temp = config->FirstChildElement("Fullscreen");
00094     if (temp == NULL) throw 0;
00095 
00096     data = temp->FirstChild()->ToText();
00097     if (data == NULL) throw 1;
00098     if (strcmp(data->Value(), "true") == 0) {
00099       m_fullscreen = true;
00100     } else if (strcmp(data->Value(), "false") == 0) {
00101       m_fullscreen = false;
00102     } else {
00103       throw 1;
00104     }
00105   } catch (int i) {
00106     switch (i) {
00107     case 0:
00108       Log::s_log->Message("Warning: <Fullscreen> did not parse correctly");
00109       break;
00110     case 1:
00111       Log::s_log->Message("Warning: Invalid Fullscreen data, using default");
00112       break;
00113     default:
00114       // Shouldn't get here
00115       Log::s_log->Message("Warning: Unknown <Fullscreen> error");
00116       break;
00117     }
00118   }
00119 
00120   try {
00121     // Deal with VBOs
00122     temp = config->FirstChildElement("VBO");
00123     if (temp == NULL) throw 0;
00124 
00125     data = temp->FirstChild()->ToText();
00126     if (data == NULL) throw 1;
00127     if (strcmp(data->Value(), "true") == 0) {
00128       m_useVBO = true;
00129     } else if (strcmp(data->Value(), "false") == 0) {
00130       m_useVBO = false;
00131     } else {
00132       throw 1;
00133     }
00134   } catch (int i) {
00135     switch (i) {
00136     case 0:
00137       Log::s_log->Message("Warning: <VBO> did not parse correctly");
00138       break;
00139     case 1:
00140       Log::s_log->Message("Warning: Invalid VBO data, using default");
00141       break;
00142     default:
00143       // Shouldn't get here
00144       Log::s_log->Message("Warning: Unknown <VBO> error");
00145       break;
00146     }
00147   }
00148 
00149   try {
00150     // Deal with SDLParachute
00151     temp = config->FirstChildElement("SDLParachute");
00152     if (temp == NULL) throw 0;
00153 
00154     data = temp->FirstChild()->ToText();
00155     if (data == NULL) throw 1;
00156     if (strcmp(data->Value(), "true") == 0) {
00157       m_useSDLParachute = true;
00158     } else if (strcmp(data->Value(), "false") == 0) {
00159       m_useSDLParachute = false;
00160     } else {
00161       throw 1;
00162     }
00163   } catch (int i) {
00164     switch (i) {
00165     case 0:
00166       Log::s_log->Message("Warning: <SDLParachute> did not parse correctly");
00167       break;
00168     case 1:
00169       Log::s_log->Message("Warning: Invalid SDLParachute data, using default");
00170       break;
00171     default:
00172       // Shouldn't get here
00173       Log::s_log->Message("Warning: Unknown <SDLParachute> error");
00174       break;
00175     }
00176   }
00177 
00178   try {
00179     // Deal with CompressTextures
00180     temp = config->FirstChildElement("CompressTextures");
00181     if (temp == NULL) throw 0;
00182 
00183     data = temp->FirstChild()->ToText();
00184     if (data == NULL) throw 1;
00185     if (strcmp(data->Value(), "true") == 0) {
00186       m_compressTextures = true;
00187     } else if (strcmp(data->Value(), "false") == 0) {
00188       m_compressTextures = false;
00189     } else {
00190       throw 1;
00191     }
00192   } catch (int i) {
00193     switch (i) {
00194     case 0:
00195       Log::s_log->Message("Warning: <CompressTextures> did not parse correctly");
00196       break;
00197     case 1:
00198       Log::s_log->Message("Warning: Invalid CompressTexture data, using default");
00199       break;
00200     default:
00201       // Shouldn't get here
00202       Log::s_log->Message("Warning: Unknown <CompressTexture> error");
00203       break;
00204     }
00205   }
00206 
00207   try {
00208     // Deal with TicksBetweenBattles
00209     temp = config->FirstChildElement("TicksBetweenBattles");
00210     if (temp == NULL) throw 0;
00211 
00212     data = temp->FirstChild()->ToText();
00213     if (data == NULL) throw 1;
00214     n = sscanf(data->Value(), "%u", &m_ticksBetweenBattles);
00215     if (n != 1) throw 1;
00216   } catch (int i) {
00217     switch (i) {
00218     case 0:
00219       Log::s_log->Message("Warning: <TicksBetweenBattles> did not parse correctly");
00220       break;
00221     case 1:
00222       Log::s_log->Message("Warning: Invalid TicksBetweenBattles data, using default");
00223       break;
00224     default:
00225       // Shouldn't get here
00226       Log::s_log->Message("Warning: Unknown <TicksBetweenBattles> error");
00227       break;
00228     }
00229   }
00230 
00231   try {
00232     // Deal with NumberALSources
00233     temp = config->FirstChildElement("NumberALSources");
00234     if (temp == NULL) throw 0;
00235 
00236     data = temp->FirstChild()->ToText();
00237     if (data == NULL) throw 1;
00238     n = sscanf(data->Value(), "%u", &m_numberALSources);
00239     if (n != 1) throw 1;
00240   } catch (int i) {
00241     switch (i) {
00242     case 0:
00243       Log::s_log->Message("Warning: <NumberALSources> did not parse correctly");
00244       break;
00245     case 1:
00246       Log::s_log->Message("Warning: Invalid NumberALSources data, using default");
00247       break;
00248     default:
00249       // Shouldn't get here
00250       Log::s_log->Message("Warning: Unknown <NumberALSources> error");
00251       break;
00252     }
00253   }
00254 
00255   try {
00256     // Deal with debug log mode
00257     temp = config->FirstChildElement("DebugLogMode");
00258     if (temp == NULL) throw 0;
00259 
00260     data = temp->FirstChild()->ToText();
00261     if (data == NULL) throw 1;
00262     if (strcmp(data->Value(), "true") == 0) {
00263       m_debugLogMode = true;
00264     } else if (strcmp(data->Value(), "false") == 0) {
00265       m_debugLogMode = false;
00266     } else {
00267       throw 1;
00268     }
00269   } catch (int i) {
00270     switch (i) {
00271     case 0:
00272       Log::s_log->Message("Warning: <DebugLogMode> did not parse correctly");
00273       break;
00274     case 1:
00275       Log::s_log->Message("Warning: Invalid DebugLogMode data, using default");
00276       break;
00277     default:
00278       // Shouldn't get here
00279       Log::s_log->Message("Warning: Unknown <DebugLogMode> error");
00280       break;
00281     }
00282   }
00283   Log::s_log->SetDebugMode(m_debugLogMode);
00284 
00285   try {
00286     // Deal with StartingShipType
00287     temp = config->FirstChildElement("StartingShipType");
00288     if (temp == NULL) throw 0;
00289 
00290     data = temp->FirstChild()->ToText();
00291     if (data == NULL) throw 1;
00292     m_startingShipType = data->Value();
00293   } catch (int i) {
00294     switch (i) {
00295       case 0:
00296         Log::s_log->Message("Warning: <StartingShipType> did not parse correctly");
00297         break;
00298       case 1:
00299         Log::s_log->Message("Warning: Invalid StartingShipType data, using default");
00300         break;
00301       default:
00302       // Shouldn't get here
00303         Log::s_log->Message("Warning: Unknown <StartingShipType> error");
00304         break;
00305     }
00306   }
00307 
00308   LogConfig();
00309 }

Config::~Config (  ) 

Definition at line 312 of file Config.cpp.

00312                 {
00313 }


Member Function Documentation

bool Config::CheckCompressTextures (  ) 

Definition at line 362 of file Config.cpp.

References m_compressTextures.

Referenced by BuildTexture().

00362                                    {
00363   return m_compressTextures;
00364 }

bool Config::CheckExtensions (  ) 

Definition at line 317 of file Config.cpp.

References CheckVBO(), m_useVBO, Log::Message(), s_config, and Log::s_log.

00317                              {
00318   // Check multi-texturing functions
00319   if (!GLEE_ARB_multitexture) {
00320     // Probably should just throw an exception
00321     Log::s_log->Message("Error: Your video card and/or drivers do not support multitexturing");
00322     return false;
00323   }
00324 
00325   // Check vertex array drawing function
00326   if (!GLEE_EXT_draw_range_elements) {
00327     // Probably should just throw an exception
00328     Log::s_log->Message("Error: Your video card and/or drivers do not support glDrawRangeElements");
00329     return false;
00330   }
00331 
00332   // Check VBOs if enabled
00333   if (Config::s_config->CheckVBO() && !GLEE_ARB_vertex_buffer_object) {
00334     m_useVBO = false;
00335     Log::s_log->Message("Warning: Your video card and/or drivers do not support VBOs, falling back on VAs");
00336   }
00337 
00338   // We have multitexturing, so we can continue
00339   return true;
00340 }

bool Config::CheckFullscreen (  ) 

Definition at line 354 of file Config.cpp.

References m_fullscreen.

00354                              {
00355   return m_fullscreen;
00356 }

bool Config::CheckSDLParachute (  ) 

Definition at line 358 of file Config.cpp.

References m_useSDLParachute.

00358                                {
00359   return m_useSDLParachute;
00360 }

bool Config::CheckVBO (  ) 

Definition at line 342 of file Config.cpp.

References m_useVBO.

Referenced by CheckExtensions().

00342                       {
00343   return m_useVBO;
00344 }

void Config::CloseConfig (  )  [static]

Definition at line 376 of file Config.cpp.

References Log::Message(), s_config, and Log::s_log.

Referenced by prepExit().

00376                          {
00377   if (s_config == NULL) {
00378     Log::s_log->Message("Warning: Close config on NULL configuration");
00379     return;
00380   }
00381 
00382   delete s_config;
00383   s_config = NULL;
00384 }

bool Config::DebugLogEnabled (  ) 

Definition at line 438 of file Config.cpp.

References m_debugLogMode.

00438                              {
00439   return m_debugLogMode;
00440 }

unsigned int Config::GetNumberALSources (  ) 

Definition at line 434 of file Config.cpp.

References m_numberALSources.

00434                                         {
00435   return m_numberALSources;
00436 }

string Config::GetStartingShipType (  ) 

Definition at line 442 of file Config.cpp.

References m_startingShipType.

00442                                    {
00443   return m_startingShipType;
00444 }

unsigned int Config::GetTicksBetweenBattles (  ) 

Definition at line 430 of file Config.cpp.

References m_ticksBetweenBattles.

00430                                             {
00431   return m_ticksBetweenBattles;
00432 }

int Config::GetWinHeight (  ) 

Definition at line 350 of file Config.cpp.

References m_winHeight.

Referenced by Battle::Battle(), IGameState::DisplayBackground(), IGameState::DisplaySplashScreen(), init(), StateSailing::Initialize(), main(), Map::Map(), and IGameState::TakeScreenshot().

00350                          {
00351   return m_winHeight;
00352 }

int Config::GetWinWidth (  ) 

Definition at line 346 of file Config.cpp.

References m_winWidth.

Referenced by Battle::Battle(), IGameState::DisplayBackground(), IGameState::DisplaySplashScreen(), init(), StateSailing::Initialize(), main(), Map::Map(), and IGameState::TakeScreenshot().

00346                         {
00347   return m_winWidth;
00348 }

void Config::LogConfig (  )  [private]

Definition at line 386 of file Config.cpp.

References m_compressTextures, m_debugLogMode, m_fullscreen, m_numberALSources, m_startingShipType, m_ticksBetweenBattles, m_useSDLParachute, m_useVBO, m_winHeight, m_winWidth, Log::Message(), and Log::s_log.

Referenced by Config().

00386                        {
00387   ostringstream outputString;
00388 
00389   outputString << "Configuration:" << endl;
00390   outputString << "Resolution: " << m_winWidth << " x " << m_winHeight << endl;
00391 
00392   outputString << "Fullscreen: ";
00393   if (m_fullscreen) outputString << "true";
00394   else outputString << "false";
00395   outputString << endl;
00396 
00397   outputString << "Use VBOs: ";
00398   if (m_useVBO) outputString << "true";
00399   else outputString << "false";
00400   outputString << endl;
00401 
00402   outputString << "Enable SDL Parachute: ";
00403   if (m_useSDLParachute) outputString << "true";
00404   else outputString << "false";
00405   outputString << endl;
00406 
00407   outputString << "Compress Textures: ";
00408   if (m_compressTextures) outputString << "true";
00409   else outputString << "false";
00410   outputString << endl;
00411 
00412   outputString << "TicksBetweenBattles: ";
00413   outputString << m_ticksBetweenBattles;
00414   outputString << endl;
00415 
00416   outputString << "NumberALSources: ";
00417   outputString << m_numberALSources;
00418   outputString << endl;
00419 
00420   outputString << "DebugLogMode: ";
00421   if (m_debugLogMode) outputString << "true";
00422   else outputString << "false";
00423   outputString << endl;
00424 
00425   outputString << "Starting Ship Type: \"" << m_startingShipType << "\"";
00426 
00427   Log::s_log->Message(outputString.str());
00428 }

bool Config::OpenConfig ( const std::string  filename  )  [static]

Definition at line 366 of file Config.cpp.

References Config(), Log::Message(), s_config, and Log::s_log.

Referenced by main().

00366                                                 {
00367   if (s_config != NULL) {
00368     Log::s_log->Message("Warning: Open config on non-NULL configuration");
00369     return false;
00370   }
00371 
00372   s_config = new Config(filename);
00373   return true;
00374 }


Member Data Documentation

bool Config::m_compressTextures [private]

Definition at line 72 of file Config.h.

Referenced by CheckCompressTextures(), Config(), and LogConfig().

bool Config::m_debugLogMode [private]

Definition at line 83 of file Config.h.

Referenced by Config(), DebugLogEnabled(), and LogConfig().

bool Config::m_fullscreen [private]

Definition at line 60 of file Config.h.

Referenced by CheckFullscreen(), Config(), and LogConfig().

unsigned int Config::m_numberALSources [private]

Definition at line 80 of file Config.h.

Referenced by Config(), GetNumberALSources(), and LogConfig().

std::string Config::m_startingShipType [private]

Definition at line 86 of file Config.h.

Referenced by Config(), GetStartingShipType(), and LogConfig().

unsigned int Config::m_ticksBetweenBattles [private]

Definition at line 76 of file Config.h.

Referenced by Config(), GetTicksBetweenBattles(), and LogConfig().

bool Config::m_useSDLParachute [private]

Definition at line 67 of file Config.h.

Referenced by CheckSDLParachute(), Config(), and LogConfig().

bool Config::m_useVBO [private]

Definition at line 63 of file Config.h.

Referenced by CheckExtensions(), CheckVBO(), Config(), and LogConfig().

int Config::m_winHeight [private]

Definition at line 57 of file Config.h.

Referenced by Config(), GetWinHeight(), and LogConfig().

int Config::m_winWidth [private]

Definition at line 56 of file Config.h.

Referenced by Config(), GetWinWidth(), and LogConfig().

Config * Config::s_config = NULL [static]

Definition at line 52 of file Config.h.

Referenced by Battle::Battle(), BuildTexture(), CheckExtensions(), CloseConfig(), IGameState::DisplayBackground(), IGameState::DisplaySplashScreen(), IGameState::IGameState(), init(), Battle::InitHUD(), StateSailing::Initialize(), IGameState::Loop(), main(), MainMenu::MainMenu(), Map::Map(), OpenConfig(), Player::Player(), Terrain::SetGlArrayPointers(), StateSailing::SetTicksToNextBattle(), StateBattle::StateBattle(), StateNewGame::SwitchTo(), StateCity::SwitchTo(), StateDone::SwitchTo(), StateBattle::SwitchTo(), Map::SwitchTo(), MainMenu::SwitchTo(), IGameState::TakeScreenshot(), Terrain::Terrain(), and Terrain::~Terrain().


The documentation for this class was generated from the following files:
Generated on Mon Jan 8 22:34:14 2007 for CrownandCutlass by  doxygen 1.4.7