diff --git a/include/niflib.h b/include/niflib.h index 114ff8279de570aad7715478e932bc6c58f541a7..db1eab657820005f02fc84f1c5ae0fc904007bfd 100644 --- a/include/niflib.h +++ b/include/niflib.h @@ -108,10 +108,10 @@ enum ExportOptions { NIFLIB_API unsigned int GetNifVersion( string const & file_name ); /*! - * Return the missing link stack with objects replaced from nif trees at specified roots. + * Return the missing link stack with objects replaced from nif trees at specified root. */ NIFLIB_API list<Ref<NiObject> > ResolveMissingLinkStack( - list<Ref<NiObject> > const & roots, + NiObject *root, const list<NiObject *> & missing_link_stack); /*! @@ -165,12 +165,12 @@ NIFLIB_API Ref<NiObject> ReadNifTree( istream & in, NifInfo * info = NULL ); /*! * Creates a new NIF file of the given file name by crawling through the data tree starting with the root objects given, and keeps track of links that cannot been written. * \param[in] out The output stream to write the NIF data to. - * \param[in] roots The root objects to start from when writing out the NIF file. All decedents of these blocks will be written to the file in tree-descending order. + * \param[in] root The root object to start from when writing out the NIF file. All decedents of this block will be written to the file in tree-descending order. * \param[in] missing_link_stack stack of links which are referred to but which are not inside the tree rooted by roots. * \param[in] info A NifInfo structure that contains information such as the version of the NIF file to create. * \sa ReadNifList, WriteNifTree */ -NIFLIB_API void WriteNifTree( ostream & out, list<Ref<NiObject> > const & roots, list<NiObject *> & missing_link_stack, const NifInfo & info = NifInfo() ); +NIFLIB_API void WriteNifTree( ostream & out, NiObject *root, list<NiObject *> & missing_link_stack, const NifInfo & info = NifInfo() ); /*! * Creates a new NIF file of the given file name by crawling through the data tree starting with the root object given. diff --git a/src/niflib.cpp b/src/niflib.cpp index 6d889bc130443ed76154da1c3189bb0436818cef..b9c233c0b0dfb7c5202714a217da6d013e11eee4 100644 --- a/src/niflib.cpp +++ b/src/niflib.cpp @@ -407,7 +407,7 @@ vector<NiObjectRef> ReadNifList( istream & in, list<NiObjectRef> & missing_link_ return obj_list; } -NiObjectRef _ResolveMissingLinkStackHelper(NiObjectRef root, NiObject *obj) { +NiObjectRef _ResolveMissingLinkStackHelper(NiObject *root, NiObject *obj) { // search by name NiNodeRef rootnode = DynamicCast<NiNode>(root); NiNodeRef objnode = DynamicCast<NiNode>(obj); @@ -428,20 +428,12 @@ NiObjectRef _ResolveMissingLinkStackHelper(NiObjectRef root, NiObject *obj) { } list<NiObjectRef> ResolveMissingLinkStack( - list<NiObjectRef> const & roots, + NiObject *root, const list<NiObject *> & missing_link_stack) { list<NiObjectRef> result; for (list<NiObject *>::const_iterator obj = missing_link_stack.begin(); obj != missing_link_stack.end(); ++obj) { - NiObjectRef resolved; - if (*obj != NULL) { - for (list<NiObjectRef>::const_iterator root = roots.begin(); root != roots.end(); ++root) { - resolved = _ResolveMissingLinkStackHelper(*root, *obj); - if (resolved != NULL) - break; - } - } - result.push_back(resolved); + result.push_back(_ResolveMissingLinkStackHelper(root, *obj)); } return result; } @@ -592,6 +584,12 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, list<NiObject out << hdrInfo(NULL); } +void WriteNifTree( ostream & out, NiObject *root, list<NiObject *> & missing_link_stack, const NifInfo & info) { + list<NiObjectRef> roots; + roots.push_back(root); + WriteNifTree( out, roots, missing_link_stack, info ); +} + void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo & info) { list<NiObject *> missing_link_stack; WriteNifTree( out, roots, missing_link_stack, info ); diff --git a/test/missing_link_stack_test.cpp b/test/missing_link_stack_test.cpp index 59abb87978607a7c2330da3ba4be2643e8b5e370..9d0b42e8b987ca5847af08fa35c9c20b54a73f09 100644 --- a/test/missing_link_stack_test.cpp +++ b/test/missing_link_stack_test.cpp @@ -43,9 +43,7 @@ BOOST_AUTO_TEST_CASE(missing_link_stack_simple_test) } // write list<NiObject *> missing_link_stack; - list<NiObjectRef> roots; - roots.push_back(StaticCast<NiObject>(shape)); - BOOST_CHECK_NO_THROW(WriteNifTree(ss, roots, missing_link_stack, NifInfo(VER_20_0_0_5))); + BOOST_CHECK_NO_THROW(WriteNifTree(ss, shape, missing_link_stack, NifInfo(VER_20_0_0_5))); bool has_root = false; bool has_bone = false; // check that root and bone are in the missing link stack @@ -63,9 +61,7 @@ BOOST_AUTO_TEST_CASE(missing_link_stack_simple_test) BOOST_CHECK_EQUAL(has_root, true); BOOST_CHECK_EQUAL(has_bone, true); // read it again - roots.clear(); - roots.push_back(StaticCast<NiObject>(root)); - list<NiObjectRef> resolved_link_stack = ResolveMissingLinkStack(roots, missing_link_stack); + list<NiObjectRef> resolved_link_stack = ResolveMissingLinkStack(root, missing_link_stack); ss.seekg(0); NifInfo info; NiObjectRef new_root;