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.
Seven
Posts: 1034 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Thu Apr 07, 2016 12:12 am
in the following code, I am sure that the file is valid but i always have an attribute count of 0
anyone see what I am doing wrong?
I use similar code to save the file and that is working fine.
Code: Select all
// create a null device, create the attributes and then load from disk
IrrlichtDevice* device = createDevice(EDT_NULL);
IXMLReader* reader = device->getFileSystem()->createXMLReader(getApplication()->getDirectory("GameDataDirectory") + filename);
if (!reader) { CS_LOG(CSL_DEBUG, "Warning! unable to load engine param file %s", filename.c_str()); return false; }
// create an attributes structure
IAttributes* attr = device->getFileSystem()->createEmptyAttributes();
if (attr)
{
attr->read(reader, false);
printf("number of attributes = %d\n",attr->getAttributeCount());
CuteAlien
Admin
Posts: 9734 Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:
Post
by CuteAlien » Thu Apr 07, 2016 9:03 am
I think you have to check first if you have an EXN_ELEMENT. Please take a look at example 25, it has a load() function which does those checks (thought it doesn't seem to load in all attribute at once). CSceneManager.cpp probably also has some code you can look at for an example in the loadScene or so.
Seven
Posts: 1034 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Sat Apr 09, 2016 12:23 am
thanks for the push!
for anyone else looking to do similar......
Code: Select all
bool CSEngine::saveToDisk(stringc filename)
{
// log this event
CS_LOG(CSL_DEBUG, "%s\n %s", "CSEngine::saveParamsToDisk()", getApplication()->getDirectory("GameDataDirectory") + filename.c_str());
// create a null device, setup the attributes and then save to disk
IrrlichtDevice* device = createDevice(EDT_NULL);
IXMLWriter* writer = device->getFileSystem()->createXMLWriter(getApplication()->getDirectory("GameDataDirectory") + filename);
if (!writer) { CS_LOG(CSL_DEBUG, "Warning! unable to create engine param file %s", filename.c_str()); return false; }
// write the xml header to the file
writer->writeXMLHeader();
writer->writeElement(L"ENGINE_PARAMS", true);
writer->writeLineBreak();
// create an attributes structure
IAttributes* attr = device->getFileSystem()->createEmptyAttributes();
if (attr)
{
// add the variables to the attributes structure
switch (m_Params.DriverType)
{
case EDT_DIRECT3D9: attr->addString("DRIVERTYPE", "EDT_DIRECT3D9"); break;
case EDT_OPENGL: attr->addString("DRIVERTYPE", "EDT_OPENGL"); break;
}
attr->addInt("ANTIALIAS", m_Params.AntiAlias);
attr->addInt("BITS", m_Params.Bits);
attr->addInt("DISPLAYADAPTER", m_Params.DisplayAdapter);
attr->addBool("DOUBLEBUFFER", m_Params.Doublebuffer);
attr->addBool("DRIVERMULTITHREADED", m_Params.DriverMultithreaded);
attr->addBool("FULLSCREEN", m_Params.Fullscreen);
attr->addBool("HANDLESRGB", m_Params.HandleSRGB);
attr->addBool("HIGHPRECISIONFPU", m_Params.HighPrecisionFPU);
attr->addBool("IGNOREINPUT", m_Params.IgnoreInput);
attr->addBool("STENCILBUFFER", m_Params.Stencilbuffer);
attr->addBool("STEREOBUFFER", m_Params.Stereobuffer);
attr->addBool("PORFORMANCETIMER", m_Params.UsePerformanceTimer);
attr->addBool("VSYNC", m_Params.Vsync);
attr->addDimension2d("WINDOWSIZE", m_Params.WindowSize);
attr->addBool("WITHALPHACHANNEL", m_Params.WithAlphaChannel);
attr->addInt("ZBUFFERBITS", m_Params.ZBufferBits);
// if thee are attributes, write them to the file
if (attr->getAttributeCount() != 0) attr->write(writer);
// close the file writing
writer->writeLineBreak();
writer->writeClosingTag(L"ENGINE_PARAMS");
// drop all of the pointers
attr->drop();
writer->drop();
device->drop();
// everything went fine
return true;
}
// something went wrong
return false;
}
bool CSEngine::loadFromDisk(stringc filename)
{
// log this event
CS_LOG(CSL_DEBUG, "%s\n %s", "CSEngine::loadFromDisk()", getApplication()->getDirectory("GameDataDirectory") + filename.c_str());
// create a null device, create the attributes and then load from disk
IrrlichtDevice* device = createDevice(EDT_NULL);
IXMLReader* reader = device->getFileSystem()->createXMLReader(getApplication()->getDirectory("GameDataDirectory") + filename);
if (!reader) { CS_LOG(CSL_DEBUG, "Warning! unable to load engine param file %s", filename.c_str()); return false; }
// create an attributes structure
IAttributes* attr = device->getFileSystem()->createEmptyAttributes();
while (reader->read())
switch (reader->getNodeType())
{
case EXN_ELEMENT:
attr->read(reader, false);
// add the variables to the attributes structure
stringc tempString = attr->getAttributeAsString("DRIVERTYPE");
if (tempString == "EDT_DIRECT3D9") m_Params.DriverType = EDT_DIRECT3D9;
if (tempString == "EDT_OPENGL") m_Params.DriverType = EDT_OPENGL;
m_Params.AntiAlias = attr->getAttributeAsInt("ANTIALIAS");
m_Params.Bits = attr->getAttributeAsBool("BITS");
m_Params.DisplayAdapter = attr->getAttributeAsBool("DISPLAYADAPTER");
m_Params.Doublebuffer = attr->getAttributeAsBool("DOUBLEBUFFER");
m_Params.DriverMultithreaded = attr->getAttributeAsBool("DRIVERMULTITHREADED");
m_Params.Fullscreen = attr->getAttributeAsBool("FULLSCREEN");
m_Params.HandleSRGB = attr->getAttributeAsBool("HANDLESRGB");
m_Params.HighPrecisionFPU = attr->getAttributeAsBool("HIGHPRECISIONFPU");
m_Params.IgnoreInput = attr->getAttributeAsBool("IGNOREINPUT");
m_Params.Stencilbuffer = attr->getAttributeAsBool("STENCILBUFFER");
m_Params.Stereobuffer = attr->getAttributeAsBool("STEREOBUFFER");
m_Params.UsePerformanceTimer = attr->getAttributeAsBool("PORFORMANCETIMER");
m_Params.Vsync = attr->getAttributeAsBool("VSYNC");
m_Params.WindowSize = attr->getAttributeAsDimension2d("WINDOWSIZE");
m_Params.WithAlphaChannel = attr->getAttributeAsBool("WITHALPHACHANNEL");
m_Params.ZBufferBits = attr->getAttributeAsInt("ZBUFFERBITS");
break;
}
// drop all of the pointers
attr->drop();
reader->drop();
device->drop();
// everything went fine
return true;
}