1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-27 04:10:24 +00:00

Merged pull request #1952

This commit is contained in:
Marc Zinnschlag 2018-10-03 13:19:28 +02:00
commit b410d87aae
4 changed files with 75 additions and 13 deletions

View file

@ -1684,7 +1684,10 @@ namespace MWMechanics
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(iter->first); MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(iter->first);
if (animation) if (animation)
animation->updateEffects(); {
animation->removeEffects();
MWBase::Environment::get().getWorld()->applyLoopingParticles(iter->first);
}
} }

View file

@ -40,6 +40,9 @@ ActorAnimation::ActorAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group>
addHiddenItemLight(*iter, light); addHiddenItemLight(*iter, light);
} }
} }
// Make sure we cleaned object from effects, just in cast if we re-use node
removeEffects();
} }
ActorAnimation::~ActorAnimation() ActorAnimation::~ActorAnimation()

View file

@ -187,14 +187,12 @@ namespace
RemoveFinishedCallbackVisitor() RemoveFinishedCallbackVisitor()
: RemoveVisitor() : RemoveVisitor()
, mHasMagicEffects(false) , mHasMagicEffects(false)
, mEffectId(-1)
{ {
} }
RemoveFinishedCallbackVisitor(int effectId) RemoveFinishedCallbackVisitor(int effectId)
: RemoveVisitor() : RemoveVisitor()
, mHasMagicEffects(false) , mHasMagicEffects(false)
, mEffectId(effectId)
{ {
} }
@ -214,9 +212,63 @@ namespace
MWRender::UpdateVfxCallback* vfxCallback = dynamic_cast<MWRender::UpdateVfxCallback*>(callback); MWRender::UpdateVfxCallback* vfxCallback = dynamic_cast<MWRender::UpdateVfxCallback*>(callback);
if (vfxCallback) if (vfxCallback)
{ {
bool finished = vfxCallback->mFinished; if (vfxCallback->mFinished)
bool toRemove = mEffectId >= 0 && vfxCallback->mParams.mEffectId == mEffectId; mToRemove.push_back(std::make_pair(group.asNode(), group.getParent(0)));
if (finished || toRemove) else
mHasMagicEffects = true;
}
}
}
virtual void apply(osg::MatrixTransform &node)
{
traverse(node);
}
virtual void apply(osg::Geometry&)
{
}
private:
int mEffectId;
};
class RemoveCallbackVisitor : public RemoveVisitor
{
public:
bool mHasMagicEffects;
RemoveCallbackVisitor()
: RemoveVisitor()
, mHasMagicEffects(false)
, mEffectId(-1)
{
}
RemoveCallbackVisitor(int effectId)
: RemoveVisitor()
, mHasMagicEffects(false)
, mEffectId(effectId)
{
}
virtual void apply(osg::Node &node)
{
traverse(node);
}
virtual void apply(osg::Group &group)
{
traverse(group);
osg::Callback* callback = group.getUpdateCallback();
if (callback)
{
MWRender::UpdateVfxCallback* vfxCallback = dynamic_cast<MWRender::UpdateVfxCallback*>(callback);
if (vfxCallback)
{
bool toRemove = mEffectId < 0 || vfxCallback->mParams.mEffectId == mEffectId;
if (toRemove)
mToRemove.push_back(std::make_pair(group.asNode(), group.getParent(0))); mToRemove.push_back(std::make_pair(group.asNode(), group.getParent(0)));
else else
mHasMagicEffects = true; mHasMagicEffects = true;
@ -546,8 +598,8 @@ namespace MWRender
} }
else else
{ {
// Remove effect immediately // Hide effect immediately
mParams.mObjects.reset(); node->setNodeMask(0);
mFinished = true; mFinished = true;
} }
} }
@ -1608,7 +1660,6 @@ namespace MWRender
params.mLoop = loop; params.mLoop = loop;
params.mEffectId = effectId; params.mEffectId = effectId;
params.mBoneName = bonename; params.mBoneName = bonename;
params.mObjects = PartHolderPtr(new PartHolder(node));
params.mAnimTime = std::shared_ptr<EffectAnimationTime>(new EffectAnimationTime); params.mAnimTime = std::shared_ptr<EffectAnimationTime>(new EffectAnimationTime);
trans->addUpdateCallback(new UpdateVfxCallback(params)); trans->addUpdateCallback(new UpdateVfxCallback(params));
@ -1623,12 +1674,17 @@ namespace MWRender
void Animation::removeEffect(int effectId) void Animation::removeEffect(int effectId)
{ {
RemoveFinishedCallbackVisitor visitor(effectId); RemoveCallbackVisitor visitor(effectId);
mInsert->accept(visitor); mInsert->accept(visitor);
visitor.remove(); visitor.remove();
mHasMagicEffects = visitor.mHasMagicEffects; mHasMagicEffects = visitor.mHasMagicEffects;
} }
void Animation::removeEffects()
{
removeEffect(-1);
}
void Animation::getLoopingEffects(std::vector<int> &out) const void Animation::getLoopingEffects(std::vector<int> &out) const
{ {
if (!mHasMagicEffects) if (!mHasMagicEffects)
@ -1892,12 +1948,12 @@ namespace MWRender
PartHolder::~PartHolder() PartHolder::~PartHolder()
{ {
if (mNode.get() && !mNode->getNumParents()) if (mNode.get() && !mNode->getNumParents())
Log(Debug::Verbose) << "Part has no parents" ; Log(Debug::Verbose) << "Part \"" << mNode->getName() << "\" has no parents" ;
if (mNode.get() && mNode->getNumParents()) if (mNode.get() && mNode->getNumParents())
{ {
if (mNode->getNumParents() > 1) if (mNode->getNumParents() > 1)
Log(Debug::Verbose) << "Part has multiple (" << mNode->getNumParents() << ") parents"; Log(Debug::Verbose) << "Part \"" << mNode->getName() << "\" has multiple (" << mNode->getNumParents() << ") parents";
mNode->getParent(0)->removeChild(mNode); mNode->getParent(0)->removeChild(mNode);
} }
} }

View file

@ -74,7 +74,6 @@ typedef std::shared_ptr<PartHolder> PartHolderPtr;
struct EffectParams struct EffectParams
{ {
std::string mModelName; // Just here so we don't add the same effect twice std::string mModelName; // Just here so we don't add the same effect twice
PartHolderPtr mObjects;
std::shared_ptr<EffectAnimationTime> mAnimTime; std::shared_ptr<EffectAnimationTime> mAnimTime;
float mMaxControllerLength; float mMaxControllerLength;
int mEffectId; int mEffectId;
@ -370,6 +369,7 @@ public:
*/ */
void addEffect (const std::string& model, int effectId, bool loop = false, const std::string& bonename = "", const std::string& texture = "", float scale = 1.0f); void addEffect (const std::string& model, int effectId, bool loop = false, const std::string& bonename = "", const std::string& texture = "", float scale = 1.0f);
void removeEffect (int effectId); void removeEffect (int effectId);
void removeEffects ();
void getLoopingEffects (std::vector<int>& out) const; void getLoopingEffects (std::vector<int>& out) const;
// Add a spell casting glow to an object. From measuring video taken from the original engine, // Add a spell casting glow to an object. From measuring video taken from the original engine,