Page 1 of 1
xml config file
Posted: Sat Sep 13, 2008 7:47 pm
by paooolino
Hello guys. My question is simple.
I just wanna load an xml config file through IXMLReader and read few useful parameters like:
- video driver
- screen resolution
- ...others...
I know I need this line of code
Code: Select all
IXMLReader* xml = device->getFileSystem()->createXMLReader("...");
but I can put it only *AFTER* the device creation. But I need it *BEFORE*, as I have to read xml parameters for creating a device. How can I proceed?!
Posted: Sat Sep 13, 2008 7:53 pm
by Acki
I don't use the IXMLReader/Writer (I'm using tinyXML), but you can create a device with the NULL driver (EDT_NULL) first to read the xml file, then drop the device and create a new one with the desired parameters...
Posted: Sat Sep 13, 2008 8:11 pm
by paooolino
mmh I will give it a try, thanks
Posted: Sat Sep 13, 2008 8:45 pm
by ehenkes
This works:
sourcecode:
Code: Select all
// ************ Setup irrlicht device ***************
s32 screenWidth, screenHeight;
SIrrlichtCreationParameters paramIrr;
MyEventReceiver receiver;
paramIrr.EventReceiver = &receiver;
IrrXMLReader* xml = createIrrXMLReader("settings.xml");
while(xml && xml->read())
{
switch(xml->getNodeType())
{
case EXN_ELEMENT:
{
if (!strcmp("settings", xml->getNodeName()))
{
screenWidth = xml->getAttributeValueAsInt("width");
screenHeight = xml->getAttributeValueAsInt("height");
paramIrr.Fullscreen = xml->getAttributeValueAsInt("fullscreen");
paramIrr.Vsync = xml->getAttributeValueAsInt("vsync");
//TODO: integrate more parameters in XML file
}
}
break;
}//switch
}//while
delete xml;
paramIrr.AntiAlias = false;
paramIrr.Bits = 32;
paramIrr.DriverType = EDT_DIRECT3D9;
paramIrr.Stencilbuffer = false;
paramIrr.WindowSize = dimension2d<s32>(screenWidth, screenHeight);
device = createDeviceEx(paramIrr);
// ************ Setup driver, smgr, guienv ***************
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
device->getCursorControl()->setVisible(true); // mouse cursor
XML file:
Code: Select all
<?xml version="1.0"?>
<config>
<!--This is a config file for the irrlicht engine.-->
<settings width = "1024" height = "768" antialias = "1" fullscreen = "0" vsync = "0">
</settings>
</config>
Posted: Sat Sep 13, 2008 10:47 pm
by hybrid
Yes, Irrlicht 1.4 should have the create XML Reader method exposed even on Windows. So you can use the XML reader even without a device.
Posted: Sun Sep 14, 2008 1:02 am
by ehenkes
So you can use the XML reader even without a device.
Yes, it definitely works before creating a device.
Posted: Mon Sep 15, 2008 4:25 am
by vitek
Posted: Mon Sep 15, 2008 4:33 am
by torleif
You can create & destroy a device or
use this settings reader
Posted: Mon Sep 15, 2008 9:57 pm
by ehenkes
Should be xml->drop();
Sorry, there is no member function "drop()".
Posted: Mon Sep 15, 2008 10:23 pm
by rogerborg
ehenkes wrote:Should be xml->drop();
Sorry, there is no member function "drop()".
Hmm. It seems like IrrXMLReader should be using IReferenceCounted as a base class (when used within Irrlicht). The documentation seems to assume that it will be. I wonder if there's a reason why it isn't?
Posted: Mon Sep 15, 2008 10:25 pm
by vitek
ehenkes wrote:Should be xml->drop();
Sorry, there is no member function "drop()". :roll:
Ah, yes. I forget that Irrlicht supports both the
IrrXMLReader and
IXMLReader types. Only the
IXMLReader inherits from
IReferenceCounted...
Travis
Posted: Tue Sep 16, 2008 7:00 am
by rogerborg
Which seems bass ackwards. Deliberate, or snafu?
Posted: Fri Sep 19, 2008 5:50 pm
by ehenkes
I forget that Irrlicht supports both the IrrXMLReader and IXMLReader types.
Nice feature.
bass ackwards = ass backwards
snafu = situation normal all beyond repair