Derive Animation from osg::Referenced to allow the UnrefQueue to delete it

pull/164/head
scrawl 8 years ago
parent a5247394dc
commit 00d4fea91c

@ -1673,9 +1673,4 @@ namespace MWRender
} }
} }
void PartHolder::unlink()
{
mNode = NULL;
}
} }

@ -58,9 +58,6 @@ public:
~PartHolder(); ~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() osg::ref_ptr<osg::Node> getNode()
{ {
return mNode; return mNode;
@ -74,7 +71,7 @@ private:
}; };
typedef boost::shared_ptr<PartHolder> PartHolderPtr; typedef boost::shared_ptr<PartHolder> PartHolderPtr;
class Animation class Animation : public osg::Referenced
{ {
public: public:
enum BoneGroup { enum BoneGroup {
@ -339,6 +336,8 @@ protected:
public: public:
Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem); Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem);
/// Must be thread safe
virtual ~Animation(); virtual ~Animation();
MWWorld::ConstPtr getPtr() const; MWWorld::ConstPtr getPtr() const;

@ -218,10 +218,10 @@ namespace MWRender
void CharacterPreview::rebuild() void CharacterPreview::rebuild()
{ {
mAnimation.reset(NULL); mAnimation = NULL;
mAnimation.reset(new NpcAnimation(mCharacter, mNode, mResourceSystem, true, mAnimation = new NpcAnimation(mCharacter, mNode, mResourceSystem, true,
(renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal))); (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal));
onSetup(); onSetup();

@ -61,7 +61,7 @@ namespace MWRender
MWWorld::Ptr mCharacter; MWWorld::Ptr mCharacter;
std::auto_ptr<MWRender::NpcAnimation> mAnimation; osg::ref_ptr<MWRender::NpcAnimation> mAnimation;
osg::ref_ptr<osg::PositionAttitudeTransform> mNode; osg::ref_ptr<osg::PositionAttitudeTransform> mNode;
std::string mCurrentAnimGroup; std::string mCurrentAnimGroup;

@ -269,12 +269,6 @@ const NpcAnimation::PartBoneMap NpcAnimation::sPartList = createPartListMap();
NpcAnimation::~NpcAnimation() 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, 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() Objects::~Objects()
{ {
for(PtrAnimationMap::iterator iter = mObjects.begin();iter != mObjects.end();++iter)
delete iter->second;
mObjects.clear(); mObjects.clear();
for (CellMap::iterator iter = mCellSceneNodes.begin(); iter != mCellSceneNodes.end(); ++iter) 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); 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) 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); ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);
// CreatureAnimation // CreatureAnimation
std::auto_ptr<Animation> anim; osg::ref_ptr<Animation> anim;
if (weaponsShields) if (weaponsShields)
anim.reset(new CreatureWeaponAnimation(ptr, mesh, mResourceSystem)); anim = new CreatureWeaponAnimation(ptr, mesh, mResourceSystem);
else else
anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem)); anim = new CreatureAnimation(ptr, mesh, mResourceSystem);
ptr.getClass().getContainerStore(ptr).setContListener(static_cast<ActorAnimation*>(anim.get())); 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) void Objects::insertNPC(const MWWorld::Ptr &ptr)
@ -102,12 +100,12 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr)
insertBegin(ptr); insertBegin(ptr);
ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor); 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).setInvListener(anim.get(), ptr);
ptr.getClass().getInventoryStore(ptr).setContListener(anim.get()); 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) bool Objects::removeObject (const MWWorld::Ptr& ptr)
@ -119,9 +117,8 @@ bool Objects::removeObject (const MWWorld::Ptr& ptr)
if(iter != mObjects.end()) if(iter != mObjects.end())
{ {
if (mUnrefQueue.get()) if (mUnrefQueue.get())
mUnrefQueue->push(iter->second->getObjectRoot()); mUnrefQueue->push(iter->second);
delete iter->second;
mObjects.erase(iter); mObjects.erase(iter);
if (ptr.getClass().isNpc()) if (ptr.getClass().isNpc())
@ -148,7 +145,7 @@ void Objects::removeCell(const MWWorld::CellStore* store)
if(ptr.getCell() == store) if(ptr.getCell() == store)
{ {
if (mUnrefQueue.get()) if (mUnrefQueue.get())
mUnrefQueue->push(iter->second->getObjectRoot()); mUnrefQueue->push(iter->second);
if (ptr.getClass().isNpc() && ptr.getRefData().getCustomData()) if (ptr.getClass().isNpc() && ptr.getRefData().getCustomData())
{ {
@ -157,7 +154,6 @@ void Objects::removeCell(const MWWorld::CellStore* store)
store.setContListener(NULL); store.setContListener(NULL);
} }
delete iter->second;
mObjects.erase(iter++); mObjects.erase(iter++);
} }
else else

@ -62,7 +62,7 @@ public:
}; };
class Objects{ 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; typedef std::map<const MWWorld::CellStore*, osg::ref_ptr<osg::Group> > CellMap;
CellMap mCellSceneNodes; CellMap mCellSceneNodes;

@ -821,8 +821,8 @@ namespace MWRender
void RenderingManager::renderPlayer(const MWWorld::Ptr &player) void RenderingManager::renderPlayer(const MWWorld::Ptr &player)
{ {
mPlayerAnimation.reset(new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0, NpcAnimation::VM_Normal, mPlayerAnimation = new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0, NpcAnimation::VM_Normal,
mFirstPersonFieldOfView)); mFirstPersonFieldOfView);
mCamera->setAnimation(mPlayerAnimation.get()); mCamera->setAnimation(mPlayerAnimation.get());
mCamera->attachTo(player); mCamera->attachTo(player);

@ -214,7 +214,7 @@ namespace MWRender
std::auto_ptr<Terrain::World> mTerrain; std::auto_ptr<Terrain::World> mTerrain;
std::auto_ptr<SkyManager> mSky; std::auto_ptr<SkyManager> mSky;
std::auto_ptr<EffectManager> mEffectManager; std::auto_ptr<EffectManager> mEffectManager;
std::auto_ptr<NpcAnimation> mPlayerAnimation; osg::ref_ptr<NpcAnimation> mPlayerAnimation;
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode; osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
std::auto_ptr<Camera> mCamera; std::auto_ptr<Camera> mCamera;
osg::Vec3f mCurrentCameraPos; osg::Vec3f mCurrentCameraPos;

Loading…
Cancel
Save