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