Merge branch 'nifstuffagain' into 'master'

niffile.cpp cleanup

See merge request OpenMW/openmw!313
pull/593/head
psi29a 4 years ago
commit 2d24e87bcc

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

Loading…
Cancel
Save