Skip to content
Browse files

More endian-awareness

  • Loading branch information...
1 parent 7c349b7 commit abf7e244782a1e4d45e1c071bff094389d7ac781 @Alphax committed
Showing with 57 additions and 5 deletions.
  1. +1 −0 basemodel.cpp
  2. +1 −1 docsys
  3. +26 −0 niftypes.h
  4. +29 −4 nifvalue.cpp
View
1 basemodel.cpp
@@ -95,6 +95,7 @@ int BaseModel::evaluateString( NifItem * array, const QString & text ) const
{
QString left, right;
+ // TODO: work out how to deal with brackets...
static const char * const exp[] = { " | ", " & ", " / ", " + ", " - ", " * " };
static const int num_exp = 6;
2 docsys
@@ -1 +1 @@
-Subproject commit 86f680b907e5c8d1b24c692c169457e540f6fff2
+Subproject commit c8c5252b7b1a02af47938ed8075cd7ea0c0f7915
View
26 niftypes.h
@@ -179,6 +179,8 @@ class Vector2
friend class NifIStream;
friend class NifOStream;
+
+ friend QDataStream & operator>>( QDataStream & ds, Vector2 & v );
};
//! An attempt at providing a QDebug stream operator for Vector2
@@ -192,6 +194,13 @@ inline QDebug &operator<<( QDebug dbg, Vector2 v )
return dbg.space();
}
+//! A stream operator for reading in a Vector2
+inline QDataStream & operator>>( QDataStream & ds, Vector2 & v )
+{
+ ds >> v.xy[0] >> v.xy[1];
+ return ds;
+}
+
//! A vector of 3 floats
class Vector3
{
@@ -761,8 +770,17 @@ class Quat
friend class NifIStream;
friend class NifOStream;
+
+ friend QDataStream & operator>>( QDataStream & ds, Quat & q );
};
+//! A stream operator for reading in a Quat
+inline QDataStream & operator>>( QDataStream & ds, Quat & q )
+{
+ ds >> q.wxyz[0] >> q.wxyz[1] >> q.wxyz[2] >> q.wxyz[3];
+ return ds;
+}
+
//! A 3 by 3 matrix
class Matrix
{
@@ -1282,6 +1300,8 @@ class Color4
friend class NifIStream;
friend class NifOStream;
+
+ friend QDataStream & operator>>( QDataStream & ds, Color4 & c );
};
// This refuses to document properly in doxygen.
@@ -1292,6 +1312,12 @@ inline Color3::Color3( const Color4 & c4 )
rgb[2] = c4[2];
}
+//! A stream operator for reading in a Color4
+inline QDataStream & operator>>( QDataStream & ds, Color4 & c )
+{
+ ds >> c.rgba[0] >> c.rgba[1] >> c.rgba[2] >> c.rgba[3];
+ return ds;
+}
//! A fixed length vector of type T.
/*!
View
33 nifvalue.cpp
@@ -793,31 +793,41 @@ bool NifIStream::read( NifValue & val )
switch ( val.type() )
{
case NifValue::tBool:
+ {
val.val.u32 = 0;
if ( bool32bit )
*dataStream >> val.val.u32;
else
*dataStream >> val.val.u08;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tByte:
+ {
val.val.u32 = 0;
*dataStream >> val.val.u08;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tWord:
case NifValue::tShort:
case NifValue::tFlags:
case NifValue::tBlockTypeIndex:
+ {
val.val.u32 = 0;
*dataStream >> val.val.u16;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tStringOffset:
case NifValue::tInt:
case NifValue::tUInt:
+ {
*dataStream >> val.val.u32;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tStringIndex:
+ {
*dataStream >> val.val.u32;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tLink:
case NifValue::tUpLink:
{
@@ -827,8 +837,10 @@ bool NifIStream::read( NifValue & val )
return ( dataStream->status() == QDataStream::Ok );
}
case NifValue::tFloat:
+ {
*dataStream >> val.val.f32;
return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tVector3:
{
Vector3 * v = static_cast<Vector3*>( val.val.data );
@@ -848,7 +860,11 @@ bool NifIStream::read( NifValue & val )
return ( dataStream->status() == QDataStream::Ok );
}
case NifValue::tQuat:
- return device->read( (char *) static_cast<Quat*>( val.val.data )->wxyz, 16 ) == 16;
+ {
+ Quat * q = static_cast<Quat*>( val.val.data );
+ *dataStream >> *q;
+ return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tQuatXYZW:
{
Quat * q = static_cast<Quat*>( val.val.data );
@@ -859,11 +875,19 @@ bool NifIStream::read( NifValue & val )
case NifValue::tMatrix4:
return device->read( (char *) static_cast<Matrix4*>( val.val.data )->m, 64 ) == 64;
case NifValue::tVector2:
- return device->read( (char *) static_cast<Vector2*>( val.val.data )->xy, 8 ) == 8;
+ {
+ Vector2 * v = static_cast<Vector2*>( val.val.data );
+ *dataStream >> *v;
+ return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tColor3:
return device->read( (char *) static_cast<Color3*>( val.val.data )->rgb, 12 ) == 12;
case NifValue::tColor4:
- return device->read( (char *) static_cast<Color4*>( val.val.data )->rgba, 16 ) == 16;
+ {
+ Color4 * c = static_cast<Color4*>( val.val.data );
+ *dataStream >> *c;
+ return ( dataStream->status() == QDataStream::Ok );
+ }
case NifValue::tSizedString:
{
int len;
@@ -1017,12 +1041,13 @@ bool NifIStream::read( NifValue & val )
}
case NifValue::tBlob:
+ {
if ( val.val.data ) {
QByteArray* array = static_cast<QByteArray*>( val.val.data );
return device->read( array->data(), array->size() ) == array->size();
}
return false;
-
+ }
case NifValue::tNone:
return true;
}

0 comments on commit abf7e24

Please sign in to comment.
Something went wrong with that request. Please try again.