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

Updated public interface in preparation for missing_link_stack support during read.

parent ddd52bf1
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,22 @@ 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.
*/
NIFLIB_API list<Ref<NiObject> > ProcessMissingLinkStack(
list<Ref<NiObject> > const & roots,
const list<NiObject *> & missing_link_stack);
/*!
* Reads the given input stream and returns a vector of object references
* \param in The input stream to read NIF data from.
* \param missing_link_stack A stack where to copy NULL refs from (in case of reading a nif from an incomplete nif tree)
* \param info Optionally, a NifInfo structure pointer can be passed in, and it will be filled with information from the header of the NIF file.
* \return All the NIF objects read from the stream.
*/
NIFLIB_API vector<Ref<NiObject> > ReadNifList( istream & in, const list<Ref<NiObject> > & missing_link_stack, NifInfo * info );
/*!
* Reads the given file by file name and returns a vector of object references
* \param file_name The name of the file to load, or the complete path if it is not in the working directory.
......
......@@ -119,6 +119,11 @@ vector<NiObjectRef> ReadNifList( string const & file_name, NifInfo * info ) {
}
vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) {
list<NiObjectRef> missing_link_stack;
return ReadNifList(in, missing_link_stack, info);
}
vector<NiObjectRef> ReadNifList( istream & in, const list<NiObjectRef> & missing_link_stack, NifInfo * info ) {
//Ensure that objects are registered
if ( g_objects_registered == false ) {
......@@ -397,6 +402,32 @@ vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) {
return obj_list;
}
NiObjectRef _ProcessMissingLinkStackHelper(NiObjectRef root, NiObject *obj) {
// search by name
NiNodeRef rootnode = DynamicCast<NiNode>(root);
NiNodeRef objnode = DynamicCast<NiNode>(obj);
if (rootnode != NULL && objnode != NULL) {
if (!(rootnode->GetName().empty()) && rootnode->GetName() == objnode->GetName()) {
return StaticCast<NiObject>(rootnode);
}
}
// nothing found
return NiObjectRef();
}
list<NiObjectRef> ProcessMissingLinkStack(
list<NiObjectRef> const & roots,
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) {
for (list<NiObjectRef>::const_iterator root = roots.begin(); root != roots.end(); ++root) {
result.push_back(_ProcessMissingLinkStackHelper(*root, *obj));
}
}
return result;
}
// Writes a valid Nif File given an ostream, a list to the root objects of a file tree
// (missing_link_stack stores a stack of links which are referred to but which
// are not inside the tree rooted by roots)
......
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