mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 09:23:53 +00:00
Cleanup magic effects, when create a new ActorAnimation
This commit is contained in:
parent
5fa9b32e76
commit
4dc424036f
3 changed files with 67 additions and 6 deletions
|
@ -40,6 +40,9 @@ ActorAnimation::ActorAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group>
|
|||
addHiddenItemLight(*iter, light);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we cleaned object from effects, just in cast if we re-use node
|
||||
removeEffects();
|
||||
}
|
||||
|
||||
ActorAnimation::~ActorAnimation()
|
||||
|
|
|
@ -213,14 +213,12 @@ namespace
|
|||
RemoveFinishedCallbackVisitor()
|
||||
: RemoveVisitor()
|
||||
, mHasMagicEffects(false)
|
||||
, mEffectId(-1)
|
||||
{
|
||||
}
|
||||
|
||||
RemoveFinishedCallbackVisitor(int effectId)
|
||||
: RemoveVisitor()
|
||||
, mHasMagicEffects(false)
|
||||
, mEffectId(effectId)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -240,9 +238,63 @@ namespace
|
|||
MWRender::UpdateVfxCallback* vfxCallback = dynamic_cast<MWRender::UpdateVfxCallback*>(callback);
|
||||
if (vfxCallback)
|
||||
{
|
||||
bool finished = vfxCallback->mFinished;
|
||||
bool toRemove = mEffectId >= 0 && vfxCallback->mParams.mEffectId == mEffectId;
|
||||
if (finished || toRemove)
|
||||
if (vfxCallback->mFinished)
|
||||
mToRemove.push_back(std::make_pair(group.asNode(), group.getParent(0)));
|
||||
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)));
|
||||
else
|
||||
mHasMagicEffects = true;
|
||||
|
@ -1649,12 +1701,17 @@ namespace MWRender
|
|||
|
||||
void Animation::removeEffect(int effectId)
|
||||
{
|
||||
RemoveFinishedCallbackVisitor visitor(effectId);
|
||||
RemoveCallbackVisitor visitor(effectId);
|
||||
mInsert->accept(visitor);
|
||||
visitor.remove();
|
||||
mHasMagicEffects = visitor.mHasMagicEffects;
|
||||
}
|
||||
|
||||
void Animation::removeEffects()
|
||||
{
|
||||
removeEffect(-1);
|
||||
}
|
||||
|
||||
void Animation::getLoopingEffects(std::vector<int> &out) const
|
||||
{
|
||||
if (!mHasMagicEffects)
|
||||
|
|
|
@ -370,6 +370,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 removeEffect (int effectId);
|
||||
void removeEffects ();
|
||||
void getLoopingEffects (std::vector<int>& out) const;
|
||||
|
||||
// Add a spell casting glow to an object. From measuring video taken from the original engine,
|
||||
|
|
Loading…
Reference in a new issue