niffile.cpp cleanup

pull/3011/head
Alexei Dobrohotov 4 years ago
parent 4faaa86449
commit 4e22c2687f

@ -16,105 +16,96 @@ NIFFile::NIFFile(Files::IStreamPtr stream, const std::string &name)
NIFFile::~NIFFile()
{
for (std::vector<Record*>::iterator it = records.begin() ; it != records.end(); ++it)
{
delete *it;
}
for (Record* record : records)
delete record;
}
template <typename NodeType> static Record* construct() { return new NodeType; }
struct RecordFactoryEntry {
typedef Record* (*create_t) ();
using create_t = Record* (*)();
create_t mCreate;
RecordType mType;
};
///Helper function for adding records to the factory map
static std::pair<std::string,RecordFactoryEntry> makeEntry(std::string recName, Record* (*create_t) (), RecordType type)
{
RecordFactoryEntry anEntry = {create_t,type};
return std::make_pair(recName, anEntry);
}
///These are all the record types we know how to read.
static std::map<std::string,RecordFactoryEntry> makeFactory()
{
std::map<std::string,RecordFactoryEntry> newFactory;
newFactory.insert(makeEntry("NiNode", &construct <NiNode> , RC_NiNode ));
newFactory.insert(makeEntry("NiSwitchNode", &construct <NiSwitchNode> , RC_NiSwitchNode ));
newFactory.insert(makeEntry("NiLODNode", &construct <NiLODNode> , RC_NiLODNode ));
newFactory.insert(makeEntry("AvoidNode", &construct <NiNode> , RC_AvoidNode ));
newFactory.insert(makeEntry("NiCollisionSwitch", &construct <NiNode> , RC_NiCollisionSwitch ));
newFactory.insert(makeEntry("NiBSParticleNode", &construct <NiNode> , RC_NiBSParticleNode ));
newFactory.insert(makeEntry("NiBSAnimationNode", &construct <NiNode> , RC_NiBSAnimationNode ));
newFactory.insert(makeEntry("NiBillboardNode", &construct <NiNode> , RC_NiBillboardNode ));
newFactory.insert(makeEntry("NiTriShape", &construct <NiTriShape> , RC_NiTriShape ));
newFactory.insert(makeEntry("NiTriStrips", &construct <NiTriStrips> , RC_NiTriStrips ));
newFactory.insert(makeEntry("NiLines", &construct <NiLines> , RC_NiLines ));
newFactory.insert(makeEntry("NiRotatingParticles", &construct <NiRotatingParticles> , RC_NiRotatingParticles ));
newFactory.insert(makeEntry("NiAutoNormalParticles", &construct <NiAutoNormalParticles> , RC_NiAutoNormalParticles ));
newFactory.insert(makeEntry("NiCamera", &construct <NiCamera> , RC_NiCamera ));
newFactory.insert(makeEntry("RootCollisionNode", &construct <NiNode> , RC_RootCollisionNode ));
newFactory.insert(makeEntry("NiTexturingProperty", &construct <NiTexturingProperty> , RC_NiTexturingProperty ));
newFactory.insert(makeEntry("NiFogProperty", &construct <NiFogProperty> , RC_NiFogProperty ));
newFactory.insert(makeEntry("NiMaterialProperty", &construct <NiMaterialProperty> , RC_NiMaterialProperty ));
newFactory.insert(makeEntry("NiZBufferProperty", &construct <NiZBufferProperty> , RC_NiZBufferProperty ));
newFactory.insert(makeEntry("NiAlphaProperty", &construct <NiAlphaProperty> , RC_NiAlphaProperty ));
newFactory.insert(makeEntry("NiVertexColorProperty", &construct <NiVertexColorProperty> , RC_NiVertexColorProperty ));
newFactory.insert(makeEntry("NiShadeProperty", &construct <NiShadeProperty> , RC_NiShadeProperty ));
newFactory.insert(makeEntry("NiDitherProperty", &construct <NiDitherProperty> , RC_NiDitherProperty ));
newFactory.insert(makeEntry("NiWireframeProperty", &construct <NiWireframeProperty> , RC_NiWireframeProperty ));
newFactory.insert(makeEntry("NiSpecularProperty", &construct <NiSpecularProperty> , RC_NiSpecularProperty ));
newFactory.insert(makeEntry("NiStencilProperty", &construct <NiStencilProperty> , RC_NiStencilProperty ));
newFactory.insert(makeEntry("NiVisController", &construct <NiVisController> , RC_NiVisController ));
newFactory.insert(makeEntry("NiGeomMorpherController", &construct <NiGeomMorpherController> , RC_NiGeomMorpherController ));
newFactory.insert(makeEntry("NiKeyframeController", &construct <NiKeyframeController> , RC_NiKeyframeController ));
newFactory.insert(makeEntry("NiAlphaController", &construct <NiAlphaController> , RC_NiAlphaController ));
newFactory.insert(makeEntry("NiRollController", &construct <NiRollController> , RC_NiRollController ));
newFactory.insert(makeEntry("NiUVController", &construct <NiUVController> , RC_NiUVController ));
newFactory.insert(makeEntry("NiPathController", &construct <NiPathController> , RC_NiPathController ));
newFactory.insert(makeEntry("NiMaterialColorController", &construct <NiMaterialColorController> , RC_NiMaterialColorController ));
newFactory.insert(makeEntry("NiBSPArrayController", &construct <NiBSPArrayController> , RC_NiBSPArrayController ));
newFactory.insert(makeEntry("NiParticleSystemController", &construct <NiParticleSystemController> , RC_NiParticleSystemController ));
newFactory.insert(makeEntry("NiFlipController", &construct <NiFlipController> , RC_NiFlipController ));
newFactory.insert(makeEntry("NiAmbientLight", &construct <NiLight> , RC_NiLight ));
newFactory.insert(makeEntry("NiDirectionalLight", &construct <NiLight> , RC_NiLight ));
newFactory.insert(makeEntry("NiPointLight", &construct <NiPointLight> , RC_NiLight ));
newFactory.insert(makeEntry("NiSpotLight", &construct <NiSpotLight> , RC_NiLight ));
newFactory.insert(makeEntry("NiTextureEffect", &construct <NiTextureEffect> , RC_NiTextureEffect ));
newFactory.insert(makeEntry("NiVertWeightsExtraData", &construct <NiVertWeightsExtraData> , RC_NiVertWeightsExtraData ));
newFactory.insert(makeEntry("NiTextKeyExtraData", &construct <NiTextKeyExtraData> , RC_NiTextKeyExtraData ));
newFactory.insert(makeEntry("NiStringExtraData", &construct <NiStringExtraData> , RC_NiStringExtraData ));
newFactory.insert(makeEntry("NiGravity", &construct <NiGravity> , RC_NiGravity ));
newFactory.insert(makeEntry("NiPlanarCollider", &construct <NiPlanarCollider> , RC_NiPlanarCollider ));
newFactory.insert(makeEntry("NiSphericalCollider", &construct <NiSphericalCollider> , RC_NiSphericalCollider ));
newFactory.insert(makeEntry("NiParticleGrowFade", &construct <NiParticleGrowFade> , RC_NiParticleGrowFade ));
newFactory.insert(makeEntry("NiParticleColorModifier", &construct <NiParticleColorModifier> , RC_NiParticleColorModifier ));
newFactory.insert(makeEntry("NiParticleRotation", &construct <NiParticleRotation> , RC_NiParticleRotation ));
newFactory.insert(makeEntry("NiFloatData", &construct <NiFloatData> , RC_NiFloatData ));
newFactory.insert(makeEntry("NiTriShapeData", &construct <NiTriShapeData> , RC_NiTriShapeData ));
newFactory.insert(makeEntry("NiTriStripsData", &construct <NiTriStripsData> , RC_NiTriStripsData ));
newFactory.insert(makeEntry("NiLinesData", &construct <NiLinesData> , RC_NiLinesData ));
newFactory.insert(makeEntry("NiVisData", &construct <NiVisData> , RC_NiVisData ));
newFactory.insert(makeEntry("NiColorData", &construct <NiColorData> , RC_NiColorData ));
newFactory.insert(makeEntry("NiPixelData", &construct <NiPixelData> , RC_NiPixelData ));
newFactory.insert(makeEntry("NiMorphData", &construct <NiMorphData> , RC_NiMorphData ));
newFactory.insert(makeEntry("NiKeyframeData", &construct <NiKeyframeData> , RC_NiKeyframeData ));
newFactory.insert(makeEntry("NiSkinData", &construct <NiSkinData> , RC_NiSkinData ));
newFactory.insert(makeEntry("NiUVData", &construct <NiUVData> , RC_NiUVData ));
newFactory.insert(makeEntry("NiPosData", &construct <NiPosData> , RC_NiPosData ));
newFactory.insert(makeEntry("NiRotatingParticlesData", &construct <NiRotatingParticlesData> , RC_NiRotatingParticlesData ));
newFactory.insert(makeEntry("NiAutoNormalParticlesData", &construct <NiAutoNormalParticlesData> , RC_NiAutoNormalParticlesData ));
newFactory.insert(makeEntry("NiSequenceStreamHelper", &construct <NiSequenceStreamHelper> , RC_NiSequenceStreamHelper ));
newFactory.insert(makeEntry("NiSourceTexture", &construct <NiSourceTexture> , RC_NiSourceTexture ));
newFactory.insert(makeEntry("NiSkinInstance", &construct <NiSkinInstance> , RC_NiSkinInstance ));
newFactory.insert(makeEntry("NiLookAtController", &construct <NiLookAtController> , RC_NiLookAtController ));
newFactory.insert(makeEntry("NiPalette", &construct <NiPalette> , RC_NiPalette ));
return newFactory;
std::map<std::string,RecordFactoryEntry> factory;
factory["NiNode"] = {&construct <NiNode> , RC_NiNode };
factory["NiSwitchNode"] = {&construct <NiSwitchNode> , RC_NiSwitchNode };
factory["NiLODNode"] = {&construct <NiLODNode> , RC_NiLODNode };
factory["AvoidNode"] = {&construct <NiNode> , RC_AvoidNode };
factory["NiCollisionSwitch"] = {&construct <NiNode> , RC_NiCollisionSwitch };
factory["NiBSParticleNode"] = {&construct <NiNode> , RC_NiBSParticleNode };
factory["NiBSAnimationNode"] = {&construct <NiNode> , RC_NiBSAnimationNode };
factory["NiBillboardNode"] = {&construct <NiNode> , RC_NiBillboardNode };
factory["NiTriShape"] = {&construct <NiTriShape> , RC_NiTriShape };
factory["NiTriStrips"] = {&construct <NiTriStrips> , RC_NiTriStrips };
factory["NiLines"] = {&construct <NiLines> , RC_NiLines };
factory["NiRotatingParticles"] = {&construct <NiRotatingParticles> , RC_NiRotatingParticles };
factory["NiAutoNormalParticles"] = {&construct <NiAutoNormalParticles> , RC_NiAutoNormalParticles };
factory["NiCamera"] = {&construct <NiCamera> , RC_NiCamera };
factory["RootCollisionNode"] = {&construct <NiNode> , RC_RootCollisionNode };
factory["NiTexturingProperty"] = {&construct <NiTexturingProperty> , RC_NiTexturingProperty };
factory["NiFogProperty"] = {&construct <NiFogProperty> , RC_NiFogProperty };
factory["NiMaterialProperty"] = {&construct <NiMaterialProperty> , RC_NiMaterialProperty };
factory["NiZBufferProperty"] = {&construct <NiZBufferProperty> , RC_NiZBufferProperty };
factory["NiAlphaProperty"] = {&construct <NiAlphaProperty> , RC_NiAlphaProperty };
factory["NiVertexColorProperty"] = {&construct <NiVertexColorProperty> , RC_NiVertexColorProperty };
factory["NiShadeProperty"] = {&construct <NiShadeProperty> , RC_NiShadeProperty };
factory["NiDitherProperty"] = {&construct <NiDitherProperty> , RC_NiDitherProperty };
factory["NiWireframeProperty"] = {&construct <NiWireframeProperty> , RC_NiWireframeProperty };
factory["NiSpecularProperty"] = {&construct <NiSpecularProperty> , RC_NiSpecularProperty };
factory["NiStencilProperty"] = {&construct <NiStencilProperty> , RC_NiStencilProperty };
factory["NiVisController"] = {&construct <NiVisController> , RC_NiVisController };
factory["NiGeomMorpherController"] = {&construct <NiGeomMorpherController> , RC_NiGeomMorpherController };
factory["NiKeyframeController"] = {&construct <NiKeyframeController> , RC_NiKeyframeController };
factory["NiAlphaController"] = {&construct <NiAlphaController> , RC_NiAlphaController };
factory["NiRollController"] = {&construct <NiRollController> , RC_NiRollController };
factory["NiUVController"] = {&construct <NiUVController> , RC_NiUVController };
factory["NiPathController"] = {&construct <NiPathController> , RC_NiPathController };
factory["NiMaterialColorController"] = {&construct <NiMaterialColorController> , RC_NiMaterialColorController };
factory["NiBSPArrayController"] = {&construct <NiBSPArrayController> , RC_NiBSPArrayController };
factory["NiParticleSystemController"] = {&construct <NiParticleSystemController> , RC_NiParticleSystemController };
factory["NiFlipController"] = {&construct <NiFlipController> , RC_NiFlipController };
factory["NiAmbientLight"] = {&construct <NiLight> , RC_NiLight };
factory["NiDirectionalLight"] = {&construct <NiLight> , RC_NiLight };
factory["NiPointLight"] = {&construct <NiPointLight> , RC_NiLight };
factory["NiSpotLight"] = {&construct <NiSpotLight> , RC_NiLight };
factory["NiTextureEffect"] = {&construct <NiTextureEffect> , RC_NiTextureEffect };
factory["NiVertWeightsExtraData"] = {&construct <NiVertWeightsExtraData> , RC_NiVertWeightsExtraData };
factory["NiTextKeyExtraData"] = {&construct <NiTextKeyExtraData> , RC_NiTextKeyExtraData };
factory["NiStringExtraData"] = {&construct <NiStringExtraData> , RC_NiStringExtraData };
factory["NiGravity"] = {&construct <NiGravity> , RC_NiGravity };
factory["NiPlanarCollider"] = {&construct <NiPlanarCollider> , RC_NiPlanarCollider };
factory["NiSphericalCollider"] = {&construct <NiSphericalCollider> , RC_NiSphericalCollider };
factory["NiParticleGrowFade"] = {&construct <NiParticleGrowFade> , RC_NiParticleGrowFade };
factory["NiParticleColorModifier"] = {&construct <NiParticleColorModifier> , RC_NiParticleColorModifier };
factory["NiParticleRotation"] = {&construct <NiParticleRotation> , RC_NiParticleRotation };
factory["NiFloatData"] = {&construct <NiFloatData> , RC_NiFloatData };
factory["NiTriShapeData"] = {&construct <NiTriShapeData> , RC_NiTriShapeData };
factory["NiTriStripsData"] = {&construct <NiTriStripsData> , RC_NiTriStripsData };
factory["NiLinesData"] = {&construct <NiLinesData> , RC_NiLinesData };
factory["NiVisData"] = {&construct <NiVisData> , RC_NiVisData };
factory["NiColorData"] = {&construct <NiColorData> , RC_NiColorData };
factory["NiPixelData"] = {&construct <NiPixelData> , RC_NiPixelData };
factory["NiMorphData"] = {&construct <NiMorphData> , RC_NiMorphData };
factory["NiKeyframeData"] = {&construct <NiKeyframeData> , RC_NiKeyframeData };
factory["NiSkinData"] = {&construct <NiSkinData> , RC_NiSkinData };
factory["NiUVData"] = {&construct <NiUVData> , RC_NiUVData };
factory["NiPosData"] = {&construct <NiPosData> , RC_NiPosData };
factory["NiRotatingParticlesData"] = {&construct <NiRotatingParticlesData> , RC_NiRotatingParticlesData };
factory["NiAutoNormalParticlesData"] = {&construct <NiAutoNormalParticlesData> , RC_NiAutoNormalParticlesData };
factory["NiSequenceStreamHelper"] = {&construct <NiSequenceStreamHelper> , RC_NiSequenceStreamHelper };
factory["NiSourceTexture"] = {&construct <NiSourceTexture> , RC_NiSourceTexture };
factory["NiSkinInstance"] = {&construct <NiSkinInstance> , RC_NiSkinInstance };
factory["NiLookAtController"] = {&construct <NiLookAtController> , RC_NiLookAtController };
factory["NiPalette"] = {&construct <NiPalette> , RC_NiPalette };
return factory;
}
@ -149,7 +140,7 @@ void NIFFile::parse(Files::IStreamPtr stream)
if(ver != NIFStream::generateVersion(4,0,0,0) && ver != VER_MW)
fail("Unsupported NIF version: " + printVersion(ver));
// Number of records
size_t recNum = nif.getInt();
size_t recNum = nif.getUInt();
records.resize(recNum);
for(size_t i = 0;i < recNum;i++)
@ -201,8 +192,8 @@ void NIFFile::parse(Files::IStreamPtr stream)
}
// Once parsing is done, do post-processing.
for(size_t i=0; i<recNum; i++)
records[i]->post(this);
for (Record* record : records)
record->post(this);
}
void NIFFile::setUseSkinning(bool skinning)

Loading…
Cancel
Save