1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00
OpenMW/apps/openmw/mwrender/objects.hpp
Bo Svensson a854a6e04a
removes UnrefQueue (#3181)
Currently, we use an `UnrefQueue` which supposedly aims to transfer destruction costs to another thread. The implications of this unusual pattern can not be well understood because some allocators might free resources more efficiently if they are freed by the same thread that allocated them. In addition, `UnrefQueue` complicates the validation of thread safety in our engine. Lastly, our current usage of `UnrefQueue` triggers `ref()`, `unref()` atomic operations as objects are passed into the queue. These operations could be more expensive than the actual destruction.

With this PR we thus remove `UnrefQueue`. We can expect these changes to have a minor impact at most because we free most resources elsewhere in `ResourceSystem::updateCache`.
2021-10-20 23:02:15 +02:00

94 lines
2.0 KiB
C++

#ifndef GAME_RENDER_OBJECTS_H
#define GAME_RENDER_OBJECTS_H
#include <map>
#include <string>
#include <osg/ref_ptr>
#include <osg/Object>
#include "../mwworld/ptr.hpp"
namespace osg
{
class Group;
}
namespace Resource
{
class ResourceSystem;
}
namespace MWWorld
{
class CellStore;
}
namespace MWRender{
class Animation;
class PtrHolder : public osg::Object
{
public:
PtrHolder(const MWWorld::Ptr& ptr)
: mPtr(ptr)
{
}
PtrHolder()
{
}
PtrHolder(const PtrHolder& copy, const osg::CopyOp& copyop)
: mPtr(copy.mPtr)
{
}
META_Object(MWRender, PtrHolder)
MWWorld::Ptr mPtr;
};
class Objects{
typedef std::map<MWWorld::ConstPtr,osg::ref_ptr<Animation> > PtrAnimationMap;
typedef std::map<const MWWorld::CellStore*, osg::ref_ptr<osg::Group> > CellMap;
CellMap mCellSceneNodes;
PtrAnimationMap mObjects;
osg::ref_ptr<osg::Group> mRootNode;
Resource::ResourceSystem* mResourceSystem;
void insertBegin(const MWWorld::Ptr& ptr);
public:
Objects(Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> rootNode);
~Objects();
/// @param animated Attempt to load separate keyframes from a .kf file matching the model file?
/// @param allowLight If false, no lights will be created, and particles systems will be removed.
void insertModel(const MWWorld::Ptr& ptr, const std::string &model, bool animated=false, bool allowLight=true);
void insertNPC(const MWWorld::Ptr& ptr);
void insertCreature (const MWWorld::Ptr& ptr, const std::string& model, bool weaponsShields);
Animation* getAnimation(const MWWorld::Ptr &ptr);
const Animation* getAnimation(const MWWorld::ConstPtr &ptr) const;
bool removeObject (const MWWorld::Ptr& ptr);
///< \return found?
void removeCell(const MWWorld::CellStore* store);
/// Updates containing cell for object rendering data
void updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &cur);
private:
void operator = (const Objects&);
Objects(const Objects&);
};
}
#endif