xml config file

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
paooolino
Posts: 50
Joined: Wed Dec 21, 2005 12:17 pm
Location: Brescia, Italy
Contact:

xml config file

Post 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?!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
paooolino
Posts: 50
Joined: Wed Dec 21, 2005 12:17 pm
Location: Brescia, Italy
Contact:

Post by paooolino »

mmh I will give it a try, thanks :wink:
ehenkes
Posts: 47
Joined: Sun Aug 03, 2008 2:52 pm
Location: Germany
Contact:

Post 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>
Last edited by ehenkes on Sun Sep 14, 2008 1:03 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
ehenkes
Posts: 47
Joined: Sun Aug 03, 2008 2:52 pm
Location: Germany
Contact:

Post by ehenkes »

So you can use the XML reader even without a device.
Yes, it definitely works before creating a device.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

ehenkes wrote:

Code: Select all

delete xml;
Should be xml->drop();.
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Post by torleif »

You can create & destroy a device or use this settings reader
ehenkes
Posts: 47
Joined: Sun Aug 03, 2008 2:52 pm
Location: Germany
Contact:

Post by ehenkes »

Should be xml->drop();
Sorry, there is no member function "drop()". :roll:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

ehenkes wrote:
Should be xml->drop();
Sorry, there is no member function "drop()". :roll:
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?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Which seems bass ackwards. Deliberate, or snafu?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
ehenkes
Posts: 47
Joined: Sun Aug 03, 2008 2:52 pm
Location: Germany
Contact:

Post by ehenkes »

I forget that Irrlicht supports both the IrrXMLReader and IXMLReader types.
Nice feature. :shock:

bass ackwards = ass backwards
snafu = situation normal all beyond repair
:)
Post Reply