Added support for running multiple text generation threads
This commit is contained in:
parent
4ba3f3c1a1
commit
8d1ef9906a
@ -604,21 +604,29 @@ int main(int argc, char** argv)
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
osg::ref_ptr<osg::OperationThread> operationThread;
|
||||
typedef std::list< osg::ref_ptr<osg::OperationThread> > Threads;
|
||||
|
||||
Threads operationThreads;
|
||||
osg::ref_ptr<UpdateTextOperation> updateOperation;
|
||||
|
||||
if (arguments.read("--mt"))
|
||||
unsigned int numThreads = 0;
|
||||
if (arguments.read("--mt", numThreads) || arguments.read("--mt"))
|
||||
{
|
||||
// construct a multi-threaded text updating test.
|
||||
if (numThreads==0) numThreads = 1;
|
||||
|
||||
// create a group to add everything into.
|
||||
osg::Group* mainGroup = new osg::Group;
|
||||
|
||||
for(unsigned int i=0; i<numThreads; ++i)
|
||||
{
|
||||
osg::Group* textGroup = new osg::Group;
|
||||
mainGroup->addChild(textGroup);
|
||||
|
||||
// create the background thread
|
||||
operationThread = new osg::OperationThread;
|
||||
osg::OperationThread* operationThread = new osg::OperationThread;
|
||||
|
||||
operationThreads.push_back(operationThread);
|
||||
|
||||
// create the operation that will run in the background and
|
||||
// sync once per frame with the main viewer loop.
|
||||
@ -638,6 +646,7 @@ int main(int argc, char** argv)
|
||||
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.5f,0.5f,0.5f),1.0)));
|
||||
|
||||
mainGroup->addChild(geode);
|
||||
}
|
||||
|
||||
viewer.setSceneData(mainGroup);
|
||||
}
|
||||
@ -677,9 +686,14 @@ int main(int argc, char** argv)
|
||||
|
||||
viewer.run();
|
||||
|
||||
if (operationThread.valid())
|
||||
if (!operationThreads.empty())
|
||||
{
|
||||
operationThread->cancel();
|
||||
for(Threads::iterator itr = operationThreads.begin();
|
||||
itr != operationThreads.begin();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user