Factored a NIFStream class out of the NIFFile class.

Split NIFFile into two parts, NIFFile which is cached and is a container
for a parsed NIF, and NIFStream which is a class specialized for parsing
NIFs. This required a semi-sweeping change to make all record classes
accept a NIFStream instead of a NIFFile as an agurment to their read
functions.
This commit is contained in:
Nathan Jeffords 2013-01-05 13:03:05 -08:00
parent 326ebb5010
commit 6de6d9ff6e
12 changed files with 249 additions and 208 deletions

View file

@ -36,7 +36,7 @@ class Controlled : public Extra
public: public:
ControllerPtr controller; ControllerPtr controller;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Extra::read(nif); Extra::read(nif);
controller.read(nif); controller.read(nif);
@ -55,7 +55,7 @@ class Named : public Controlled
public: public:
std::string name; std::string name;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
name = nif->getString(); name = nif->getString();
Controlled::read(nif); Controlled::read(nif);
@ -66,7 +66,7 @@ typedef Named NiSequenceStreamHelper;
class NiParticleGrowFade : public Controlled class NiParticleGrowFade : public Controlled
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controlled::read(nif); Controlled::read(nif);
@ -80,7 +80,7 @@ class NiParticleColorModifier : public Controlled
public: public:
NiColorDataPtr data; NiColorDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controlled::read(nif); Controlled::read(nif);
data.read(nif); data.read(nif);
@ -96,7 +96,7 @@ public:
class NiGravity : public Controlled class NiGravity : public Controlled
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controlled::read(nif); Controlled::read(nif);
@ -109,7 +109,7 @@ public:
class NiPlanarCollider : public Controlled class NiPlanarCollider : public Controlled
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controlled::read(nif); Controlled::read(nif);
@ -121,7 +121,7 @@ public:
class NiParticleRotation : public Controlled class NiParticleRotation : public Controlled
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controlled::read(nif); Controlled::read(nif);

View file

@ -40,7 +40,7 @@ public:
float timeStart, timeStop; float timeStart, timeStop;
ControlledPtr target; ControlledPtr target;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
next.read(nif); next.read(nif);
@ -65,7 +65,7 @@ public:
class NiBSPArrayController : public Controller class NiBSPArrayController : public Controller
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
@ -82,7 +82,7 @@ class NiMaterialColorController : public Controller
public: public:
NiPosDataPtr data; NiPosDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
data.read(nif); data.read(nif);
@ -101,7 +101,7 @@ public:
NiPosDataPtr posData; NiPosDataPtr posData;
NiFloatDataPtr floatData; NiFloatDataPtr floatData;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
@ -129,7 +129,7 @@ class NiUVController : public Controller
public: public:
NiUVDataPtr data; NiUVDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
@ -149,7 +149,7 @@ class NiKeyframeController : public Controller
public: public:
NiKeyframeDataPtr data; NiKeyframeDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
data.read(nif); data.read(nif);
@ -167,7 +167,7 @@ class NiAlphaController : public Controller
public: public:
NiFloatDataPtr data; NiFloatDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
data.read(nif); data.read(nif);
@ -185,7 +185,7 @@ class NiGeomMorpherController : public Controller
public: public:
NiMorphDataPtr data; NiMorphDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
data.read(nif); data.read(nif);
@ -204,7 +204,7 @@ class NiVisController : public Controller
public: public:
NiVisDataPtr data; NiVisDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
data.read(nif); data.read(nif);

View file

@ -65,7 +65,7 @@ public:
*/ */
int alpha; int alpha;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Named::read(nif); Named::read(nif);
@ -102,7 +102,7 @@ public:
Ogre::Vector3 center; Ogre::Vector3 center;
float radius; float radius;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
int verts = nif->getUShort(); int verts = nif->getUShort();
@ -138,7 +138,7 @@ public:
// Triangles, three vertex indices per triangle // Triangles, three vertex indices per triangle
std::vector<short> triangles; std::vector<short> triangles;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
ShapeData::read(nif); ShapeData::read(nif);
@ -167,7 +167,7 @@ class NiAutoNormalParticlesData : public ShapeData
public: public:
int activeCount; int activeCount;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
ShapeData::read(nif); ShapeData::read(nif);
@ -189,7 +189,7 @@ public:
class NiRotatingParticlesData : public NiAutoNormalParticlesData class NiRotatingParticlesData : public NiAutoNormalParticlesData
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
NiAutoNormalParticlesData::read(nif); NiAutoNormalParticlesData::read(nif);
@ -208,7 +208,7 @@ class NiPosData : public Record
public: public:
Vector3KeyList mKeyList; Vector3KeyList mKeyList;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
mKeyList.read(nif); mKeyList.read(nif);
} }
@ -219,7 +219,7 @@ class NiUVData : public Record
public: public:
FloatKeyList mKeyList[4]; FloatKeyList mKeyList[4];
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
for(int i = 0;i < 4;i++) for(int i = 0;i < 4;i++)
mKeyList[i].read(nif); mKeyList[i].read(nif);
@ -231,7 +231,7 @@ class NiFloatData : public Record
public: public:
FloatKeyList mKeyList; FloatKeyList mKeyList;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
mKeyList.read(nif); mKeyList.read(nif);
} }
@ -243,7 +243,7 @@ public:
unsigned int rmask, gmask, bmask, amask; unsigned int rmask, gmask, bmask, amask;
int bpp, mips; int bpp, mips;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
nif->getInt(); // always 0 or 1 nif->getInt(); // always 0 or 1
@ -281,7 +281,7 @@ class NiColorData : public Record
public: public:
Vector4KeyList mKeyList; Vector4KeyList mKeyList;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
mKeyList.read(nif); mKeyList.read(nif);
} }
@ -295,7 +295,7 @@ public:
char isSet; char isSet;
}; };
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
int count = nif->getInt(); int count = nif->getInt();
@ -311,7 +311,7 @@ public:
NodePtr root; NodePtr root;
NodeList bones; NodeList bones;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
data.read(nif); data.read(nif);
root.read(nif); root.read(nif);
@ -347,7 +347,7 @@ public:
BoneTrafo trafo; BoneTrafo trafo;
std::vector<BoneInfo> bones; std::vector<BoneInfo> bones;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
trafo.rotation = nif->getMatrix3(); trafo.rotation = nif->getMatrix3();
trafo.trans = nif->getVector3(); trafo.trans = nif->getVector3();
@ -385,7 +385,7 @@ struct NiMorphData : public Record
}; };
std::vector<MorphData> mMorphs; std::vector<MorphData> mMorphs;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
int morphCount = nif->getInt(); int morphCount = nif->getInt();
int vertCount = nif->getInt(); int vertCount = nif->getInt();
@ -410,7 +410,7 @@ struct NiKeyframeData : public Record
Vector3KeyList mTranslations; Vector3KeyList mTranslations;
FloatKeyList mScales; FloatKeyList mScales;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
mRotations.read(nif); mRotations.read(nif);
mTranslations.read(nif); mTranslations.read(nif);

View file

@ -42,7 +42,7 @@ struct NiLight : Effect
Ogre::Vector3 diffuse; Ogre::Vector3 diffuse;
Ogre::Vector3 specular; Ogre::Vector3 specular;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
dimmer = nif->getFloat(); dimmer = nif->getFloat();
ambient = nif->getVector3(); ambient = nif->getVector3();
@ -52,7 +52,7 @@ struct NiLight : Effect
}; };
SLight light; SLight light;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Effect::read(nif); Effect::read(nif);
@ -66,7 +66,7 @@ struct NiTextureEffect : Effect
{ {
NiSourceTexturePtr texture; NiSourceTexturePtr texture;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Effect::read(nif); Effect::read(nif);

View file

@ -40,14 +40,14 @@ class Extra : public Record
public: public:
ExtraPtr extra; ExtraPtr extra;
void read(NIFFile *nif) { extra.read(nif); } void read(NIFStream *nif) { extra.read(nif); }
void post(NIFFile *nif) { extra.post(nif); } void post(NIFFile *nif) { extra.post(nif); }
}; };
class NiVertWeightsExtraData : public Extra class NiVertWeightsExtraData : public Extra
{ {
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Extra::read(nif); Extra::read(nif);
@ -70,7 +70,7 @@ public:
}; };
std::vector<TextKey> list; std::vector<TextKey> list;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Extra::read(nif); Extra::read(nif);
@ -95,7 +95,7 @@ public:
*/ */
std::string string; std::string string;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Extra::read(nif); Extra::read(nif);

View file

@ -174,10 +174,7 @@ NIFFile::ptr NIFFile::create (const std::string &name) { return LoadedCache::cre
NIFFile::NIFFile(const std::string &name, psudo_private_modifier) NIFFile::NIFFile(const std::string &name, psudo_private_modifier)
: filename(name) : filename(name)
{ {
inp = Ogre::ResourceGroupManager::getSingleton().openResource(name);
parse(); parse();
// Make sure to close the file after it was loaded into memory
inp.setNull();
} }
NIFFile::~NIFFile() NIFFile::~NIFFile()
@ -195,18 +192,20 @@ NIFFile::~NIFFile()
void NIFFile::parse() void NIFFile::parse()
{ {
NIFStream nif (this, Ogre::ResourceGroupManager::getSingleton().openResource(filename));
// Check the header string // Check the header string
std::string head = getString(40); std::string head = nif.getString(40);
if(head.compare(0, 22, "NetImmerse File Format") != 0) if(head.compare(0, 22, "NetImmerse File Format") != 0)
fail("Invalid NIF header"); fail("Invalid NIF header");
// Get BCD version // Get BCD version
ver = getInt(); ver = nif.getInt();
if(ver != VER_MW) if(ver != VER_MW)
fail("Unsupported NIF version"); fail("Unsupported NIF version");
// Number of records // Number of records
size_t recNum = getInt(); size_t recNum = nif.getInt();
records.resize(recNum); records.resize(recNum);
/* The format for 10.0.1.0 seems to be a bit different. After the /* The format for 10.0.1.0 seems to be a bit different. After the
@ -222,7 +221,7 @@ void NIFFile::parse()
{ {
Record *r = NULL; Record *r = NULL;
std::string rec = getString(); std::string rec = nif.getString();
/* These are all the record types we know how to read. /* These are all the record types we know how to read.
@ -312,7 +311,7 @@ void NIFFile::parse()
r->recName = rec; r->recName = rec;
r->recIndex = i; r->recIndex = i;
records[i] = r; records[i] = r;
r->read(this); r->read(&nif);
// Discard tranformations for the root node, otherwise some meshes // Discard tranformations for the root node, otherwise some meshes
// occasionally get wrong orientation. Only for NiNode-s for now, but // occasionally get wrong orientation. Only for NiNode-s for now, but

View file

@ -46,6 +46,7 @@
#include "record.hpp" #include "record.hpp"
#include "nif_types.hpp" #include "nif_types.hpp"
#include "nif_stream.hpp"
namespace Nif namespace Nif
{ {
@ -59,9 +60,6 @@ class NIFFile
/// Nif file version /// Nif file version
int ver; int ver;
/// Input stream
Ogre::DataStreamPtr inp;
/// File name, used for error messages /// File name, used for error messages
std::string filename; std::string filename;
@ -71,33 +69,6 @@ class NIFFile
/// Parse the file /// Parse the file
void parse(); void parse();
uint8_t read_byte()
{
uint8_t byte;
if(inp->read(&byte, 1) != 1) return 0;
return byte;
}
uint16_t read_le16()
{
uint8_t buffer[2];
if(inp->read(buffer, 2) != 2) return 0;
return buffer[0] | (buffer[1]<<8);
}
uint32_t read_le32()
{
uint8_t buffer[4];
if(inp->read(buffer, 4) != 4) return 0;
return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24);
}
float read_le32f()
{
union {
uint32_t i;
float f;
} u = { read_le32() };
return u.f;
}
class LoadedCache; class LoadedCache;
friend class LoadedCache; friend class LoadedCache;
@ -117,8 +88,8 @@ public:
void warn(const std::string &msg) void warn(const std::string &msg)
{ {
std::cerr<< "NIFFile Warning: "<<msg <<std::endl std::cerr << "NIFFile Warning: " << msg <<std::endl
<< "File: "<<filename <<std::endl; << "File: " << filename <<std::endl;
} }
typedef boost::shared_ptr <NIFFile> ptr; typedef boost::shared_ptr <NIFFile> ptr;
@ -147,111 +118,6 @@ public:
/// Number of records /// Number of records
size_t numRecords() { return records.size(); } size_t numRecords() { return records.size(); }
/*************************************************
Parser functions
****************************************************/
void skip(size_t size) { inp->skip(size); }
char getChar() { return read_byte(); }
short getShort() { return read_le16(); }
unsigned short getUShort() { return read_le16(); }
int getInt() { return read_le32(); }
unsigned int getUInt() { return read_le32(); }
float getFloat() { return read_le32f(); }
Ogre::Vector2 getVector2()
{
float a[2];
for(size_t i = 0;i < 2;i++)
a[i] = getFloat();
return Ogre::Vector2(a);
}
Ogre::Vector3 getVector3()
{
float a[3];
for(size_t i = 0;i < 3;i++)
a[i] = getFloat();
return Ogre::Vector3(a);
}
Ogre::Vector4 getVector4()
{
float a[4];
for(size_t i = 0;i < 4;i++)
a[i] = getFloat();
return Ogre::Vector4(a);
}
Ogre::Matrix3 getMatrix3()
{
Ogre::Real a[3][3];
for(size_t i = 0;i < 3;i++)
{
for(size_t j = 0;j < 3;j++)
a[i][j] = Ogre::Real(getFloat());
}
return Ogre::Matrix3(a);
}
Ogre::Quaternion getQuaternion()
{
float a[4];
for(size_t i = 0;i < 4;i++)
a[i] = getFloat();
return Ogre::Quaternion(a);
}
Transformation getTrafo()
{
Transformation t;
t.pos = getVector3();
t.rotation = getMatrix3();
t.scale = getFloat();
return t;
}
std::string getString(size_t length)
{
std::vector<char> str (length+1, 0);
if(inp->read(&str[0], length) != length)
throw std::runtime_error ("string length in NIF file does not match");
return &str[0];
}
std::string getString()
{
size_t size = read_le32();
return getString(size);
}
void getShorts(std::vector<short> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getShort();
}
void getFloats(std::vector<float> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getFloat();
}
void getVector2s(std::vector<Ogre::Vector2> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector2();
}
void getVector3s(std::vector<Ogre::Vector3> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector3();
}
void getVector4s(std::vector<Ogre::Vector4> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector4();
}
}; };
@ -270,7 +136,7 @@ typedef KeyT<Ogre::Vector3> Vector3Key;
typedef KeyT<Ogre::Vector4> Vector4Key; typedef KeyT<Ogre::Vector4> Vector4Key;
typedef KeyT<Ogre::Quaternion> QuaternionKey; typedef KeyT<Ogre::Quaternion> QuaternionKey;
template<typename T, T (NIFFile::*getValue)()> template<typename T, T (NIFStream::*getValue)()>
struct KeyListT { struct KeyListT {
typedef std::vector< KeyT<T> > VecType; typedef std::vector< KeyT<T> > VecType;
@ -281,7 +147,7 @@ struct KeyListT {
int mInterpolationType; int mInterpolationType;
VecType mKeys; VecType mKeys;
void read(NIFFile *nif, bool force=false) void read(NIFStream *nif, bool force=false)
{ {
size_t count = nif->getInt(); size_t count = nif->getInt();
if(count == 0 && !force) if(count == 0 && !force)
@ -322,13 +188,13 @@ struct KeyListT {
} }
} }
else else
nif->warn("Unhandled interpolation type: "+Ogre::StringConverter::toString(mInterpolationType)); nif->file->warn("Unhandled interpolation type: "+Ogre::StringConverter::toString(mInterpolationType));
} }
}; };
typedef KeyListT<float,&NIFFile::getFloat> FloatKeyList; typedef KeyListT<float,&NIFStream::getFloat> FloatKeyList;
typedef KeyListT<Ogre::Vector3,&NIFFile::getVector3> Vector3KeyList; typedef KeyListT<Ogre::Vector3,&NIFStream::getVector3> Vector3KeyList;
typedef KeyListT<Ogre::Vector4,&NIFFile::getVector4> Vector4KeyList; typedef KeyListT<Ogre::Vector4,&NIFStream::getVector4> Vector4KeyList;
typedef KeyListT<Ogre::Quaternion,&NIFFile::getQuaternion> QuaternionKeyList; typedef KeyListT<Ogre::Quaternion,&NIFStream::getQuaternion> QuaternionKeyList;
} // Namespace } // Namespace
#endif #endif

View file

@ -0,0 +1,175 @@
#ifndef _NIF_STREAM_HPP_
#define _NIF_STREAM_HPP_
namespace Nif
{
class NIFFile;
class NIFStream {
/// Input stream
Ogre::DataStreamPtr inp;
uint8_t read_byte()
{
uint8_t byte;
if(inp->read(&byte, 1) != 1) return 0;
return byte;
}
uint16_t read_le16()
{
uint8_t buffer[2];
if(inp->read(buffer, 2) != 2) return 0;
return buffer[0] | (buffer[1]<<8);
}
uint32_t read_le32()
{
uint8_t buffer[4];
if(inp->read(buffer, 4) != 4) return 0;
return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24);
}
float read_le32f()
{
union {
uint32_t i;
float f;
} u = { read_le32() };
return u.f;
}
public:
NIFFile * const file;
NIFStream (NIFFile * file, Ogre::DataStreamPtr inp): file (file), inp (inp) {}
/*************************************************
Parser functions
****************************************************/
template <typename T>
struct GetHandler
{
typedef T (NIFStream::*fn_t)();
static const fn_t sValue; // this is specialized per supported type in the .cpp file
static T read (NIFStream* nif)
{
return (nif->*sValue) ();
}
};
template <typename T>
void read (NIFStream* nif, T & Value)
{
Value = GetHandler <T>::read (nif);
}
void skip(size_t size) { inp->skip(size); }
void read (void * data, size_t size) { inp->read (data, size); }
char getChar() { return read_byte(); }
short getShort() { return read_le16(); }
unsigned short getUShort() { return read_le16(); }
int getInt() { return read_le32(); }
int getUInt() { return read_le32(); }
float getFloat() { return read_le32f(); }
Ogre::Vector2 getVector2()
{
float a[2];
for(size_t i = 0;i < 2;i++)
a[i] = getFloat();
return Ogre::Vector2(a);
}
Ogre::Vector3 getVector3()
{
float a[3];
for(size_t i = 0;i < 3;i++)
a[i] = getFloat();
return Ogre::Vector3(a);
}
Ogre::Vector4 getVector4()
{
float a[4];
for(size_t i = 0;i < 4;i++)
a[i] = getFloat();
return Ogre::Vector4(a);
}
Ogre::Matrix3 getMatrix3()
{
Ogre::Real a[3][3];
for(size_t i = 0;i < 3;i++)
{
for(size_t j = 0;j < 3;j++)
a[i][j] = Ogre::Real(getFloat());
}
return Ogre::Matrix3(a);
}
Ogre::Quaternion getQuaternion()
{
float a[4];
for(size_t i = 0;i < 4;i++)
a[i] = getFloat();
return Ogre::Quaternion(a);
}
Transformation getTrafo()
{
Transformation t;
t.pos = getVector3();
t.rotation = getMatrix3();
t.scale = getFloat();
return t;
}
std::string getString(size_t length)
{
std::vector<char> str (length+1, 0);
if(inp->read(&str[0], length) != length)
throw std::runtime_error ("string length in NIF file does not match");
return &str[0];
}
std::string getString()
{
size_t size = read_le32();
return getString(size);
}
void getShorts(std::vector<short> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getShort();
}
void getFloats(std::vector<float> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getFloat();
}
void getVector2s(std::vector<Ogre::Vector2> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector2();
}
void getVector3s(std::vector<Ogre::Vector3> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector3();
}
void getVector4s(std::vector<Ogre::Vector4> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector4();
}
};
}
#endif

View file

@ -54,7 +54,7 @@ public:
Ogre::Matrix3 boundRot; Ogre::Matrix3 boundRot;
Ogre::Vector3 boundXYZ; // Box size Ogre::Vector3 boundXYZ; // Box size
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Named::read(nif); Named::read(nif);
@ -128,7 +128,7 @@ struct NiNode : Node
0x20, 0x40, 0x80 unknown 0x20, 0x40, 0x80 unknown
*/ */
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Node::read(nif); Node::read(nif);
children.read(nif); children.read(nif);
@ -162,7 +162,7 @@ struct NiTriShape : Node
NiTriShapeDataPtr data; NiTriShapeDataPtr data;
NiSkinInstancePtr skin; NiSkinInstancePtr skin;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Node::read(nif); Node::read(nif);
data.read(nif); data.read(nif);
@ -190,7 +190,7 @@ struct NiCamera : Node
// Level of detail modifier // Level of detail modifier
float LOD; float LOD;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
left = nif->getFloat(); left = nif->getFloat();
right = nif->getFloat(); right = nif->getFloat();
@ -209,7 +209,7 @@ struct NiCamera : Node
}; };
Camera cam; Camera cam;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Node::read(nif); Node::read(nif);
@ -224,7 +224,7 @@ struct NiAutoNormalParticles : Node
{ {
NiAutoNormalParticlesDataPtr data; NiAutoNormalParticlesDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Node::read(nif); Node::read(nif);
data.read(nif); data.read(nif);
@ -242,7 +242,7 @@ struct NiRotatingParticles : Node
{ {
NiRotatingParticlesDataPtr data; NiRotatingParticlesDataPtr data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Node::read(nif); Node::read(nif);
data.read(nif); data.read(nif);

View file

@ -35,7 +35,7 @@ public:
// The meaning of these depends on the actual property type. // The meaning of these depends on the actual property type.
int flags; int flags;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Named::read(nif); Named::read(nif);
flags = nif->getUShort(); flags = nif->getUShort();
@ -67,7 +67,7 @@ public:
int clamp, set, filter; int clamp, set, filter;
short unknown2; short unknown2;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
inUse = !!nif->getInt(); inUse = !!nif->getInt();
if(!inUse) return; if(!inUse) return;
@ -111,7 +111,7 @@ public:
*/ */
Texture textures[7]; Texture textures[7];
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Property::read(nif); Property::read(nif);
apply = nif->getInt(); apply = nif->getInt();
@ -157,7 +157,7 @@ struct StructPropT : Property
{ {
T data; T data;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
Property::read(nif); Property::read(nif);
data.read(nif); data.read(nif);
@ -170,7 +170,7 @@ struct S_MaterialProperty
Ogre::Vector3 ambient, diffuse, specular, emissive; Ogre::Vector3 ambient, diffuse, specular, emissive;
float glossiness, alpha; float glossiness, alpha;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
ambient = nif->getVector3(); ambient = nif->getVector3();
diffuse = nif->getVector3(); diffuse = nif->getVector3();
@ -194,7 +194,7 @@ struct S_VertexColorProperty
*/ */
int vertmode, lightmode; int vertmode, lightmode;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
vertmode = nif->getInt(); vertmode = nif->getInt();
lightmode = nif->getInt(); lightmode = nif->getInt();
@ -251,7 +251,7 @@ struct S_AlphaProperty
// Tested against when certain flags are set (see above.) // Tested against when certain flags are set (see above.)
unsigned char threshold; unsigned char threshold;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
threshold = nif->getChar(); threshold = nif->getChar();
} }
@ -300,7 +300,7 @@ struct S_StencilProperty
*/ */
int drawMode; int drawMode;
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
enabled = nif->getChar(); enabled = nif->getChar();
compareFunc = nif->getInt(); compareFunc = nif->getInt();

View file

@ -30,6 +30,7 @@ namespace Nif
{ {
class NIFFile; class NIFFile;
class NIFStream;
enum RecordType enum RecordType
{ {
@ -97,7 +98,7 @@ struct Record
Record() : recType(RC_MISSING), recIndex(~(size_t)0) {} Record() : recType(RC_MISSING), recIndex(~(size_t)0) {}
/// Parses the record from file /// Parses the record from file
virtual void read(NIFFile *nif) = 0; virtual void read(NIFStream *nif) = 0;
/// Does post-processing, after the entire tree is loaded /// Does post-processing, after the entire tree is loaded
virtual void post(NIFFile *nif) {} virtual void post(NIFFile *nif) {}

View file

@ -46,7 +46,7 @@ public:
RecordPtrT() : index(-2) {} RecordPtrT() : index(-2) {}
/// Read the index from the nif /// Read the index from the nif
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
// Can only read the index once // Can only read the index once
assert(index == -2); assert(index == -2);
@ -99,7 +99,7 @@ class RecordListT
std::vector<Ptr> list; std::vector<Ptr> list;
public: public:
void read(NIFFile *nif) void read(NIFStream *nif)
{ {
int len = nif->getInt(); int len = nif->getInt();
list.resize(len); list.resize(len);