Modernize NiRotatingParticlesData and NiVisData

macos_ci_fix
Alexei Kotov 1 year ago
parent eba0ab444b
commit 523e7e8228

@ -194,7 +194,12 @@ namespace Nif
{ {
NiParticlesData::read(nif); NiParticlesData::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0) && nif->getBoolean()) if (nif->getVersion() > NIFStream::generateVersion(4, 2, 2, 0))
return;
bool hasRotations;
nif->read(hasRotations);
if (hasRotations)
nif->readVector(rotations, vertices.size()); nif->readVector(rotations, vertices.size());
} }
@ -281,12 +286,16 @@ namespace Nif
void NiVisData::read(NIFStream* nif) void NiVisData::read(NIFStream* nif)
{ {
int count = nif->getInt(); mKeys = std::make_shared<std::map<float, bool>>();
mVis.resize(count); uint32_t numKeys;
for (size_t i = 0; i < mVis.size(); i++) nif->read(numKeys);
for (size_t i = 0; i < numKeys; i++)
{ {
mVis[i].time = nif->getFloat(); float time;
mVis[i].isSet = (nif->getChar() != 0); char value;
nif->read(time);
nif->read(value);
(*mKeys)[time] = (value != 0);
} }
} }

@ -161,12 +161,8 @@ namespace Nif
struct NiVisData : public Record struct NiVisData : public Record
{ {
struct VisData // TODO: investigate possible use of ByteKeyMap
{ std::shared_ptr<std::map<float, bool>> mKeys;
float time;
bool isSet;
};
std::vector<VisData> mVis;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };

@ -319,7 +319,7 @@ namespace NifOsg
= ByteInterpolator(static_cast<const Nif::NiBoolInterpolator*>(ctrl->mInterpolator.getPtr())); = ByteInterpolator(static_cast<const Nif::NiBoolInterpolator*>(ctrl->mInterpolator.getPtr()));
} }
else if (!ctrl->mData.empty()) else if (!ctrl->mData.empty())
mData = ctrl->mData->mVis; mData = ctrl->mData->mKeys;
} }
VisController::VisController() {} VisController::VisController() {}
@ -338,15 +338,13 @@ namespace NifOsg
if (!mInterpolator.empty()) if (!mInterpolator.empty())
return mInterpolator.interpKey(time); return mInterpolator.interpKey(time);
if (mData.size() == 0) if (mData->empty())
return true; return true;
for (size_t i = 1; i < mData.size(); i++) auto iter = mData->upper_bound(time);
{ if (iter != mData->begin())
if (mData[i].time > time) --iter;
return mData[i - 1].isSet; return iter->second;
}
return mData.back().isSet;
} }
void VisController::operator()(osg::Node* node, osg::NodeVisitor* nv) void VisController::operator()(osg::Node* node, osg::NodeVisitor* nv)

@ -1,19 +1,18 @@
#ifndef COMPONENTS_NIFOSG_CONTROLLER_H #ifndef COMPONENTS_NIFOSG_CONTROLLER_H
#define COMPONENTS_NIFOSG_CONTROLLER_H #define COMPONENTS_NIFOSG_CONTROLLER_H
#include <set>
#include <type_traits>
#include <osg/Texture2D>
#include <components/nif/controller.hpp> #include <components/nif/controller.hpp>
#include <components/nif/data.hpp> #include <components/nif/data.hpp>
#include <components/nif/nifkey.hpp> #include <components/nif/nifkey.hpp>
#include <components/sceneutil/keyframe.hpp> #include <components/sceneutil/keyframe.hpp>
#include <components/sceneutil/nodecallback.hpp> #include <components/sceneutil/nodecallback.hpp>
#include <components/sceneutil/statesetupdater.hpp> #include <components/sceneutil/statesetupdater.hpp>
#include <set>
#include <type_traits>
#include <osg/Texture2D>
namespace osg namespace osg
{ {
class Material; class Material;
@ -283,7 +282,7 @@ namespace NifOsg
class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller
{ {
private: private:
std::vector<Nif::NiVisData::VisData> mData; std::shared_ptr<std::map<float, bool>> mData;
ByteInterpolator mInterpolator; ByteInterpolator mInterpolator;
unsigned int mMask{ 0u }; unsigned int mMask{ 0u };

Loading…
Cancel
Save