i want to make a settings.xml that will keep the info about screen resolution, v-sync, antialiasing, full screen options.
so my code is:
core::stringw AntiA,FullScr,VSync;
core::stringc Width, Height;
....
io::IXMLReader* xml2 = device->getFileSystem()->createXMLReader(
"settings.xml");
while(xml2 && xml2->read())
{
switch(xml2->getNodeType())
{
case io::EXN_TEXT:
Width = xml2->getAttributeValue(L"Width");
Height = xml2->getAttributeValue(L"Height");
FullScr = xml2->getAttributeValue(L"FullScreen");
AntiA = xml2->getAttributeValue(L"AntiAlias");
VSync = xml2->getAttributeValue(L"VSync");
break;
}
}
if (xml2)
xml2->drop();
....
param.WindowSize.Width = Width.c_str();
param.WindowSize.Height = Height.c_str();
param.AntiAlias = AntiA.c_str();
param.Fullscreen = FullScr.c_str();
param.Vsync = VSync.c_str();
and the xml file:
<settings>
Width="800"
Height="600"
AntiAlias="true"
FullScreen="false"
VSync="false"
</settings>
but still gives some errors and doesn't read the xml data
also i want to make an xml writer to write new values in settings.xml when new screen resolution is set from the options menu...and the new setting to be loaded next time the program is open.
any suggestions could be usefull
10x
Help needed with XML reader/writer
I don't know much about Irrlicht's xml reader/writer (I'm using tinyXML), but this is very wrong:the parameters are not alpha numeric values, so you can't assign strings to them !!!
param.WindowSize.Width and .Height are integers and the others are boolean !!!
look at the api, there should be functions for reading/writing integer, float and boolean values, too...
Code: Select all
param.WindowSize.Width = Width.c_str();
param.WindowSize.Height = Height.c_str();
param.AntiAlias = AntiA.c_str();
param.Fullscreen = FullScr.c_str();
param.Vsync = VSync.c_str();
param.WindowSize.Width and .Height are integers and the others are boolean !!!
look at the api, there should be functions for reading/writing integer, float and boolean values, too...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
The following works:
C++ Source
XML file:
Hence, with
<settings
Width="800"
Height="600"
AntiAlias="true"
FullScreen="false"
VSync="false">
</settings>
try
With "getAttributeValueAsInt" you can directly use in this case. I don't see the need for strings.
C++ Source
Code: Select all
CCharacter::CCharacter(ISceneManager* smgr, const char* filename)
{
// read XML file ////////////////////////
IrrXMLReader* xml = createIrrXMLReader(filename);
// strings for storing the data we want to get out of the file
std::string modelFile;
// parse the file until end reached
while(xml && xml->read())
{
switch(xml->getNodeType())
{
case EXN_ELEMENT:
{
// Get data from file
if (!strcmp("startUpModel", xml->getNodeName()))
modelFile = xml->getAttributeValue("file");
if (!strcmp("messageText", xml->getNodeName()))
caption = xml->getAttributeValue("caption");
if (!strcmp("Health", xml->getNodeName()))
healthPoints = f32(xml->getAttributeValueAsInt("points"));
if (!strcmp("Armor", xml->getNodeName()))
{
armorType = xml->getAttributeValueAsInt("type");
armorPoints = xml->getAttributeValueAsInt("points");
}
if (!strcmp("Attack", xml->getNodeName()))
{
attackType = xml->getAttributeValueAsInt("type");
attackPower = xml->getAttributeValueAsInt("power");
attackRange = xml->getAttributeValueAsInt("range");
attackArea = xml->getAttributeValueAsInt("area");
}
if (!strcmp("Move", xml->getNodeName()))
{
moveType = xml->getAttributeValueAsInt("type");
moveValue = xml->getAttributeValueAsInt("value");
}
if (!strcmp("Scale", xml->getNodeName()))
{
scale.X = xml->getAttributeValueAsFloat("x");
scale.Y = xml->getAttributeValueAsFloat("y");
scale.Z = xml->getAttributeValueAsFloat("z");
}
if (!strcmp("startPos", xml->getNodeName()))
{
startPos.X = xml->getAttributeValueAsFloat("x");
startPos.Y = xml->getAttributeValueAsFloat("y");
startPos.Z = xml->getAttributeValueAsFloat("z");
}
}
break;
}
}
delete xml;
Code: Select all
<?xml version="1.0"?>
<config>
<!--This is a config file for the Irrlicht Engine Mesh Viewer.-->
<startUpModel file="../media/Robot.x"></startUpModel>
<messageText caption="Robot 1.0"></messageText>
<Scale x="0.5" y="0.5" z="0.5"></Scale>
<startPos x="400" y="50" z="-250"></startPos>
<Health points="100"></Health>
<Armor type="1" points="920"></Armor>
<Attack power="1020" type="1" range="4" area="1"></Attack>
<Move type="1" value="1"></Move>
</config>
<settings
Width="800"
Height="600"
AntiAlias="true"
FullScreen="false"
VSync="false">
</settings>
try
Code: Select all
if (!strcmp("settings", xml->getNodeName()))
{
screenWidth = xml->getAttributeValueAsInt("Width");
screenHeight = xml->getAttributeValueAsInt("Height");
//...
}
Code: Select all
int screenWidth, screenHeight
Last edited by ehenkes on Sat Aug 23, 2008 2:16 pm, edited 1 time in total.
reply
10x Acki and ehenkes ... really helpfull... i was tired that night and wrote the code all wrong =))
10x again
10x again
reply
hey ehenkes, it worked like a charm with the method you explained nice and clean
now i need to figure ou how to generate settings.xml each time the user changes the screen resolution from options menu
10x again
now i need to figure ou how to generate settings.xml each time the user changes the screen resolution from options menu
10x again
reply
are they builtin irrlicht ??? or they are aditional ?
i think irrlicht has it's own xml writer
i think irrlicht has it's own xml writer