Skip to content
Snippets Groups Projects
Commit f1b53eab authored by Amorilia's avatar Amorilia
Browse files

New WriteNifTree function which can take a missing_link_stack argument.

parent 4c6d9e90
No related branches found
No related tags found
No related merge requests found
......@@ -110,7 +110,7 @@ public:
/*! NIFLIB_HIDDEN function. For internal use only. */
NIFLIB_HIDDEN virtual void Read( istream& in, list<unsigned int> & link_stack, const NifInfo & info ) = 0;
/*! NIFLIB_HIDDEN function. For internal use only. */
NIFLIB_HIDDEN virtual void Write( ostream& out, const map< Ref<NiObject>, unsigned int> & link_map, const NifInfo & info ) const = 0;
NIFLIB_HIDDEN virtual void Write( ostream& out, const map< Ref<NiObject>, unsigned int> & link_map, list<NiObject *> & missing_link_stack, const NifInfo & info ) const = 0;
/*! NIFLIB_HIDDEN function. For internal use only. */
NIFLIB_HIDDEN virtual void FixLinks( const map<unsigned int, Ref<NiObject> > & objects, list<unsigned int> & link_stack, const NifInfo & info ) = 0;
/*! NIFLIB_HIDDEN function. For internal use only. */
......
......@@ -398,7 +398,9 @@ vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) {
}
// Writes a valid Nif File given an ostream, a list to the root objects of a file tree
void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo & info ) {
// (missing_link_stack stores a stack of links which are referred to but which
// are not inside the tree rooted by roots)
void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, list<NiObject *> & missing_link_stack, const NifInfo & info) {
//Enumerate all objects in tree
map<Type*,unsigned int> type_map;
......@@ -463,7 +465,7 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo
header.blockSize.resize( objects.size() );
for ( unsigned int i = 0; i < objects.size(); ++i ) {
ostr.reset();
objects[i]->Write( ostr, link_map, info );
objects[i]->Write( ostr, link_map, missing_link_stack, info );
header.blockSize[i] = ostr.tellp();
}
header.numStrings = header.strings.size();
......@@ -505,7 +507,7 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo
WriteUInt( 0, out );
}
objects[i]->Write( out, link_map, info );
objects[i]->Write( out, link_map, missing_link_stack, info );
}
//--Write Footer--//
......@@ -534,13 +536,18 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo
footer.numRoots = roots.size();
footer.roots.insert(footer.roots.end(), roots.begin(), roots.end());
}
footer.Write( out, link_map, info );
footer.Write( out, link_map, missing_link_stack, info );
}
// clear the header pointer in the stream. Should be in try/catch block
out << hdrInfo(NULL);
}
void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo & info) {
list<NiObject *> missing_link_stack;
WriteNifTree( out, roots, missing_link_stack, info );
}
// Writes a valid Nif File given a file name, a pointer to the root object of a file tree
void WriteNifTree( string const & file_name, NiObject * root, const NifInfo & info ) {
//Open output file
......
......@@ -108,7 +108,8 @@ NiObjectRef NiObject::Clone( unsigned int version, unsigned int user_version ) {
//Write this object's data to the stream
NifInfo info( version, user_version );
this->Write( tmp, link_map, info );
list<NiObject *> missing_link_stack;
this->Write( tmp, link_map, missing_link_stack, info );
//Dummy stack
list<unsigned int> link_stack;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment