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 ...@@ -1524,64 +1524,96 @@ namespace scene
virtual ISceneManager* createNewSceneManager(bool cloneContent=false) = 0; virtual ISceneManager* createNewSceneManager(bool cloneContent=false) = 0;
//! Saves the current scene into a file. //! Saves the current scene into a file.
/** Scene nodes with the option isDebugObject set to true are not being saved. /** Scene nodes with the option isDebugObject set to true are
The scene is usually written to an .irr file, an xml based format. .irr files can not being saved. The scene is usually written to an .irr file,
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org). an xml based format. .irr files can Be edited with the Irrlicht
To load .irr files again, see ISceneManager::loadScene(). Engine Editor, irrEdit (http://irredit.irrlicht3d.org). To
load .irr files again, see ISceneManager::loadScene().
\param filename Name of the file. \param filename Name of the file.
\param userDataSerializer If you want to save some user data for every scene node into the \param userDataSerializer If you want to save some user data
file, implement the ISceneUserDataSerializer interface and provide it as parameter here. for every scene node into the file, implement the
Otherwise, simply specify 0 as this parameter. ISceneUserDataSerializer interface and provide it as parameter
\param node Node which is taken as the top node of the scene. This node and all of its here. Otherwise, simply specify 0 as this parameter.
descendants are saved into the scene file. Pass 0 or the scene manager to save the full \param node Node which is taken as the top node of the scene.
scene (which is also the default). 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. */ \return True if successful. */
virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0; virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0;
//! Saves the current scene into a file. //! Saves the current scene into a file.
/** Scene nodes with the option isDebugObject set to true are not being saved. /** Scene nodes with the option isDebugObject set to true are
The scene is usually written to an .irr file, an xml based format. .irr files can not being saved. The scene is usually written to an .irr file,
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org). an xml based format. .irr files can Be edited with the Irrlicht
To load .irr files again, see ISceneManager::loadScene(). Engine Editor, irrEdit (http://irredit.irrlicht3d.org). To
\param file: File where the scene is saved into. load .irr files again, see ISceneManager::loadScene().
\param userDataSerializer: If you want to save some user data for every scene node into the \param file File where the scene is saved into.
file, implement the ISceneUserDataSerializer interface and provide it as parameter here. \param userDataSerializer If you want to save some user data
Otherwise, simply specify 0 as this parameter. for every scene node into the file, implement the
\param node Node which is taken as the top node of the scene. This node and all of its ISceneUserDataSerializer interface and provide it as parameter
descendants are saved into the scene file. Pass 0 or the scene manager to save the full here. Otherwise, simply specify 0 as this parameter.
scene (which is also the default). \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. */ \return True if successful. */
virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0; 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. //! 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 /** The scene is usually loaded from an .irr file, an xml based
can be added to the engine via ISceneManager::addExternalSceneLoader. .irr files can format, but other scene formats can be added to the engine via
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org) or ISceneManager::addExternalSceneLoader. .irr files can Be edited
saved directly by the engine using ISceneManager::saveScene(). with the Irrlicht Engine Editor, irrEdit
\param filename: Name of the file. (http://irredit.irrlicht3d.org) or saved directly by the engine
\param userDataSerializer: If you want to load user data 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, possibily saved in that file for some scene nodes in the file,
implement the ISceneUserDataSerializer interface and provide it implement the ISceneUserDataSerializer interface and provide it
as parameter here. Otherwise, simply specify 0 as this as parameter here. Otherwise, simply specify 0 as this
parameter. parameter.
\param rootNode Node which is taken as the root node of the scene. Pass 0 to add the scene \param rootNode Node which is taken as the root node of the
directly to the scene manager (which is also the default). scene. Pass 0 to add the scene directly to the scene manager
(which is also the default).
\return True if successful. */ \return True if successful. */
virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) = 0; 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. //! 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 /** The scene is usually loaded from an .irr file, an xml based
can be added to the engine via ISceneManager::addExternalSceneLoader. .irr files can format, but other scene formats can be added to the engine via
Be edited with the Irrlicht Engine Editor, irrEdit (http://irredit.irrlicht3d.org) or ISceneManager::addExternalSceneLoader. .irr files can Be edited
saved directly by the engine using ISceneManager::saveScene(). with the Irrlicht Engine Editor, irrEdit
\param file: File where the scene is going to be saved into. (http://irredit.irrlicht3d.org) or saved directly by the engine
\param userDataSerializer: If you want to load user data 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, possibily saved in that file for some scene nodes in the file,
implement the ISceneUserDataSerializer interface and provide it implement the ISceneUserDataSerializer interface and provide it
as parameter here. Otherwise, simply specify 0 as this as parameter here. Otherwise, simply specify 0 as this
parameter. parameter.
\param rootNode Node which is taken as the root node of the scene. Pass 0 to add the scene \param rootNode Node which is taken as the root node of the
directly to the scene manager (which is also the default). scene. Pass 0 to add the scene directly to the scene manager
(which is also the default).
\return True if successful. */ \return True if successful. */
virtual bool loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) = 0; 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 ...@@ -2110,6 +2110,9 @@ bool CSceneManager::saveScene(const io::path& filename, ISceneUserDataSerializer
ret = saveScene(file, userDataSerializer, node); ret = saveScene(file, userDataSerializer, node);
file->drop(); file->drop();
} }
else
os::Printer::log("Unable to open file", filename, ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret; return ret;
} }
...@@ -2120,22 +2123,35 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us ...@@ -2120,22 +2123,35 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us
{ {
if (!file) if (!file)
{ {
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false; return false;
} }
bool result=false;
io::IXMLWriter* writer = FileSystem->createXMLWriter(file); io::IXMLWriter* writer = FileSystem->createXMLWriter(file);
if (!writer) if (!writer)
{ {
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; os::Printer::log("Unable to create XML writer", file->getFileName(), ELL_ERROR);
return false; }
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) if (!node)
node=this; node=this;
writer->writeXMLHeader(); writer->writeXMLHeader();
writeSceneNode(writer, node, userDataSerializer, FileSystem->getFileDir(FileSystem->getAbsolutePath(file->getFileName())).c_str(), true); writeSceneNode(writer, node, userDataSerializer, currentPath.c_str(), true);
writer->drop();
return true; return true;
} }
...@@ -2144,29 +2160,16 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us ...@@ -2144,29 +2160,16 @@ bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* us
//! Loads a scene. //! Loads a scene.
bool CSceneManager::loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer, ISceneNode* rootNode) bool CSceneManager::loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer, ISceneNode* rootNode)
{ {
bool ret = false;
io::IReadFile* file = FileSystem->createAndOpenFile(filename); io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (!file) if (!file)
{ {
os::Printer::log("Unable to open scene file", filename.c_str(), ELL_ERROR); os::Printer::log("Unable to open scene file", filename.c_str(), ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false; return false;
} }
// try scene loaders in reverse order const bool ret = loadScene(file, userDataSerializer, rootNode);
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);
file->drop(); file->drop();
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret; return ret;
} }
...@@ -2177,7 +2180,6 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use ...@@ -2177,7 +2180,6 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use
if (!file) if (!file)
{ {
os::Printer::log("Unable to open scene file", ELL_ERROR); os::Printer::log("Unable to open scene file", ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false; return false;
} }
...@@ -2192,10 +2194,10 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use ...@@ -2192,10 +2194,10 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use
if (!ret) if (!ret)
os::Printer::log("Could not load scene file, perhaps the format is unsupported: ", file->getFileName().c_str(), ELL_ERROR); 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; return ret;
} }
//! writes a scene node //! writes a scene node
void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer, void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer,
const fschar_t* currentPath, bool init) const fschar_t* currentPath, bool init)
......
...@@ -479,6 +479,9 @@ namespace scene ...@@ -479,6 +479,9 @@ namespace scene
//! Saves the current scene into a file. //! Saves the current scene into a file.
virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0); 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. //! 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); 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