mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 09:23:53 +00:00
Use vector for EffectManager effects
This commit is contained in:
parent
ee89eccb06
commit
4d74f8137c
2 changed files with 22 additions and 21 deletions
|
@ -11,6 +11,8 @@
|
|||
#include "vismask.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
|
@ -43,6 +45,8 @@ void EffectManager::addEffect(const std::string &model, const std::string& textu
|
|||
trans->setScale(osg::Vec3f(scale, scale, scale));
|
||||
trans->addChild(node);
|
||||
|
||||
effect.mTransform = trans;
|
||||
|
||||
SceneUtil::AssignControllerSourcesVisitor assignVisitor(effect.mAnimTime);
|
||||
node->accept(assignVisitor);
|
||||
|
||||
|
@ -53,30 +57,29 @@ void EffectManager::addEffect(const std::string &model, const std::string& textu
|
|||
|
||||
mParentNode->addChild(trans);
|
||||
|
||||
mEffects[trans] = effect;
|
||||
mEffects.push_back(std::move(effect));
|
||||
}
|
||||
|
||||
void EffectManager::update(float dt)
|
||||
{
|
||||
for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); )
|
||||
{
|
||||
it->second.mAnimTime->addTime(dt);
|
||||
|
||||
if (it->second.mAnimTime->getTime() >= it->second.mMaxControllerLength)
|
||||
{
|
||||
mParentNode->removeChild(it->first);
|
||||
mEffects.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
mEffects.erase(
|
||||
std::remove_if(
|
||||
mEffects.begin(),
|
||||
mEffects.end(),
|
||||
[dt](Effect& effect)
|
||||
{
|
||||
effect.mAnimTime->addTime(dt);
|
||||
return effect.mAnimTime->getTime() >= effect.mMaxControllerLength;
|
||||
}),
|
||||
mEffects.end()
|
||||
);
|
||||
}
|
||||
|
||||
void EffectManager::clear()
|
||||
{
|
||||
for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
|
||||
for(const auto& effect : mEffects)
|
||||
{
|
||||
mParentNode->removeChild(it->first);
|
||||
mParentNode->removeChild(effect.mTransform);
|
||||
}
|
||||
mEffects.clear();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef OPENMW_MWRENDER_EFFECTMANAGER_H
|
||||
#define OPENMW_MWRENDER_EFFECTMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
|
@ -29,6 +29,7 @@ namespace MWRender
|
|||
{
|
||||
public:
|
||||
EffectManager(osg::ref_ptr<osg::Group> parent, Resource::ResourceSystem* resourceSystem);
|
||||
EffectManager(const EffectManager&) = delete;
|
||||
~EffectManager();
|
||||
|
||||
/// Add an effect. When it's finished playing, it will be removed automatically.
|
||||
|
@ -44,16 +45,13 @@ namespace MWRender
|
|||
{
|
||||
float mMaxControllerLength;
|
||||
std::shared_ptr<EffectAnimationTime> mAnimTime;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mTransform;
|
||||
};
|
||||
|
||||
typedef std::map<osg::ref_ptr<osg::PositionAttitudeTransform>, Effect> EffectMap;
|
||||
EffectMap mEffects;
|
||||
std::vector<Effect> mEffects;
|
||||
|
||||
osg::ref_ptr<osg::Group> mParentNode;
|
||||
Resource::ResourceSystem* mResourceSystem;
|
||||
|
||||
EffectManager(const EffectManager&);
|
||||
void operator=(const EffectManager&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue