mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Introduce UnrefQueue to handle the deleting of no longer needed objects in the background thread
This commit is contained in:
parent
f6f9eff9a6
commit
d11c2864df
9 changed files with 128 additions and 22 deletions
46
components/sceneutil/unrefqueue.cpp
Normal file
46
components/sceneutil/unrefqueue.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "unrefqueue.hpp"
|
||||
|
||||
#include <osg/Object>
|
||||
//#include <osg/Timer>
|
||||
//#include <iostream>
|
||||
|
||||
#include <components/sceneutil/workqueue.hpp>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
class UnrefWorkItem : public SceneUtil::WorkItem
|
||||
{
|
||||
public:
|
||||
std::vector<osg::ref_ptr<osg::Object> > mObjects;
|
||||
|
||||
virtual void doWork()
|
||||
{
|
||||
//osg::Timer timer;
|
||||
//size_t objcount = mObjects.size();
|
||||
mObjects.clear();
|
||||
//std::cout << "cleared " << objcount << " objects in " << timer.time_m() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
UnrefQueue::UnrefQueue()
|
||||
{
|
||||
mWorkItem = new UnrefWorkItem;
|
||||
}
|
||||
|
||||
void UnrefQueue::push(osg::Object *obj)
|
||||
{
|
||||
mWorkItem->mObjects.push_back(obj);
|
||||
}
|
||||
|
||||
void UnrefQueue::flush(SceneUtil::WorkQueue *workQueue)
|
||||
{
|
||||
if (mWorkItem->mObjects.empty())
|
||||
return;
|
||||
|
||||
workQueue->addWorkItem(mWorkItem);
|
||||
|
||||
mWorkItem = new UnrefWorkItem;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue