From 664a4620ea931e62c2f772424d93cbedd4043654 Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Wed, 14 Jun 2006 23:36:24 +0000
Subject: [PATCH] Implemented Quaternion template specialization. Some other
 DAoC related fixes to XML.

---
 NIF_IO.cpp        | 18 ++++++++--------
 NIF_IO.h          |  9 ++++++--
 gen/obj_defines.h | 55 ++++++++++++++++++++++++++++++-----------------
 niflib.h          |  2 +-
 4 files changed, 52 insertions(+), 32 deletions(-)

diff --git a/NIF_IO.cpp b/NIF_IO.cpp
index 4b03566f..4b5d22d9 100644
--- a/NIF_IO.cpp
+++ b/NIF_IO.cpp
@@ -119,7 +119,7 @@ float ReadFloat( istream &in ){
 string ReadString( istream &in ) {
 	uint len = ReadUInt( in );
 	string out;
-	if ( len > 4000 )
+	if ( len > 10000 )
 	    throw runtime_error("String too long. Not a NIF file or unsupported format?");
 	if ( len > 0 ) {
 	    out.resize(len);
@@ -612,7 +612,12 @@ string HexString( const byte * src, uint len ) {
 
 }
 
- void StreamQuatKey( Key<Quaternion> & key, istream& file, KeyType type ) {
+//Byte
+ostream & operator<<( ostream & out, byte const & val ) {
+	return out << uint(val);
+}
+
+void NifStream( Key<Quaternion> & key, istream& file, uint version, KeyType type ) {
 	key.time = ReadFloat( file );
 
 	//If key type is not 1, 2, or 3, throw an exception
@@ -632,7 +637,7 @@ string HexString( const byte * src, uint len ) {
 }
 
 
-void StreamQuatKey( Key<Quaternion> const & key, ostream& file, KeyType type ) {
+void NifStream( Key<Quaternion> const & key, ostream& file, uint version,  KeyType type ) {
 	WriteFloat( key.time, file );
 
 	//If key type is not 1, 2, or 3, throw an exception
@@ -649,9 +654,4 @@ void StreamQuatKey( Key<Quaternion> const & key, ostream& file, KeyType type ) {
 		WriteFloat( key.bias, file);
 		WriteFloat( key.continuity, file);
 	}
-}
-
-//Byte
-ostream & operator<<( ostream & out, byte const & val ) {
-	return out << uint(val);
-}
+}
\ No newline at end of file
diff --git a/NIF_IO.h b/NIF_IO.h
index 673a37b5..bb3ae1ee 100644
--- a/NIF_IO.h
+++ b/NIF_IO.h
@@ -379,6 +379,11 @@ ostream & operator<<( ostream & out, HeaderString const & val );
 
 //--Templates--//
 
+void NifStream( Key<Quaternion> & key, istream& file, uint version, KeyType type );
+
+
+void NifStream( Key<Quaternion> const & key, ostream& file, uint version,  KeyType type );
+
 //Key<T>
 template <class T> 
 void NifStream( Key<T> & key, istream& file, uint version, KeyType type ) {
@@ -450,8 +455,8 @@ ostream & operator<<( ostream & out, Key<T> const & val ) {
 }
 
 //Key<Quaternion>
-void StreamQuatKey( Key<Quaternion> & key, istream& file, uint version, KeyType type );
-void StreamQuatKey( Key<Quaternion> const & key, ostream& file, uint version, KeyType type );
+//void StreamQuatKey( Key<Quaternion> & key, istream& file, uint version, KeyType type );
+//void StreamQuatKey( Key<Quaternion> const & key, ostream& file, uint version, KeyType type );
 
 //The HexString function creates a formatted hex display of the given data for use in printing
 //a debug string for information that is not understood
diff --git a/gen/obj_defines.h b/gen/obj_defines.h
index 0e077758..6340516b 100644
--- a/gen/obj_defines.h
+++ b/gen/obj_defines.h
@@ -8513,54 +8513,69 @@ return refs; \
 
 #define NI_PARTICLE_MESH_MODIFIER_MEMBERS \
 uint numParticleMeshes; \
-Ref<NiAVObject > particleMeshes; \
+vector<Ref<NiAVObject > > particleMeshes; \
 
 #define NI_PARTICLE_MESH_MODIFIER_INCLUDE "AParticleModifier.h" \
 
 #define NI_PARTICLE_MESH_MODIFIER_PARENT AParticleModifier \
 
 #define NI_PARTICLE_MESH_MODIFIER_CONSTRUCT \
- : numParticleMeshes((uint)0), particleMeshes(NULL) \
+ : numParticleMeshes((uint)0) \
 
 #define NI_PARTICLE_MESH_MODIFIER_READ \
 uint block_num; \
 AParticleModifier::Read( in, link_stack, version, user_version ); \
 NifStream( numParticleMeshes, in, version ); \
-NifStream( block_num, in, version ); \
-link_stack.push_back( block_num ); \
+particleMeshes.resize(numParticleMeshes); \
+for (uint i0 = 0; i0 < particleMeshes.size(); i0++) { \
+	NifStream( block_num, in, version ); \
+	link_stack.push_back( block_num ); \
+}; \
 
 #define NI_PARTICLE_MESH_MODIFIER_WRITE \
 AParticleModifier::Write( out, link_map, version, user_version ); \
 NifStream( numParticleMeshes, out, version ); \
-if ( particleMeshes != NULL ) \
-	NifStream( link_map[StaticCast<NiObject>(particleMeshes)], out, version ); \
-else \
-	NifStream( 0xffffffff, out, version ); \
+for (uint i0 = 0; i0 < particleMeshes.size(); i0++) { \
+	if ( particleMeshes[i0] != NULL ) \
+		NifStream( link_map[StaticCast<NiObject>(particleMeshes[i0])], out, version ); \
+	else \
+		NifStream( 0xffffffff, out, version ); \
+}; \
 
 #define NI_PARTICLE_MESH_MODIFIER_STRING \
 stringstream out; \
 out << AParticleModifier::asString(); \
 out << "Num Particle Meshes:  " << numParticleMeshes << endl; \
-out << "Particle Meshes:  " << particleMeshes << endl; \
+for (uint i0 = 0; i0 < particleMeshes.size(); i0++) { \
+	if ( !verbose && ( i0 > MAXARRAYDUMP ) ) { \
+		out << "<Data Truncated. Use verbose mode to see complete listing.>" << endl; \
+		break; \
+	}; \
+	out << "  Particle Meshes[" << i0 << "]:  " << particleMeshes[i0] << endl; \
+}; \
 return out.str(); \
 
 #define NI_PARTICLE_MESH_MODIFIER_FIXLINKS \
 AParticleModifier::FixLinks( objects, link_stack, version, user_version ); \
-if (link_stack.empty()) \
-	throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
-if (link_stack.front() != 0xffffffff) { \
-	particleMeshes = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
-	if ( particleMeshes == NULL ) \
-		throw runtime_error("Link could not be cast to required type during file read. This NIF file may be invalid or improperly understood."); \
-} else \
-	particleMeshes = NULL; \
-link_stack.pop_front(); \
+for (uint i0 = 0; i0 < particleMeshes.size(); i0++) { \
+	if (link_stack.empty()) \
+		throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
+	if (link_stack.front() != 0xffffffff) { \
+		particleMeshes[i0] = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
+		if ( particleMeshes[i0] == NULL ) \
+			throw runtime_error("Link could not be cast to required type during file read. This NIF file may be invalid or improperly understood."); \
+	} else \
+		particleMeshes[i0] = NULL; \
+	link_stack.pop_front(); \
+}; \
 
 #define NI_PARTICLE_MESH_MODIFIER_GETREFS \
 list<Ref<NiObject> > refs; \
 refs = AParticleModifier::GetRefs(); \
-if ( particleMeshes != NULL ) \
-	refs.push_back(StaticCast<NiObject>(particleMeshes)); \
+for (uint i0 = 0; i0 < particleMeshes.size(); i0++) { \
+	if ( particleMeshes[i0] != NULL ) \
+		refs.push_back(StaticCast<NiObject>(particleMeshes[i0])); \
+}; \
 return refs; \
 
 #define NI_PARTICLE_ROTATION_MEMBERS \
diff --git a/niflib.h b/niflib.h
index e5b25bbe..86c7a594 100644
--- a/niflib.h
+++ b/niflib.h
@@ -194,7 +194,7 @@ NIFLIB_API void WriteFileGroup( string const & file_name, NiObjectRef const & ro
  * \param right The root block of the second Nif tree to merge.
  * \param version The version of the nif format to use during the clone operation on the right-hand tree.  The default is the highest version availiable.
  */
-NIFLIB_API void MergeNifTrees( NiNodeRef target, NiAVObjectRef right, unsigned int version = 0xffffffff );
+//NIFLIB_API void MergeNifTrees( NiNodeRef target, NiAVObjectRef right, unsigned int version = 0xffffffff );
 
 
 //// Returns list of all blocks in the tree rooted by root block.
-- 
GitLab