mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 12:40:04 +00:00
Derive Animation from osg::Referenced to allow the UnrefQueue to delete it
This commit is contained in:
parent
a5247394dc
commit
00d4fea91c
@ -1673,9 +1673,4 @@ namespace MWRender
|
||||
}
|
||||
}
|
||||
|
||||
void PartHolder::unlink()
|
||||
{
|
||||
mNode = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,9 +58,6 @@ public:
|
||||
|
||||
~PartHolder();
|
||||
|
||||
/// Unreferences mNode *without* detaching it from the graph. Only use if you know what you are doing.
|
||||
void unlink();
|
||||
|
||||
osg::ref_ptr<osg::Node> getNode()
|
||||
{
|
||||
return mNode;
|
||||
@ -74,7 +71,7 @@ private:
|
||||
};
|
||||
typedef boost::shared_ptr<PartHolder> PartHolderPtr;
|
||||
|
||||
class Animation
|
||||
class Animation : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
enum BoneGroup {
|
||||
@ -339,6 +336,8 @@ protected:
|
||||
public:
|
||||
|
||||
Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem);
|
||||
|
||||
/// Must be thread safe
|
||||
virtual ~Animation();
|
||||
|
||||
MWWorld::ConstPtr getPtr() const;
|
||||
|
@ -218,10 +218,10 @@ namespace MWRender
|
||||
|
||||
void CharacterPreview::rebuild()
|
||||
{
|
||||
mAnimation.reset(NULL);
|
||||
mAnimation = NULL;
|
||||
|
||||
mAnimation.reset(new NpcAnimation(mCharacter, mNode, mResourceSystem, true,
|
||||
(renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal)));
|
||||
mAnimation = new NpcAnimation(mCharacter, mNode, mResourceSystem, true,
|
||||
(renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
|
||||
|
||||
onSetup();
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace MWRender
|
||||
|
||||
MWWorld::Ptr mCharacter;
|
||||
|
||||
std::auto_ptr<MWRender::NpcAnimation> mAnimation;
|
||||
osg::ref_ptr<MWRender::NpcAnimation> mAnimation;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mNode;
|
||||
std::string mCurrentAnimGroup;
|
||||
|
||||
|
@ -269,12 +269,6 @@ const NpcAnimation::PartBoneMap NpcAnimation::sPartList = createPartListMap();
|
||||
|
||||
NpcAnimation::~NpcAnimation()
|
||||
{
|
||||
// do not detach (delete) parts yet, this is done so the background thread can handle the deletion
|
||||
for(size_t i = 0;i < ESM::PRT_Count;i++)
|
||||
{
|
||||
if (mObjectParts[i].get())
|
||||
mObjectParts[i]->unlink();
|
||||
}
|
||||
}
|
||||
|
||||
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem,
|
||||
|
@ -29,8 +29,6 @@ Objects::Objects(Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Gro
|
||||
|
||||
Objects::~Objects()
|
||||
{
|
||||
for(PtrAnimationMap::iterator iter = mObjects.begin();iter != mObjects.end();++iter)
|
||||
delete iter->second;
|
||||
mObjects.clear();
|
||||
|
||||
for (CellMap::iterator iter = mCellSceneNodes.begin(); iter != mCellSceneNodes.end(); ++iter)
|
||||
@ -74,9 +72,9 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool
|
||||
{
|
||||
insertBegin(ptr);
|
||||
|
||||
std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, animated, allowLight));
|
||||
osg::ref_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, animated, allowLight));
|
||||
|
||||
mObjects.insert(std::make_pair(ptr, anim.release()));
|
||||
mObjects.insert(std::make_pair(ptr, anim));
|
||||
}
|
||||
|
||||
void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, bool weaponsShields)
|
||||
@ -85,16 +83,16 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b
|
||||
ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);
|
||||
|
||||
// CreatureAnimation
|
||||
std::auto_ptr<Animation> anim;
|
||||
osg::ref_ptr<Animation> anim;
|
||||
|
||||
if (weaponsShields)
|
||||
anim.reset(new CreatureWeaponAnimation(ptr, mesh, mResourceSystem));
|
||||
anim = new CreatureWeaponAnimation(ptr, mesh, mResourceSystem);
|
||||
else
|
||||
anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem));
|
||||
anim = new CreatureAnimation(ptr, mesh, mResourceSystem);
|
||||
|
||||
ptr.getClass().getContainerStore(ptr).setContListener(static_cast<ActorAnimation*>(anim.get()));
|
||||
|
||||
mObjects.insert(std::make_pair(ptr, anim.release()));
|
||||
mObjects.insert(std::make_pair(ptr, anim));
|
||||
}
|
||||
|
||||
void Objects::insertNPC(const MWWorld::Ptr &ptr)
|
||||
@ -102,12 +100,12 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr)
|
||||
insertBegin(ptr);
|
||||
ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);
|
||||
|
||||
std::auto_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem));
|
||||
osg::ref_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem));
|
||||
|
||||
ptr.getClass().getInventoryStore(ptr).setInvListener(anim.get(), ptr);
|
||||
ptr.getClass().getInventoryStore(ptr).setContListener(anim.get());
|
||||
|
||||
mObjects.insert(std::make_pair(ptr, anim.release()));
|
||||
mObjects.insert(std::make_pair(ptr, anim));
|
||||
}
|
||||
|
||||
bool Objects::removeObject (const MWWorld::Ptr& ptr)
|
||||
@ -119,9 +117,8 @@ bool Objects::removeObject (const MWWorld::Ptr& ptr)
|
||||
if(iter != mObjects.end())
|
||||
{
|
||||
if (mUnrefQueue.get())
|
||||
mUnrefQueue->push(iter->second->getObjectRoot());
|
||||
mUnrefQueue->push(iter->second);
|
||||
|
||||
delete iter->second;
|
||||
mObjects.erase(iter);
|
||||
|
||||
if (ptr.getClass().isNpc())
|
||||
@ -148,7 +145,7 @@ void Objects::removeCell(const MWWorld::CellStore* store)
|
||||
if(ptr.getCell() == store)
|
||||
{
|
||||
if (mUnrefQueue.get())
|
||||
mUnrefQueue->push(iter->second->getObjectRoot());
|
||||
mUnrefQueue->push(iter->second);
|
||||
|
||||
if (ptr.getClass().isNpc() && ptr.getRefData().getCustomData())
|
||||
{
|
||||
@ -157,7 +154,6 @@ void Objects::removeCell(const MWWorld::CellStore* store)
|
||||
store.setContListener(NULL);
|
||||
}
|
||||
|
||||
delete iter->second;
|
||||
mObjects.erase(iter++);
|
||||
}
|
||||
else
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
};
|
||||
|
||||
class Objects{
|
||||
typedef std::map<MWWorld::ConstPtr,Animation*> PtrAnimationMap;
|
||||
typedef std::map<MWWorld::ConstPtr,osg::ref_ptr<Animation> > PtrAnimationMap;
|
||||
|
||||
typedef std::map<const MWWorld::CellStore*, osg::ref_ptr<osg::Group> > CellMap;
|
||||
CellMap mCellSceneNodes;
|
||||
|
@ -821,8 +821,8 @@ namespace MWRender
|
||||
|
||||
void RenderingManager::renderPlayer(const MWWorld::Ptr &player)
|
||||
{
|
||||
mPlayerAnimation.reset(new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0, NpcAnimation::VM_Normal,
|
||||
mFirstPersonFieldOfView));
|
||||
mPlayerAnimation = new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0, NpcAnimation::VM_Normal,
|
||||
mFirstPersonFieldOfView);
|
||||
|
||||
mCamera->setAnimation(mPlayerAnimation.get());
|
||||
mCamera->attachTo(player);
|
||||
|
@ -214,7 +214,7 @@ namespace MWRender
|
||||
std::auto_ptr<Terrain::World> mTerrain;
|
||||
std::auto_ptr<SkyManager> mSky;
|
||||
std::auto_ptr<EffectManager> mEffectManager;
|
||||
std::auto_ptr<NpcAnimation> mPlayerAnimation;
|
||||
osg::ref_ptr<NpcAnimation> mPlayerAnimation;
|
||||
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
|
||||
std::auto_ptr<Camera> mCamera;
|
||||
osg::Vec3f mCurrentCameraPos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user