1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-28 20:06:41 +00:00

Cleanup magic effects, when create a new ActorAnimation

This commit is contained in:
Andrei Kortunov 2018-09-28 13:57:13 +04:00
parent 5fa9b32e76
commit 4dc424036f
3 changed files with 67 additions and 6 deletions

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

@ -213,14 +213,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)
{ {
} }
@ -240,9 +238,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;
@ -1649,12 +1701,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)

View file

@ -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 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,