From 32caab663f5e0ed00781ec949465407e25d0deaa Mon Sep 17 00:00:00 2001 From: capostrophic Date: Tue, 31 Dec 2019 13:38:57 +0300 Subject: [PATCH] Enumerate interpolation types properly --- components/nif/data.cpp | 2 +- components/nif/nifkey.hpp | 39 ++++++++++++++++---------------- components/nifosg/controller.hpp | 4 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index cde8e58765..828f5c368a 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -265,7 +265,7 @@ void NiKeyframeData::read(NIFStream *nif) { mRotations = std::make_shared(); mRotations->read(nif); - if(mRotations->mInterpolationType == Vector3KeyMap::XYZ) + if(mRotations->mInterpolationType == InterpolationType_XYZ) { //Chomp unused float nif->getFloat(); diff --git a/components/nif/nifkey.hpp b/components/nif/nifkey.hpp index 3e03b4b1f9..333d8a7cfa 100644 --- a/components/nif/nifkey.hpp +++ b/components/nif/nifkey.hpp @@ -13,6 +13,16 @@ namespace Nif { +enum InterpolationType +{ + InterpolationType_Unknown = 0, + InterpolationType_Linear = 1, + InterpolationType_Quadratic = 2, + InterpolationType_TBC = 3, + InterpolationType_XYZ = 4, + InterpolationType_Constant = 5 +}; + template struct KeyT { T mValue; @@ -38,17 +48,7 @@ struct KeyMapT { using ValueType = T; using KeyType = KeyT; - enum InterpolationType - { - Unknown = 0, - Linear = 1, - Quadratic = 2, - TBC = 3, - XYZ = 4, - Constant = 5 - }; - - unsigned int mInterpolationType = Linear; + unsigned int mInterpolationType = InterpolationType_Linear; MapType mKeys; //Read in a KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html) @@ -56,7 +56,7 @@ struct KeyMapT { { assert(nif); - mInterpolationType = Unknown; + mInterpolationType = InterpolationType_Unknown; size_t count = nif->getUInt(); if(count == 0 && !force) @@ -69,7 +69,8 @@ struct KeyMapT { KeyT key; NIFStream &nifReference = *nif; - if (mInterpolationType == Linear || mInterpolationType == Constant) + if (mInterpolationType == InterpolationType_Linear + || mInterpolationType == InterpolationType_Constant) { for(size_t i = 0;i < count;i++) { @@ -78,7 +79,7 @@ struct KeyMapT { mKeys[time] = key; } } - else if (mInterpolationType == Quadratic) + else if (mInterpolationType == InterpolationType_Quadratic) { for(size_t i = 0;i < count;i++) { @@ -87,7 +88,7 @@ struct KeyMapT { mKeys[time] = key; } } - else if (mInterpolationType == TBC) + else if (mInterpolationType == InterpolationType_TBC) { for(size_t i = 0;i < count;i++) { @@ -97,11 +98,11 @@ struct KeyMapT { } } //XYZ keys aren't actually read here. - //data.hpp sees that the last type read was sXYZInterpolation and: + //data.hpp sees that the last type read was InterpolationType_XYZ and: // Eats a floating point number, then // Re-runs the read function 3 more times. - // When it does that it's reading in a bunch of sLinearInterpolation keys, not sXYZInterpolation. - else if(mInterpolationType == XYZ) + // When it does that it's reading in a bunch of InterpolationType_Linear keys, not InterpolationType_XYZ. + else if(mInterpolationType == InterpolationType_XYZ) { //Don't try to read XYZ keys into the wrong part if ( count != 1 ) @@ -112,7 +113,7 @@ struct KeyMapT { nif->file->fail(error.str()); } } - else if (mInterpolationType == Unknown) + else if (mInterpolationType == InterpolationType_Unknown) { if (count != 0) nif->file->fail("Interpolation type 0 doesn't work with keys"); diff --git a/components/nifosg/controller.hpp b/components/nifosg/controller.hpp index 85da77eda8..c9bda2e627 100644 --- a/components/nifosg/controller.hpp +++ b/components/nifosg/controller.hpp @@ -111,7 +111,7 @@ namespace NifOsg { switch (type) { - case 5: + case Nif::InterpolationType_Constant: return fraction > 0.5f ? b.mValue : a.mValue; default: return a.mValue + ((b.mValue - a.mValue) * fraction); @@ -121,7 +121,7 @@ namespace NifOsg { switch (type) { - case 5: + case Nif::InterpolationType_Constant: return fraction > 0.5f ? b.mValue : a.mValue; default: {