Commit 516faec0 authored by hybrid's avatar hybrid

Add another saveScene overload which allows to pass in a user-created...

Add another saveScene overload which allows to pass in a user-created XMLWriter. Patch suggested by eversilver.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4284 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 23b8381c
......@@ -1524,64 +1524,96 @@ namespace scene
virtual ISceneManager* createNewSceneManager(bool cloneContent=false) = 0;
//! Saves the current scene into a file.
/** Scene nodes with the option isDebugObject set to true are not being saved.
The scene is usually written to an .irr file, an xml based format. .irr files can
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org).
To load .irr files again, see ISceneManager::loadScene().
/** Scene nodes with the option isDebugObject set to true are
not being saved. The scene is usually written to an .irr file,
an xml based format. .irr files can Be edited with the Irrlicht
Engine Editor, irrEdit (http://irredit.irrlicht3d.org). To
load .irr files again, see ISceneManager::loadScene().
\param filename Name of the file.
\param userDataSerializer If you want to save some user data for every scene node into the
file, implement the ISceneUserDataSerializer interface and provide it as parameter here.
Otherwise, simply specify 0 as this parameter.
\param node Node which is taken as the top node of the scene. This node and all of its
descendants are saved into the scene file. Pass 0 or the scene manager to save the full
scene (which is also the default).
\param userDataSerializer If you want to save some user data
for every scene node into the file, implement the
ISceneUserDataSerializer interface and provide it as parameter
here. Otherwise, simply specify 0 as this parameter.
\param node Node which is taken as the top node of the scene.
This node and all of its descendants are saved into the scene
file. Pass 0 or the scene manager to save the full scene (which
is also the default).
\return True if successful. */
virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0;
//! Saves the current scene into a file.
/** Scene nodes with the option isDebugObject set to true are not being saved.
The scene is usually written to an .irr file, an xml based format. .irr files can
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org).
To load .irr files again, see ISceneManager::loadScene().
\param file: File where the scene is saved into.
\param userDataSerializer: If you want to save some user data for every scene node into the
file, implement the ISceneUserDataSerializer interface and provide it as parameter here.
Otherwise, simply specify 0 as this parameter.
\param node Node which is taken as the top node of the scene. This node and all of its
descendants are saved into the scene file. Pass 0 or the scene manager to save the full
scene (which is also the default).
/** Scene nodes with the option isDebugObject set to true are
not being saved. The scene is usually written to an .irr file,
an xml based format. .irr files can Be edited with the Irrlicht
Engine Editor, irrEdit (http://irredit.irrlicht3d.org). To
load .irr files again, see ISceneManager::loadScene().
\param file File where the scene is saved into.
\param userDataSerializer If you want to save some user data
for every scene node into the file, implement the
ISceneUserDataSerializer interface and provide it as parameter
here. Otherwise, simply specify 0 as this parameter.
\param node Node which is taken as the top node of the scene.
This node and all of its descendants are saved into the scene
file. Pass 0 or the scene manager to save the full scene (which
is also the default).
\return True if successful. */
virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0;
//! Saves the current scene into a file.
/** Scene nodes with the option isDebugObject set to true are
not being saved. The scene is usually written to an .irr file,
an xml based format. .irr files can Be edited with the Irrlicht
Engine Editor, irrEdit (http://irredit.irrlicht3d.org). To
load .irr files again, see ISceneManager::loadScene().
\param writer XMLWriter with which the scene is saved.
\param currentPath Path which is used for relative file names.
Usually the directory of the file written into.
\param userDataSerializer If you want to save some user data
for every scene node into the file, implement the
ISceneUserDataSerializer interface and provide it as parameter
here. Otherwise, simply specify 0 as this parameter.
\param node Node which is taken as the top node of the scene.
This node and all of its descendants are saved into the scene
file. Pass 0 or the scene manager to save the full scene (which
is also the default).
\return True if successful. */
virtual bool saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0;
//! Loads a scene. Note that the current scene is not cleared before.
/** The scene is usually loaded from an .irr file, an xml based format, but other scene formats
can be added to the engine via ISceneManager::addExternalSceneLoader. .irr files can
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org) or
saved directly by the engine using ISceneManager::saveScene().
\param filename: Name of the file.
\param userDataSerializer: If you want to load user data
/** The scene is usually loaded from an .irr file, an xml based
format, but other scene formats can be added to the engine via
ISceneManager::addExternalSceneLoader. .irr files can Be edited
with the Irrlicht Engine Editor, irrEdit
(http://irredit.irrlicht3d.org) or saved directly by the engine
using ISceneManager::saveScene().
\param filename Name of the file to load from.
\param userDataSerializer If you want to load user data
possibily saved in that file for some scene nodes in the file,
implement the ISceneUserDataSerializer interface and provide it
as parameter here. Otherwise, simply specify 0 as this
parameter.
\param rootNode Node which is taken as the root node of the scene. Pass 0 to add the scene
directly to the scene manager (which is also the default).
\param rootNode Node which is taken as the root node of the
scene. Pass 0 to add the scene directly to the scene manager
(which is also the default).
\return True if successful. */
virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) = 0;
//! Loads a scene. Note that the current scene is not cleared before.
/** The scene is usually loaded from an .irr file, an xml based format, but other scene formats
can be added to the engine via ISceneManager::addExternalSceneLoader. .irr files can
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org) or
saved directly by the engine using ISceneManager::saveScene().
\param file: File where the scene is going to be saved into.
\param userDataSerializer: If you want to load user data
/** The scene is usually loaded from an .irr file, an xml based
format, but other scene formats can be added to the engine via
ISceneManager::addExternalSceneLoader. .irr files can Be edited
with the Irrlicht Engine Editor, irrEdit
(http://irredit.irrlicht3d.org) or saved directly by the engine
using ISceneManager::saveScene().
\param file File where the scene is loaded from.
\param userDataSerializer If you want to load user data
possibily saved in that file for some scene nodes in the file,
implement the ISceneUserDataSerializer interface and provide it
as parameter here. Otherwise, simply specify 0 as this
parameter.
\param rootNode Node which is taken as the root node of the scene. Pass 0 to add the scene
directly to the scene manager (which is also the default).
\param rootNode Node which is taken as the root node of the
scene. Pass 0 to add the scene directly to the scene manager
(which is also the default).
\return True if successful. */
virtual bool loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) = 0;
......
......@@ -2110,6 +2110,9 @@ bool CSceneManager::saveScene(const io::path& filename, ISceneUserDataSerializer
ret = saveScene(file, userDataSerializer, node);
file->drop();
}
else
os::Printer::log("Unable to open file", filename, ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
......@@ -2120,22 +2123,35 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us
{
if (!file)
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
bool result=false;
io::IXMLWriter* writer = FileSystem->createXMLWriter(file);
if (!writer)
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
os::Printer::log("Unable to create XML writer", file->getFileName(), ELL_ERROR);
}
else
{
result = saveScene(writer, FileSystem->getFileDir(FileSystem->getAbsolutePath(file->getFileName())), userDataSerializer, node);
writer->drop();
}
return result;
}
//! Saves the current scene into a file.
bool CSceneManager::saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node)
{
if (!writer)
return false;
if (!node)
node=this;
writer->writeXMLHeader();
writeSceneNode(writer, node, userDataSerializer, FileSystem->getFileDir(FileSystem->getAbsolutePath(file->getFileName())).c_str(), true);
writer->drop();
writeSceneNode(writer, node, userDataSerializer, currentPath.c_str(), true);
return true;
}
......@@ -2144,29 +2160,16 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us
//! Loads a scene.
bool CSceneManager::loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer, ISceneNode* rootNode)
{
bool ret = false;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (!file)
{
os::Printer::log("Unable to open scene file", filename.c_str(), ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
// try scene loaders in reverse order
s32 i = SceneLoaderList.size()-1;
for (; i >= 0 && !ret; --i)
if (SceneLoaderList[i]->isALoadableFileExtension(filename))
ret = SceneLoaderList[i]->loadScene(file, userDataSerializer, rootNode);
if (!ret)
os::Printer::log("Could not load scene file, perhaps the format is unsupported: ", filename.c_str(), ELL_ERROR);
const bool ret = loadScene(file, userDataSerializer, rootNode);
file->drop();
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
......@@ -2177,7 +2180,6 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use
if (!file)
{
os::Printer::log("Unable to open scene file", ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
......@@ -2192,10 +2194,10 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use
if (!ret)
os::Printer::log("Could not load scene file, perhaps the format is unsupported: ", file->getFileName().c_str(), ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
//! writes a scene node
void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer,
const fschar_t* currentPath, bool init)
......
......@@ -479,6 +479,9 @@ namespace scene
//! Saves the current scene into a file.
virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0);
//! Saves the current scene into a file.
virtual bool saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0);
//! Loads a scene. Note that the current scene is not cleared before.
virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment