From ec3bc2eedf81f1835edd65f4cbea657069a15796 Mon Sep 17 00:00:00 2001 From: Amorilia <amorilia@users.sourceforge.net> Date: Thu, 27 Apr 2006 20:47:33 +0000 Subject: [PATCH] XML update; niflib IO update to improve compilation with generated code. --- NIF_IO.cpp | 31 ++++++++++++++++++++++++++++++- NIF_IO.h | 27 ++++++++++++--------------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/NIF_IO.cpp b/NIF_IO.cpp index 31bae547..09ec965b 100644 --- a/NIF_IO.cpp +++ b/NIF_IO.cpp @@ -123,6 +123,13 @@ ostream & operator<<(ostream & lh, usVector3 const & rh) { /** * Read utility functions */ +int ReadInt( istream& in ){ + + int tmp; + in.read( (char*)&tmp, 4 ); + return tmp; +} + uint ReadUInt( istream& in ){ uint tmp; @@ -209,6 +216,11 @@ bool ReadBool( istream &in, unsigned int version ) { /** * Write utility functions. */ +void WriteInt( int val, ostream& out ){ + + out.write( (char*)&val, 4 ); +} + void WriteUInt( uint val, ostream& out ){ out.write( (char*)&val, 4 ); @@ -335,10 +347,12 @@ ostream & operator<<(ostream & lh, Bin const & rh) { //--Overloaded versions of Read/Write functions ReadData/WriteData +void NifStream( int & val, istream& in, uint version ) { val = ReadInt( in ); }; void NifStream( uint & val, istream& in, uint version ) { val = ReadUInt( in ); }; void NifStream( ushort & val, istream& in, uint version ) { val = ReadUShort( in ); }; void NifStream( short & val, istream& in, uint version ) { val = ReadShort( in ); }; void NifStream( byte & val, istream& in, uint version ) { val = ReadByte( in ); }; +void NifStream( bool & val, istream& in, uint version ) { val = ReadBool( in, version ); }; void NifStream( float & val, istream& in, uint version ) { val = ReadFloat( in ); }; void NifStream( string & val, istream& in, uint version ) { val = ReadString( in ); }; void NifStream( KeyType & val, istream& in, uint version ) { val = KeyType(ReadUInt( in )); }; @@ -412,12 +426,24 @@ void NifStream( TexDesc & val, istream& in, uint version ) { } } +void NifStream( IBlock * val, istream& in, uint version ) { + int n; + in.read( (char*)&n, 4 ); + val = 0; // TODO: do something with that n, something like this: + //if ( n == -1 ) + // val = 0; + //else + // val = blk_ref(n); + // BUT: block n may not have been processed yet, so we can't return a pointer... ? they will have to be + // resolved when calling FixLinks()? +}; - +void NifStream( int const & val, ostream& out, uint version ) { WriteInt( val, out ); } void NifStream( uint const & val, ostream& out, uint version ) { WriteUInt( val, out ); } void NifStream( ushort const & val, ostream& out, uint version ) { WriteUShort( val, out ); } void NifStream( short const & val, ostream& out, uint version ) { WriteShort( val, out ); } void NifStream( byte const & val, ostream& out, uint version ) { WriteByte( val, out ); } +void NifStream( bool const & val, ostream& out, uint version ) { WriteBool( val, out, version ); } void NifStream( float const & val, ostream& out, uint version ) { WriteFloat( val, out ); } void NifStream( string const & val, ostream& out, uint version ) { WriteString( val, out ); } void NifStream( KeyType const & val, ostream& out, uint version ) { WriteUInt( val, out ); } @@ -484,6 +510,9 @@ void NifStream( TexDesc const & val, ostream& out, uint version ) { } } }; +void NifStream( IBlock const * const val, ostream& out, uint version ) { + NifStream( val->GetBlockNum(), out, version ); +}; string HexString( const byte * src, uint len ) { stringstream out; diff --git a/NIF_IO.h b/NIF_IO.h index 93cf3a8f..141913f3 100644 --- a/NIF_IO.h +++ b/NIF_IO.h @@ -155,6 +155,7 @@ ostream & operator<<(ostream & lh, usVector3 const & rh); /** * Read utility functions */ +int ReadInt( istream& in ); uint ReadUInt( istream& in ); ushort ReadUShort( istream& in ); short ReadShort( istream& in ); @@ -168,10 +169,12 @@ void ReadFVector3( fVector3& fvec, istream& in ); void ReadFVector4( fVector4& fvec, istream& in ); //Read +void NifStream( int & val, istream& in, uint version = 0 ); void NifStream( uint & val, istream& in, uint version = 0 ); void NifStream( ushort & val, istream& in, uint version = 0 ); void NifStream( short & val, istream& in, uint version = 0 ); void NifStream( byte & val, istream& in, uint version = 0 ); +void NifStream( bool & val, istream& in, uint version ); // version is significant void NifStream( float & val, istream& in, uint version = 0 ); void NifStream( string & val, istream& in, uint version = 0 ); void NifStream( Vector3 & val, istream& in, uint version = 0 ); @@ -181,6 +184,7 @@ void NifStream( Color4 & val, istream& in, uint version = 0 ); void NifStream( Triangle & val, istream& in, uint version = 0 ); void NifStream( TexDesc & val, istream& in, uint version ); // version is significant void NifStream( LODRange & val, istream& in, uint version = 0 ); +void NifStream( IBlock * val, istream& in, uint version = 0 ); template <class T> void NifStream( Key<T> & key, istream& file, KeyType type ) { @@ -212,10 +216,10 @@ void NifStream( Key<T> & key, istream& file, KeyType type ) { void StreamQuatKey( Key<Quaternion> & key, istream& file, KeyType type ); template <class T> -void NifStream( vector<T> & val, istream& file ) { +void NifStream( vector<T> & val, istream& file, uint version = 0 ) { typename vector<T>::iterator it; for ( it = val.begin(); it != val.end(); ++it ) { - NifStream( *it, file ); + NifStream( *it, file, version ); } } @@ -223,35 +227,27 @@ void NifStream( vector<T> & val, istream& file ) { /** * Write utility functions. */ +void WriteInt( int val, ostream& out ); void WriteUInt( uint val, ostream& out ); - void WriteUShort( ushort val, ostream& out ); - void WriteShort( short val, ostream& out ); - void WriteByte( byte val, ostream& out ); - void WriteUSVector3( usVector3 const & fvec, ostream& out ); - void WriteFloat( float val, ostream& out ); - void WriteString( string const & val, ostream& out ); - void WriteBool( bool val, ostream& out, unsigned int version ); - void WriteFVector2( fVector2 const & fvec, ostream& out ); - void WriteFVector3( fVector3 const & fvec, ostream& out ); - void WriteFVector4( fVector4 const & fvec, ostream& out ); - void WriteBlockName( const char* name, uint nameLength, ostream& out ); //Write +void NifStream( int const & val, ostream& out, uint version = 0 ); void NifStream( uint const & val, ostream& out, uint version = 0 ); void NifStream( ushort const & val, ostream& out, uint version = 0 ); void NifStream( short const & val, ostream& out, uint version = 0 ); void NifStream( byte const & val, ostream& out, uint version = 0 ); +void NifStream( bool const & val, ostream& out, uint version ); // version is significant void NifStream( float const & val, ostream& out, uint version = 0 ); void NifStream( string const & val, ostream& out, uint version = 0 ); void NifStream( Vector3 const & val, ostream& out, uint version = 0 ); @@ -261,6 +257,7 @@ void NifStream( Color4 const & val, ostream& out, uint version = 0 ); void NifStream( Triangle const & val, ostream& out, uint version = 0 ); void NifStream( TexDesc const & val, ostream& out, uint version ); // version is significant void NifStream( LODRange const & val, ostream& out, uint version = 0 ); +void NifStream( IBlock const * const val, ostream& out, uint version = 0 ); template <class T> void NifStream( Key<T> const & key, ostream& file, KeyType type ) { @@ -290,10 +287,10 @@ void NifStream( Key<T> const & key, ostream& file, KeyType type ) { void StreamQuatKey( Key<Quaternion> const & key, ostream& file, KeyType type ); template <class T> -void NifStream( vector<T> const & val, ostream& file ) { +void NifStream( vector<T> const & val, ostream& file, uint version = 0 ) { typename vector<T>::const_iterator it; for ( it = val.begin(); it != val.end(); ++it ) { - NifStream( *it, file ); + NifStream( *it, file, version ); } } -- GitLab