XML Level loading problems

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
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

XML Level loading problems

Post by JPulham »

I have an XML level like this:

Code: Select all

<level>
    <name>Desert Canyon</name>
    <desc>../models/level01.bmp</desc>
    <skymap>
        <image>../skys/reddesert_top.bmp</image>
        <image>../skys/reddesert_bottom.bmp</image>
        <image>../skys/reddesert_left.bmp</image>
        <image>../skys/reddesert_right.bmp</image>
        <image>../skys/reddesert_front.bmp</image>
        <image>../skys/reddesert_back.bmp</image>
    </skymap>
    <mesh file="../models/level01.3.lmts" type="lmts"></mesh>
</level>
and the reader looks like this

Code: Select all

//setup game data
stringc levelpath;
levelpath = "data\\levels\\";
				    levelpath.append(lstLevel->getListItem(lstLevel->getSelected()));
				    
IXMLReader* xml = device->getFileSystem()->createXMLReader(levelpath.c_str());
while(xml && xml->read())
{
switch(xml->getNodeType())
{
case EXN_TEXT:
break;
case EXN_ELEMENT:
if(stringw("mesh") == xml->getNodeName())
{
//load mesh
stringc meshpath;
meshpath = xml->getAttributeValue(L"file");
IAnimatedMesh* mesh = smgr->getMesh(meshpath.c_str());
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
}
//setup Newton Mesh data
NewtonCollision* LvlCollision;
LvlCollision = NewtonCreateTreeCollision(nWorld, NULL);
NewtonTreeCollisionBeginBuild(LvlCollision);
//read in data from the irrlicht mesh data
//finallise mesh
NewtonTreeCollisionEndBuild(LvlCollision, 1);
//build newton body
NewtonBody* LevelBody = NewtonCreateBody(nWorld, LvlCollision);
//release mesh
NewtonReleaseCollision(nWorld, LvlCollision);
}
if(stringw("skymap") == xml->getNodeName())
{
//load sky
stringc imgTop;
stringc imgBottom;
stringc imgLeft;
stringc imgRight;
stringc imgFront;
stringc imgBack;
for(int i = 0;i < 6;i++)
{
xml->read();
if(stringw("image") == xml->getNodeName())
{
xml->getNodeData();
}
}
SkyBox = smgr->addSkyBoxSceneNode(
driver->getTexture(imgTop.c_str()),
driver->getTexture(imgBottom.c_str()),
driver->getTexture(imgLeft.c_str()),
driver->getTexture(imgRight.c_str()),
driver->getTexture(imgFront.c_str()),
driver->getTexture(imgBack.c_str()));
}
break;
}
}
// delete the parser after 
if(xml)xml->drop();
When I run the game I get a blank screen. What went wrong?
pushpork
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

<image>../skys/reddesert_top.bmp</image>
XML sees this as 3 separate areas, an element, followed by text, followed by an element end. Your case handler for EXN_TEXT does nothing, so it never gets the skybox path. You could do 1 of 2 things, have the elements keep track of which EXN_TEXT the next skybox is, or the easier way would be to do your XML like this:

<image name="top" path="../skys/reddesert_top.bmp">

Then check which name you got from image, and set the path to load the texture:

Code: Select all

case EXN_ELEMENT:
    if (xml->getNodeName() == L"image")
    {
        name = xml->getAttributeValue(L"name");
        if (name == L"top") imgTop = xml->getAttributeValue(L"path");
    }
    break;
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Do it the way i did it...right your own reader....its the easiest way....cause i couldn't get the irrxml parser to work either....
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Killingsworth
Posts: 11
Joined: Mon Dec 05, 2005 11:21 pm
Location: Griffin, Georgia

Post by Killingsworth »

There's nothing wrong with IrrXML. I like it. Follow JPulham's suggestions and you should be fine. He's right, it's not reading the path. So eather make the path an attribute (which is what I'd do) or make it read the text.
You wouldn't hit a kid with contacts would you?!
Post Reply