hello Tomiz if i understand your mess you want the configmanger file I hope this is the right file
Tomzi thank you for all your help
#include "ConfigManager.h"
CConfigManager::CConfigManager(void)
{
IntConfigReader();
}
CConfigManager::~CConfigManager(void)
{
}
//! Reads in the parameters used for the createDevice function.
void CConfigManager::readDeviceOptions()
{
TiXmlElement *pDevice = pConfig->FirstChild("Device")->ToElement();
if(pDevice==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Device tag", doc.ErrorCol());
}else{
setScreenResolution(pDevice);
setFullscreen(pDevice);
setBitsperPixel(pDevice);
setStencilbuffer(pDevice);
setVsync(pDevice);
setDriverType(pDevice);
setParticleEffects(pDevice);
DEBUGLOG<<"Reading of Device tag Done ..."<<endl;
}
}
// Set Screen resolution, use standard sizes ie 640x480, 800x600, 1024x768, 1200x1400 etc
void CConfigManager::setScreenResolution(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *ScreenResolution = pDeviceRoot->FirstChild("ScreenResolution")->ToElement();
if(ScreenResolution==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Screen Resolution tag ",doc.ErrorCol());
}else{
attr=ScreenResolution->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Height or Width atribute ",doc.ErrorCol());
}
while(attr)
{
DeviceConfig[attr->Name()]=attr->Value();
attr=attr->Next();
}
DEBUGLOG<<"Screen resolution: " + DeviceConfig["height"] + " x " + DeviceConfig["width"]<<endl;
}
}
//! Sets the FullScreen or Windowed mode parameter
void CConfigManager::setFullscreen(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *Fullscreen = pDeviceRoot->FirstChild("Fullscreen")->ToElement();
if(Fullscreen==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Full screen tag ",doc.ErrorCol());
}else{
attr=Fullscreen->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Full screen tag ",doc.ErrorCol());
}
DeviceConfig["FullscreenValue"]=attr->Value();
DEBUGLOG<<"Fullscreen: " + DeviceConfig["FullscreenValue"]<<endl;
}
}
//! Sets the Bits per pixel setting, 16 or 32.
void CConfigManager::setBitsperPixel(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *BitsperPixel = pDeviceRoot->FirstChild("BitsperPixel")->ToElement();
if(BitsperPixel==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Bits per Pixel tag ",doc.ErrorCol());
}else{
attr=BitsperPixel->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Bits per Pixel tag ",doc.ErrorCol());
}
DeviceConfig["BitsperPixelValue"]=attr->Value();
DEBUGLOG<<"Bits per pixel: " + DeviceConfig["BitsperPixelValue"]<<endl;
}
}
//! Sets shadows, true or false.
void CConfigManager::setStencilbuffer(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *Stencilbuffer = pDeviceRoot->FirstChild("Stencilbuffer")->ToElement();
if(Stencilbuffer==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Stencil buffer tag ",doc.ErrorCol());
}else{
attr=Stencilbuffer->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Stencil buffer tag ",doc.ErrorCol());
}
DeviceConfig["StencilbufferValue"]=attr->Value();
DEBUGLOG<<"Shadows: " + DeviceConfig["StencilbufferValue"]<<endl;
}
}
//! Sets the vertical retrace option, true or false
void CConfigManager::setVsync(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *Vsync = pDeviceRoot->FirstChild("Vsync")->ToElement();
if(Vsync==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("Vsync tag ",doc.ErrorCol());
}else{
attr=Vsync->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Vsync buffer tag ",doc.ErrorCol());
}
DeviceConfig["VsyncValue"]=attr->Value();
DEBUGLOG<<"Vsync: " + DeviceConfig["VsyncValue"]<<endl;
}
}
//! Sets the driver type
void CConfigManager::setDriverType(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *DriverType = pDeviceRoot->FirstChild("DriverType")->ToElement();
if(DriverType==NULL || doc.ErrorId()==4 || doc.ErrorId()==9){
ErrorMessage("Driver Type tag ",doc.ErrorCol());
}else{
attr=DriverType->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Driver Type tag ",doc.ErrorCol());
}
DeviceConfig["DriverType"]=attr->Value();
DEBUGLOG<<"Device type: " + DeviceConfig["DriverType"]<<endl;
}
}
//! Sets Particle effects, true or false
void CConfigManager::setParticleEffects(TiXmlElement *pDeviceRoot)
{
// use to clean the variable so we dont have do make new each time just re use
attr=NULL;
TiXmlElement *ParticleEffects = pDeviceRoot->FirstChild("ParticleEffects")->ToElement();
if(ParticleEffects==NULL || doc.ErrorId()==4 || doc.ErrorId()==9)
{
ErrorMessage("ParticleEffects tag ",doc.ErrorCol());
}else{
attr=ParticleEffects->FirstAttribute();
if(attr==NULL)
{
ErrorMessage("Particle Effects tag ",doc.ErrorCol());
}
DeviceConfig["ParticleEffectsValue"]=attr->Value();
DEBUGLOG<<"Particle effects: " + DeviceConfig["ParticleEffectsValue"]<<endl;
}
}
//______________________________________________________________________
// Loging Methods
//______________________________________________________________________
void CConfigManager::ErrorMessage(const char *pErrorTag,int ErrorCol)
{
LOG<<"\n Error: the Config.xml is malformed"<<endl;
LOG<< pErrorTag <<" tag not found or malformed at line "<<ErrorCol<<endl;
LOG<<"For more information see the Web Page"<<endl;
LOG<<"or the documentation"<<endl;
}
void CConfigManager::ErrorMessage(const char *pErrorTag){
LOG<<"\n Error: the Config.xml is malformed"<<endl;
LOG<< pErrorTag <<" tag not found or malformed at line "<<endl;
LOG<<"For more information see the Web Page"<<endl;
LOG<<"or the documentation"<<endl;
}
//______________________________________________________________________
//! Initialise config reader
void CConfigManager::IntConfigReader(){
if(!doc.LoadFile("Config.xml"))
{
LOG<<"\n Error while loading Config.xml"<<endl;
LOG<<"Config file malformed or is not there"<<endl;
LOG<<doc.ErrorDesc()<<" at line :"<<doc.ErrorRow()<<endl;
}else{
DEBUGLOG<<"Loading Config.xml Done"<<endl; ;
}
pConfig = doc.FirstChild("Config")->ToElement();
if(pConfig==NULL || doc.ErrorId()==4 || doc.ErrorId()==9){
ErrorMessage("Config Tag",doc.ErrorCol());
}else{
readDeviceOptions();
readSoundOptions();
}
}
//-----------------------------------------------------------------------------
// Public methods
// Get Methods
bool CConfigManager::getVsync()
{
return convertToBoolean(DeviceConfig["VsyncValue"]);
}
bool CConfigManager::getStencilbuffer()
{
return convertToBoolean(DeviceConfig["StencilbufferValue"]);
}
bool CConfigManager::getFullscreen()
{
return convertToBoolean(DeviceConfig["FullscreenValue"]);
}
irr::core::dimension2d<irr::s32> CConfigManager::getScreenResolution()
{
return irr::core::dimension2d<irr::s32>(convertToInt(DeviceConfig["height"]),
convertToInt(DeviceConfig["width"]));
}
bool CConfigManager::getParticleEffects()
{
return convertToBoolean(DeviceConfig["ParticleEffectsValue"]);
}
//! return valid driver types
irr::video::E_DRIVER_TYPE CConfigManager::getDriverType()
{
if(DeviceConfig["DriverType"]=="OpenGL")
return irr::video::EDT_OPENGL;
else if (DeviceConfig["DriverType"]=="DirectX8")
return irr::video::EDT_DIRECT3D8;
else if (DeviceConfig["DriverType"]=="DirectX9")
return irr::video::EDT_DIRECT3D9;
else if (DeviceConfig["DriverType"]=="Irrlicht Software")
return irr::video::EDT_SOFTWARE;
else if (DeviceConfig["DriverType"]=="Apfelbaum Software")
return irr::video::EDT_SOFTWARE2;
else if (DeviceConfig["DriverType"]=="Null")
return irr::video::EDT_NULL;
else{
LOG<<"Error"<< DeviceConfig["DriverType"]<<" is not valid"<<endl;
LOG<<"Using Irrlicht Softwate Driver "<<endl;
LOG<<endl;
return irr::video::EDT_SOFTWARE;
}
}
//! gets the value for bits per pixel
int CConfigManager::getBitsperPixel()
{
int BitsperPixelValue= convertToInt(DeviceConfig["BitsperPixelValue"]);
if(BitsperPixelValue==32)
return 32;
else if (BitsperPixelValue== 16)
return 16;
else{
LOG<<"Error the value of Bits per Pixel us not support by Irrlicht"<<endl;
LOG<<"Using 16 bits "<<endl;
LOG<<endl;
return 16;
}
}