mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-10 06:39:49 +00:00
Modernize NiRotatingParticlesData and NiVisData
This commit is contained in:
parent
eba0ab444b
commit
523e7e8228
@ -194,7 +194,12 @@ namespace 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());
|
||||
}
|
||||
|
||||
@ -281,12 +286,16 @@ namespace Nif
|
||||
|
||||
void NiVisData::read(NIFStream* nif)
|
||||
{
|
||||
int count = nif->getInt();
|
||||
mVis.resize(count);
|
||||
for (size_t i = 0; i < mVis.size(); i++)
|
||||
mKeys = std::make_shared<std::map<float, bool>>();
|
||||
uint32_t numKeys;
|
||||
nif->read(numKeys);
|
||||
for (size_t i = 0; i < numKeys; i++)
|
||||
{
|
||||
mVis[i].time = nif->getFloat();
|
||||
mVis[i].isSet = (nif->getChar() != 0);
|
||||
float time;
|
||||
char value;
|
||||
nif->read(time);
|
||||
nif->read(value);
|
||||
(*mKeys)[time] = (value != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,12 +161,8 @@ namespace Nif
|
||||
|
||||
struct NiVisData : public Record
|
||||
{
|
||||
struct VisData
|
||||
{
|
||||
float time;
|
||||
bool isSet;
|
||||
};
|
||||
std::vector<VisData> mVis;
|
||||
// TODO: investigate possible use of ByteKeyMap
|
||||
std::shared_ptr<std::map<float, bool>> mKeys;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
@ -319,7 +319,7 @@ namespace NifOsg
|
||||
= ByteInterpolator(static_cast<const Nif::NiBoolInterpolator*>(ctrl->mInterpolator.getPtr()));
|
||||
}
|
||||
else if (!ctrl->mData.empty())
|
||||
mData = ctrl->mData->mVis;
|
||||
mData = ctrl->mData->mKeys;
|
||||
}
|
||||
|
||||
VisController::VisController() {}
|
||||
@ -338,15 +338,13 @@ namespace NifOsg
|
||||
if (!mInterpolator.empty())
|
||||
return mInterpolator.interpKey(time);
|
||||
|
||||
if (mData.size() == 0)
|
||||
if (mData->empty())
|
||||
return true;
|
||||
|
||||
for (size_t i = 1; i < mData.size(); i++)
|
||||
{
|
||||
if (mData[i].time > time)
|
||||
return mData[i - 1].isSet;
|
||||
}
|
||||
return mData.back().isSet;
|
||||
auto iter = mData->upper_bound(time);
|
||||
if (iter != mData->begin())
|
||||
--iter;
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
void VisController::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
|
@ -1,19 +1,18 @@
|
||||
#ifndef COMPONENTS_NIFOSG_CONTROLLER_H
|
||||
#define COMPONENTS_NIFOSG_CONTROLLER_H
|
||||
|
||||
#include <components/nif/controller.hpp>
|
||||
#include <components/nif/data.hpp>
|
||||
#include <components/nif/nifkey.hpp>
|
||||
|
||||
#include <components/sceneutil/keyframe.hpp>
|
||||
#include <components/sceneutil/nodecallback.hpp>
|
||||
#include <components/sceneutil/statesetupdater.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
|
||||
#include <osg/Texture2D>
|
||||
|
||||
#include <components/nif/controller.hpp>
|
||||
#include <components/nif/data.hpp>
|
||||
#include <components/nif/nifkey.hpp>
|
||||
#include <components/sceneutil/keyframe.hpp>
|
||||
#include <components/sceneutil/nodecallback.hpp>
|
||||
#include <components/sceneutil/statesetupdater.hpp>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Material;
|
||||
@ -283,7 +282,7 @@ namespace NifOsg
|
||||
class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller
|
||||
{
|
||||
private:
|
||||
std::vector<Nif::NiVisData::VisData> mData;
|
||||
std::shared_ptr<std::map<float, bool>> mData;
|
||||
ByteInterpolator mInterpolator;
|
||||
unsigned int mMask{ 0u };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user