From 6b36e55a4e78df0a7e996bd8dfa55895ce78e15e Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 22 Feb 2015 19:17:03 +0100 Subject: [PATCH] NIF reader cleanup: move definitions to cpp file --- components/nif/base.hpp | 22 +--- components/nif/controlled.hpp | 78 ++----------- components/nif/controller.hpp | 182 +++-------------------------- components/nif/data.cpp | 209 +++++++++++++++++++++++++++++++++ components/nif/data.hpp | 210 +++------------------------------- components/nif/effect.hpp | 52 +-------- components/nif/extra.hpp | 35 +----- components/nif/nifkey.hpp | 4 + components/nif/property.hpp | 109 ++---------------- components/nif/record.hpp | 6 - 10 files changed, 274 insertions(+), 633 deletions(-) diff --git a/components/nif/base.hpp b/components/nif/base.hpp index 30c652b64..4b2e40dec 100644 --- a/components/nif/base.hpp +++ b/components/nif/base.hpp @@ -32,26 +32,8 @@ public: float timeStart, timeStop; ControlledPtr target; - void read(NIFStream *nif) - { - next.read(nif); - - flags = nif->getUShort(); - - frequency = nif->getFloat(); - phase = nif->getFloat(); - timeStart = nif->getFloat(); - timeStop = nif->getFloat(); - - target.read(nif); - } - - void post(NIFFile *nif) - { - Record::post(nif); - next.post(nif); - target.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; /// Anything that has a controller diff --git a/components/nif/controlled.hpp b/components/nif/controlled.hpp index 51890f069..ac75c3508 100644 --- a/components/nif/controlled.hpp +++ b/components/nif/controlled.hpp @@ -62,31 +62,8 @@ public: */ int alpha; - void read(NIFStream *nif) - { - Named::read(nif); - - external = !!nif->getChar(); - if(external) - filename = nif->getString(); - else - { - nif->getChar(); // always 1 - data.read(nif); - } - - pixel = nif->getInt(); - mipmap = nif->getInt(); - alpha = nif->getInt(); - - nif->getChar(); // always 1 - } - - void post(NIFFile *nif) - { - Named::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiParticleGrowFade : public Controlled @@ -95,12 +72,7 @@ public: float growTime; float fadeTime; - void read(NIFStream *nif) - { - Controlled::read(nif); - growTime = nif->getFloat(); - fadeTime = nif->getFloat(); - } + void read(NIFStream *nif); }; class NiParticleColorModifier : public Controlled @@ -108,17 +80,8 @@ class NiParticleColorModifier : public Controlled public: NiColorDataPtr data; - void read(NIFStream *nif) - { - Controlled::read(nif); - data.read(nif); - } - - void post(NIFFile *nif) - { - Controlled::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiGravity : public Controlled @@ -132,45 +95,20 @@ public: osg::Vec3f mPosition; osg::Vec3f mDirection; - void read(NIFStream *nif) - { - Controlled::read(nif); - - /*unknown*/nif->getFloat(); - mForce = nif->getFloat(); - mType = nif->getUInt(); - mPosition = nif->getVector3(); - mDirection = nif->getVector3(); - } + void read(NIFStream *nif); }; // NiPinaColada class NiPlanarCollider : public Controlled { public: - void read(NIFStream *nif) - { - Controlled::read(nif); - - // (I think) 4 floats + 4 vectors - nif->skip(4*16); - } + void read(NIFStream *nif); }; class NiParticleRotation : public Controlled { public: - void read(NIFStream *nif) - { - Controlled::read(nif); - - /* - byte (0 or 1) - float (1) - float*3 - */ - nif->skip(17); - } + void read(NIFStream *nif); }; diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index 718748c31..73344e77b 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -74,66 +74,8 @@ public: ExtraPtr extra; - void read(NIFStream *nif) - { - Controller::read(nif); - - velocity = nif->getFloat(); - velocityRandom = nif->getFloat(); - verticalDir = nif->getFloat(); - verticalAngle = nif->getFloat(); - horizontalDir = nif->getFloat(); - horizontalAngle = nif->getFloat(); - /*normal?*/ nif->getVector3(); - /*color?*/ nif->getVector4(); - size = nif->getFloat(); - startTime = nif->getFloat(); - stopTime = nif->getFloat(); - nif->getChar(); - emitRate = nif->getFloat(); - lifetime = nif->getFloat(); - lifetimeRandom = nif->getFloat(); - - emitFlags = nif->getUShort(); - offsetRandom = nif->getVector3(); - - emitter.read(nif); - - /* Unknown Short, 0? - * Unknown Float, 1.0? - * Unknown Int, 1? - * Unknown Int, 0? - * Unknown Short, 0? - */ - nif->skip(16); - - numParticles = nif->getUShort(); - activeCount = nif->getUShort(); - - particles.resize(numParticles); - for(size_t i = 0;i < particles.size();i++) - { - particles[i].velocity = nif->getVector3(); - nif->getVector3(); /* unknown */ - particles[i].lifetime = nif->getFloat(); - particles[i].lifespan = nif->getFloat(); - particles[i].timestamp = nif->getFloat(); - nif->getUShort(); /* unknown */ - particles[i].vertex = nif->getUShort(); - } - - nif->getUInt(); /* -1? */ - extra.read(nif); - nif->getUInt(); /* -1? */ - nif->getChar(); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - emitter.post(nif); - extra.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; typedef NiParticleSystemController NiBSPArrayController; @@ -142,17 +84,8 @@ class NiMaterialColorController : public Controller public: NiPosDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - data.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiPathController : public Controller @@ -161,27 +94,8 @@ public: NiPosDataPtr posData; NiFloatDataPtr floatData; - void read(NIFStream *nif) - { - Controller::read(nif); - - /* - int = 1 - 2xfloat - short = 0 or 1 - */ - nif->skip(14); - posData.read(nif); - floatData.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - - posData.post(nif); - floatData.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiUVController : public Controller @@ -189,19 +103,8 @@ class NiUVController : public Controller public: NiUVDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - - nif->getUShort(); // always 0 - data.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiKeyframeController : public Controller @@ -209,17 +112,8 @@ class NiKeyframeController : public Controller public: NiKeyframeDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - data.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiAlphaController : public Controller @@ -227,17 +121,8 @@ class NiAlphaController : public Controller public: NiFloatDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - data.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiGeomMorpherController : public Controller @@ -245,18 +130,8 @@ class NiGeomMorpherController : public Controller public: NiMorphDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - data.read(nif); - nif->getChar(); // always 0 - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiVisController : public Controller @@ -264,17 +139,8 @@ class NiVisController : public Controller public: NiVisDataPtr data; - void read(NIFStream *nif) - { - Controller::read(nif); - data.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - data.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiFlipController : public Controller @@ -284,20 +150,8 @@ public: float mDelta; // Time between two flips. delta = (start_time - stop_time) / num_sources NiSourceTextureList mSources; - void read(NIFStream *nif) - { - Controller::read(nif); - mTexSlot = nif->getUInt(); - /*unknown=*/nif->getUInt();/*0?*/ - mDelta = nif->getFloat(); - mSources.read(nif); - } - - void post(NIFFile *nif) - { - Controller::post(nif); - mSources.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; } // Namespace diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 4248b93d2..c4de1e1bf 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -3,6 +3,13 @@ namespace Nif { +void NiSkinInstance::read(NIFStream *nif) +{ + data.read(nif); + root.read(nif); + bones.read(nif); +} + void NiSkinInstance::post(NIFFile *nif) { data.post(nif); @@ -26,4 +33,206 @@ void NiSkinInstance::post(NIFFile *nif) } } +void ShapeData::read(NIFStream *nif) +{ + int verts = nif->getUShort(); + + if(nif->getInt()) + nif->getVector3s(vertices, verts); + + if(nif->getInt()) + nif->getVector3s(normals, verts); + + center = nif->getVector3(); + radius = nif->getFloat(); + + if(nif->getInt()) + nif->getVector4s(colors, verts); + + // Only the first 6 bits are used as a count. I think the rest are + // flags of some sort. + int uvs = nif->getUShort(); + uvs &= 0x3f; + + if(nif->getInt()) + { + uvlist.resize(uvs); + for(int i = 0;i < uvs;i++) + nif->getVector2s(uvlist[i], verts); + } +} + +void NiTriShapeData::read(NIFStream *nif) +{ + ShapeData::read(nif); + + /*int tris =*/ nif->getUShort(); + + // We have three times as many vertices as triangles, so this + // is always equal to tris*3. + int cnt = nif->getInt(); + nif->getShorts(triangles, cnt); + + // Read the match list, which lists the vertices that are equal to + // vertices. We don't actually need need this for anything, so + // just skip it. + int verts = nif->getUShort(); + for(int i=0;i < verts;i++) + { + // Number of vertices matching vertex 'i' + int num = nif->getUShort(); + nif->skip(num * sizeof(short)); + } +} + +void NiAutoNormalParticlesData::read(NIFStream *nif) +{ + ShapeData::read(nif); + + // Should always match the number of vertices + numParticles = nif->getUShort(); + + particleRadius = nif->getFloat(); + activeCount = nif->getUShort(); + + if(nif->getInt()) + { + // Particle sizes + nif->getFloats(sizes, vertices.size()); + } +} + +void NiRotatingParticlesData::read(NIFStream *nif) +{ + NiAutoNormalParticlesData::read(nif); + + if(nif->getInt()) + { + // Rotation quaternions. + nif->getQuaternions(rotations, vertices.size()); + } +} + +void NiPosData::read(NIFStream *nif) +{ + mKeyList.read(nif); +} + +void NiUVData::read(NIFStream *nif) +{ + for(int i = 0;i < 4;i++) + mKeyList[i].read(nif); +} + +void NiFloatData::read(NIFStream *nif) +{ + mKeyList.read(nif); +} + +void NiPixelData::read(NIFStream *nif) +{ + nif->getInt(); // always 0 or 1 + + rmask = nif->getInt(); // usually 0xff + gmask = nif->getInt(); // usually 0xff00 + bmask = nif->getInt(); // usually 0xff0000 + amask = nif->getInt(); // usually 0xff000000 or zero + + bpp = nif->getInt(); + + // Unknown + nif->skip(12); + + mips = nif->getInt(); + + // Bytes per pixel, should be bpp * 8 + /*int bytes =*/ nif->getInt(); + + for(int i=0; igetInt(); + /*int y =*/ nif->getInt(); + /*int offset =*/ nif->getInt(); + } + + // Skip the data + unsigned int dataSize = nif->getInt(); + nif->skip(dataSize); +} + +void NiColorData::read(NIFStream *nif) +{ + mKeyMap.read(nif); +} + +void NiVisData::read(NIFStream *nif) +{ + int count = nif->getInt(); + mVis.resize(count); + for(size_t i = 0;i < mVis.size();i++) + { + mVis[i].time = nif->getFloat(); + mVis[i].isSet = nif->getChar(); + } +} + +void NiSkinData::read(NIFStream *nif) +{ + trafo.rotation = nif->getMatrix3(); + trafo.pos = nif->getVector3(); + trafo.scale = nif->getFloat(); + + int boneNum = nif->getInt(); + nif->getInt(); // -1 + + bones.resize(boneNum); + for(int i=0;igetMatrix3(); + bi.trafo.pos = nif->getVector3(); + bi.trafo.scale = nif->getFloat(); + bi.unknown = nif->getVector4(); + + // Number of vertex weights + bi.weights.resize(nif->getUShort()); + for(size_t j = 0;j < bi.weights.size();j++) + { + bi.weights[j].vertex = nif->getUShort(); + bi.weights[j].weight = nif->getFloat(); + } + } +} + +void NiMorphData::read(NIFStream *nif) +{ + int morphCount = nif->getInt(); + int vertCount = nif->getInt(); + /*relative targets?*/nif->getChar(); + + mMorphs.resize(morphCount); + for(int i = 0;i < morphCount;i++) + { + mMorphs[i].mData.read(nif, true); + nif->getVector3s(mMorphs[i].mVertices, vertCount); + } +} + +void NiKeyframeData::read(NIFStream *nif) +{ + mRotations.read(nif); + if(mRotations.mInterpolationType == mRotations.sXYZInterpolation) + { + //Chomp unused float + nif->getFloat(); + mXRotations.read(nif, true); + mYRotations.read(nif, true); + mZRotations.read(nif, true); + } + mTranslations.read(nif); + mScales.read(nif); +} + } // Namespace diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 656d27628..3b1244831 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -41,34 +41,7 @@ public: osg::Vec3f center; float radius; - void read(NIFStream *nif) - { - int verts = nif->getUShort(); - - if(nif->getInt()) - nif->getVector3s(vertices, verts); - - if(nif->getInt()) - nif->getVector3s(normals, verts); - - center = nif->getVector3(); - radius = nif->getFloat(); - - if(nif->getInt()) - nif->getVector4s(colors, verts); - - // Only the first 6 bits are used as a count. I think the rest are - // flags of some sort. - int uvs = nif->getUShort(); - uvs &= 0x3f; - - if(nif->getInt()) - { - uvlist.resize(uvs); - for(int i = 0;i < uvs;i++) - nif->getVector2s(uvlist[i], verts); - } - } + void read(NIFStream *nif); }; class NiTriShapeData : public ShapeData @@ -77,28 +50,7 @@ public: // Triangles, three vertex indices per triangle std::vector triangles; - void read(NIFStream *nif) - { - ShapeData::read(nif); - - /*int tris =*/ nif->getUShort(); - - // We have three times as many vertices as triangles, so this - // is always equal to tris*3. - int cnt = nif->getInt(); - nif->getShorts(triangles, cnt); - - // Read the match list, which lists the vertices that are equal to - // vertices. We don't actually need need this for anything, so - // just skip it. - int verts = nif->getUShort(); - for(int i=0;i < verts;i++) - { - // Number of vertices matching vertex 'i' - int num = nif->getUShort(); - nif->skip(num * sizeof(short)); - } - } + void read(NIFStream *nif); }; class NiAutoNormalParticlesData : public ShapeData @@ -112,22 +64,7 @@ public: std::vector sizes; - void read(NIFStream *nif) - { - ShapeData::read(nif); - - // Should always match the number of vertices - numParticles = nif->getUShort(); - - particleRadius = nif->getFloat(); - activeCount = nif->getUShort(); - - if(nif->getInt()) - { - // Particle sizes - nif->getFloats(sizes, vertices.size()); - } - } + void read(NIFStream *nif); }; class NiRotatingParticlesData : public NiAutoNormalParticlesData @@ -135,16 +72,7 @@ class NiRotatingParticlesData : public NiAutoNormalParticlesData public: std::vector rotations; - void read(NIFStream *nif) - { - NiAutoNormalParticlesData::read(nif); - - if(nif->getInt()) - { - // Rotation quaternions. - nif->getQuaternions(rotations, vertices.size()); - } - } + void read(NIFStream *nif); }; class NiPosData : public Record @@ -152,10 +80,7 @@ class NiPosData : public Record public: Vector3KeyMap mKeyList; - void read(NIFStream *nif) - { - mKeyList.read(nif); - } + void read(NIFStream *nif); }; class NiUVData : public Record @@ -163,11 +88,7 @@ class NiUVData : public Record public: FloatKeyMap mKeyList[4]; - void read(NIFStream *nif) - { - for(int i = 0;i < 4;i++) - mKeyList[i].read(nif); - } + void read(NIFStream *nif); }; class NiFloatData : public Record @@ -175,10 +96,7 @@ class NiFloatData : public Record public: FloatKeyMap mKeyList; - void read(NIFStream *nif) - { - mKeyList.read(nif); - } + void read(NIFStream *nif); }; class NiPixelData : public Record @@ -187,37 +105,7 @@ public: unsigned int rmask, gmask, bmask, amask; int bpp, mips; - void read(NIFStream *nif) - { - nif->getInt(); // always 0 or 1 - - rmask = nif->getInt(); // usually 0xff - gmask = nif->getInt(); // usually 0xff00 - bmask = nif->getInt(); // usually 0xff0000 - amask = nif->getInt(); // usually 0xff000000 or zero - - bpp = nif->getInt(); - - // Unknown - nif->skip(12); - - mips = nif->getInt(); - - // Bytes per pixel, should be bpp * 8 - /*int bytes =*/ nif->getInt(); - - for(int i=0; igetInt(); - /*int y =*/ nif->getInt(); - /*int offset =*/ nif->getInt(); - } - - // Skip the data - unsigned int dataSize = nif->getInt(); - nif->skip(dataSize); - } + void read(NIFStream *nif); }; class NiColorData : public Record @@ -225,10 +113,7 @@ class NiColorData : public Record public: Vector4KeyMap mKeyMap; - void read(NIFStream *nif) - { - mKeyMap.read(nif); - } + void read(NIFStream *nif); }; class NiVisData : public Record @@ -240,16 +125,7 @@ public: }; std::vector mVis; - void read(NIFStream *nif) - { - int count = nif->getInt(); - mVis.resize(count); - for(size_t i = 0;i < mVis.size();i++) - { - mVis[i].time = nif->getFloat(); - mVis[i].isSet = nif->getChar(); - } - } + void read(NIFStream *nif); }; class NiSkinInstance : public Record @@ -259,13 +135,7 @@ public: NodePtr root; NodeList bones; - void read(NIFStream *nif) - { - data.read(nif); - root.read(nif); - bones.read(nif); - } - + void read(NIFStream *nif); void post(NIFFile *nif); }; @@ -288,34 +158,7 @@ public: Transformation trafo; std::vector bones; - void read(NIFStream *nif) - { - trafo.rotation = nif->getMatrix3(); - trafo.pos = nif->getVector3(); - trafo.scale = nif->getFloat(); - - int boneNum = nif->getInt(); - nif->getInt(); // -1 - - bones.resize(boneNum); - for(int i=0;igetMatrix3(); - bi.trafo.pos = nif->getVector3(); - bi.trafo.scale = nif->getFloat(); - bi.unknown = nif->getVector4(); - - // Number of vertex weights - bi.weights.resize(nif->getUShort()); - for(size_t j = 0;j < bi.weights.size();j++) - { - bi.weights[j].vertex = nif->getUShort(); - bi.weights[j].weight = nif->getFloat(); - } - } - } + void read(NIFStream *nif); }; struct NiMorphData : public Record @@ -326,19 +169,7 @@ struct NiMorphData : public Record }; std::vector mMorphs; - void read(NIFStream *nif) - { - int morphCount = nif->getInt(); - int vertCount = nif->getInt(); - /*relative targets?*/nif->getChar(); - - mMorphs.resize(morphCount); - for(int i = 0;i < morphCount;i++) - { - mMorphs[i].mData.read(nif, true); - nif->getVector3s(mMorphs[i].mVertices, vertCount); - } - } + void read(NIFStream *nif); }; @@ -353,20 +184,7 @@ struct NiKeyframeData : public Record Vector3KeyMap mTranslations; FloatKeyMap mScales; - void read(NIFStream *nif) - { - mRotations.read(nif); - if(mRotations.mInterpolationType == mRotations.sXYZInterpolation) - { - //Chomp unused float - nif->getFloat(); - mXRotations.read(nif, true); - mYRotations.read(nif, true); - mZRotations.read(nif, true); - } - mTranslations.read(nif); - mScales.read(nif); - } + void read(NIFStream *nif); }; } // Namespace diff --git a/components/nif/effect.hpp b/components/nif/effect.hpp index 679557e25..fae1cd7f5 100644 --- a/components/nif/effect.hpp +++ b/components/nif/effect.hpp @@ -42,63 +42,19 @@ struct NiLight : Effect osg::Vec3f diffuse; osg::Vec3f specular; - void read(NIFStream *nif) - { - dimmer = nif->getFloat(); - ambient = nif->getVector3(); - diffuse = nif->getVector3(); - specular = nif->getVector3(); - } + void read(NIFStream *nif); }; SLight light; - void read(NIFStream *nif) - { - Effect::read(nif); - - nif->getInt(); // 1 - nif->getInt(); // 1? - light.read(nif); - } + void read(NIFStream *nif); }; struct NiTextureEffect : Effect { NiSourceTexturePtr texture; - void read(NIFStream *nif) - { - Effect::read(nif); - - int tmp = nif->getInt(); - if(tmp) nif->getInt(); // always 1? - - /* - 3 x Vector4 = [1,0,0,0] - int = 2 - int = 0 or 3 - int = 2 - int = 2 - */ - nif->skip(16*4); - - texture.read(nif); - - /* - byte = 0 - vector4 = [1,0,0,0] - short = 0 - short = -75 - short = 0 - */ - nif->skip(23); - } - - void post(NIFFile *nif) - { - Effect::post(nif); - texture.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; } // Namespace diff --git a/components/nif/extra.hpp b/components/nif/extra.hpp index 2913c62b0..1e5a8616d 100644 --- a/components/nif/extra.hpp +++ b/components/nif/extra.hpp @@ -32,17 +32,7 @@ namespace Nif class NiVertWeightsExtraData : public Extra { public: - void read(NIFStream *nif) - { - Extra::read(nif); - - // We should have s*4+2 == i, for some reason. Might simply be the - // size of the rest of the record, unhelpful as that may be. - /*int i =*/ nif->getInt(); - int s = nif->getUShort(); - - nif->skip(s * sizeof(float)); // vertex weights I guess - } + void read(NIFStream *nif); }; class NiTextKeyExtraData : public Extra @@ -55,20 +45,7 @@ public: }; std::vector list; - void read(NIFStream *nif) - { - Extra::read(nif); - - nif->getInt(); // 0 - - int keynum = nif->getInt(); - list.resize(keynum); - for(int i=0; igetFloat(); - list[i].text = nif->getString(); - } - } + void read(NIFStream *nif); }; class NiStringExtraData : public Extra @@ -80,13 +57,7 @@ public: */ std::string string; - void read(NIFStream *nif) - { - Extra::read(nif); - - nif->getInt(); // size of string + 4. Really useful... - string = nif->getString(); - } + void read(NIFStream *nif); }; } // Namespace diff --git a/components/nif/nifkey.hpp b/components/nif/nifkey.hpp index b8b01513b..549ea3eb3 100644 --- a/components/nif/nifkey.hpp +++ b/components/nif/nifkey.hpp @@ -24,6 +24,10 @@ struct KeyT { float mContinuity; // Only for TBC interpolation */ }; +typedef KeyT FloatKey; +typedef KeyT Vector3Key; +typedef KeyT Vector4Key; +typedef KeyT QuaternionKey; template struct KeyMapT { diff --git a/components/nif/property.hpp b/components/nif/property.hpp index 610f5427a..b06044e9f 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -26,9 +26,6 @@ #include "base.hpp" -#include "controlled.hpp" -#include "data.hpp" - namespace Nif { @@ -38,11 +35,7 @@ public: // The meaning of these depends on the actual property type. int flags; - void read(NIFStream *nif) - { - Named::read(nif); - flags = nif->getUShort(); - } + void read(NIFStream *nif); }; class NiTexturingProperty : public Property @@ -70,26 +63,8 @@ public: int clamp, uvSet, filter; short unknown2; - void read(NIFStream *nif) - { - inUse = !!nif->getInt(); - if(!inUse) return; - - texture.read(nif); - clamp = nif->getInt(); - filter = nif->getInt(); - uvSet = nif->getInt(); - - // I have no idea, but I think these are actually two - // PS2-specific shorts (ps2L and ps2K), followed by an unknown - // short. - nif->skip(6); - } - - void post(NIFFile *nif) - { - texture.post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; /* Apply mode: @@ -120,42 +95,14 @@ public: GlossTexture = 3, GlowTexture = 4, BumpTexture = 5, - DecalTexture = 6 + DecalTexture = 6, + NumTextures = 7 // Sentry value }; Texture textures[7]; - void read(NIFStream *nif) - { - Property::read(nif); - apply = nif->getInt(); - - // Unknown, always 7. Probably the number of textures to read - // below - nif->getInt(); - - textures[0].read(nif); // Base - textures[1].read(nif); // Dark - textures[2].read(nif); // Detail - textures[3].read(nif); // Gloss (never present) - textures[4].read(nif); // Glow - textures[5].read(nif); // Bump map - if(textures[5].inUse) - { - // Ignore these at the moment - /*float lumaScale =*/ nif->getFloat(); - /*float lumaOffset =*/ nif->getFloat(); - /*const Vector4 *lumaMatrix =*/ nif->getVector4(); - } - textures[6].read(nif); // Decal - } - - void post(NIFFile *nif) - { - Property::post(nif); - for(int i = 0;i < 7;i++) - textures[i].post(nif); - } + void read(NIFStream *nif); + void post(NIFFile *nif); }; class NiFogProperty : public Property @@ -164,14 +111,7 @@ public: float mFogDepth; osg::Vec3f mColour; - - void read(NIFStream *nif) - { - Property::read(nif); - - mFogDepth = nif->getFloat(); - mColour = nif->getVector3(); - } + void read(NIFStream *nif); }; // These contain no other data than the 'flags' field in Property @@ -200,15 +140,7 @@ struct S_MaterialProperty osg::Vec3f ambient, diffuse, specular, emissive; float glossiness, alpha; - void read(NIFStream *nif) - { - ambient = nif->getVector3(); - diffuse = nif->getVector3(); - specular = nif->getVector3(); - emissive = nif->getVector3(); - glossiness = nif->getFloat(); - alpha = nif->getFloat(); - } + void read(NIFStream *nif); }; struct S_VertexColorProperty @@ -224,11 +156,7 @@ struct S_VertexColorProperty */ int vertmode, lightmode; - void read(NIFStream *nif) - { - vertmode = nif->getInt(); - lightmode = nif->getInt(); - } + void read(NIFStream *nif); }; struct S_AlphaProperty @@ -273,10 +201,7 @@ struct S_AlphaProperty // Tested against when certain flags are set (see above.) unsigned char threshold; - void read(NIFStream *nif) - { - threshold = nif->getChar(); - } + void read(NIFStream *nif); }; /* @@ -322,17 +247,7 @@ struct S_StencilProperty */ int drawMode; - void read(NIFStream *nif) - { - enabled = nif->getChar(); - compareFunc = nif->getInt(); - stencilRef = nif->getUInt(); - stencilMask = nif->getUInt(); - failAction = nif->getInt(); - zFailAction = nif->getInt(); - zPassAction = nif->getInt(); - drawMode = nif->getInt(); - } + void read(NIFStream *nif); }; class NiAlphaProperty : public StructPropT { }; diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 07d7540f8..1022802cc 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -110,12 +110,6 @@ struct Record virtual void post(NIFFile *nif) {} virtual ~Record() {} - - /* - Use these later if you want custom allocation of all NIF objects - static void* operator new(size_t size); - static void operator delete(void *p); - */ }; } // Namespace