1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:49:56 +00:00
openmw-tes3mp/apps/openmw/mwrender/effectmanager.cpp

85 lines
2.2 KiB
C++
Raw Normal View History

2014-01-17 09:52:44 +00:00
#include "effectmanager.hpp"
2015-04-19 15:55:56 +00:00
#include <osg/PositionAttitudeTransform>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/controller.hpp>
2014-01-17 09:52:44 +00:00
#include "animation.hpp"
#include "vismask.hpp"
2015-04-19 15:55:56 +00:00
#include "util.hpp"
2014-01-17 09:52:44 +00:00
namespace MWRender
{
2015-04-19 15:55:56 +00:00
EffectManager::EffectManager(osg::ref_ptr<osg::Group> parent, Resource::ResourceSystem* resourceSystem)
: mParentNode(parent)
, mResourceSystem(resourceSystem)
2014-01-17 09:52:44 +00:00
{
}
2015-04-19 15:55:56 +00:00
EffectManager::~EffectManager()
2014-01-17 09:52:44 +00:00
{
2015-04-19 15:55:56 +00:00
clear();
}
2014-01-17 09:52:44 +00:00
2016-09-14 14:18:29 +00:00
void EffectManager::addEffect(const std::string &model, const std::string& textureOverride, const osg::Vec3f &worldPosition, float scale, bool isMagicVFX)
2015-04-19 15:55:56 +00:00
{
2016-02-09 17:33:02 +00:00
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(model);
2014-01-17 09:52:44 +00:00
node->setNodeMask(Mask_Effect);
2014-01-17 09:52:44 +00:00
2015-04-19 15:55:56 +00:00
Effect effect;
effect.mAnimTime.reset(new EffectAnimationTime);
2014-01-17 09:52:44 +00:00
2015-04-19 15:55:56 +00:00
SceneUtil::FindMaxControllerLengthVisitor findMaxLengthVisitor;
node->accept(findMaxLengthVisitor);
effect.mMaxControllerLength = findMaxLengthVisitor.getMaxLength();
osg::ref_ptr<osg::PositionAttitudeTransform> trans = new osg::PositionAttitudeTransform;
trans->setPosition(worldPosition);
trans->setScale(osg::Vec3f(scale, scale, scale));
2015-04-19 15:55:56 +00:00
trans->addChild(node);
SceneUtil::AssignControllerSourcesVisitor assignVisitor(effect.mAnimTime);
node->accept(assignVisitor);
2016-09-14 14:18:29 +00:00
if (isMagicVFX)
overrideFirstRootTexture(textureOverride, mResourceSystem, node);
else
overrideTexture(textureOverride, mResourceSystem, node);
2014-01-17 09:52:44 +00:00
2015-04-19 15:55:56 +00:00
mParentNode->addChild(trans);
mEffects[trans] = effect;
2014-01-17 09:52:44 +00:00
}
2015-04-19 15:55:56 +00:00
void EffectManager::update(float dt)
2014-01-17 09:52:44 +00:00
{
2015-04-19 15:55:56 +00:00
for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); )
2014-01-17 09:52:44 +00:00
{
2015-04-19 15:55:56 +00:00
it->second.mAnimTime->addTime(dt);
2014-01-17 09:52:44 +00:00
2015-04-19 15:55:56 +00:00
if (it->second.mAnimTime->getTime() >= it->second.mMaxControllerLength)
2014-01-17 09:52:44 +00:00
{
2015-04-19 15:55:56 +00:00
mParentNode->removeChild(it->first);
mEffects.erase(it++);
2014-01-17 09:52:44 +00:00
}
2015-04-19 15:55:56 +00:00
else
++it;
2014-01-17 09:52:44 +00:00
}
}
void EffectManager::clear()
{
2015-04-19 15:55:56 +00:00
for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
2014-01-17 09:52:44 +00:00
{
2015-04-19 15:55:56 +00:00
mParentNode->removeChild(it->first);
2014-01-17 09:52:44 +00:00
}
2015-04-19 15:55:56 +00:00
mEffects.clear();
2014-01-17 09:52:44 +00:00
}
}