|
|
@ -1043,10 +1043,11 @@ void lightThread::run()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while(!isDone)
|
|
|
|
while(!isDone)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{//wait for occlusion (and lights) to be ready
|
|
|
|
tthread::lock_guard<tthread::mutex> guard(dispatch.occlusionMutex);
|
|
|
|
tthread::lock_guard<tthread::mutex> guard(dispatch.occlusionMutex);
|
|
|
|
|
|
|
|
if(!dispatch.occlusionReady)
|
|
|
|
dispatch.occlusionDone.wait(dispatch.occlusionMutex);//wait for work
|
|
|
|
dispatch.occlusionDone.wait(dispatch.occlusionMutex);//wait for work
|
|
|
|
if(dispatch.unprocessed.size()==0) //spurious wake-up
|
|
|
|
if(dispatch.unprocessed.size()==0 || !dispatch.occlusionReady) //spurious wake-up
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if(dispatch.occlusion.size()!=canvas.size()) //oh no somebody resized stuff
|
|
|
|
if(dispatch.occlusion.size()!=canvas.size()) //oh no somebody resized stuff
|
|
|
|
canvas.resize(dispatch.occlusion.size());
|
|
|
|
canvas.resize(dispatch.occlusion.size());
|
|
|
@ -1055,8 +1056,18 @@ void lightThread::run()
|
|
|
|
|
|
|
|
|
|
|
|
{ //get my rectangle (any will do)
|
|
|
|
{ //get my rectangle (any will do)
|
|
|
|
tthread::lock_guard<tthread::mutex> guard(dispatch.unprocessedMutex);
|
|
|
|
tthread::lock_guard<tthread::mutex> guard(dispatch.unprocessedMutex);
|
|
|
|
|
|
|
|
if (dispatch.unprocessed.size()==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//wtf?? why?!
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
myRect=dispatch.unprocessed.top();
|
|
|
|
myRect=dispatch.unprocessed.top();
|
|
|
|
dispatch.unprocessed.pop();
|
|
|
|
dispatch.unprocessed.pop();
|
|
|
|
|
|
|
|
if (dispatch.unprocessed.size()==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dispatch.occlusionReady=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
work();
|
|
|
|
work();
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1173,8 +1184,10 @@ void lightThreadDispatch::signalDoneOcclusion()
|
|
|
|
tthread::lock_guard<tthread::mutex> guardWrite(writeLock);
|
|
|
|
tthread::lock_guard<tthread::mutex> guardWrite(writeLock);
|
|
|
|
writeCount=0;
|
|
|
|
writeCount=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tthread::lock_guard<tthread::mutex> guard(occlusionMutex);
|
|
|
|
tthread::lock_guard<tthread::mutex> guard1(occlusionMutex);
|
|
|
|
|
|
|
|
tthread::lock_guard<tthread::mutex> guard2(unprocessedMutex);
|
|
|
|
|
|
|
|
while(!unprocessed.empty())
|
|
|
|
|
|
|
|
unprocessed.pop();
|
|
|
|
viewPort=getMapViewport();
|
|
|
|
viewPort=getMapViewport();
|
|
|
|
int threadCount=threadPool.size();
|
|
|
|
int threadCount=threadPool.size();
|
|
|
|
int w=viewPort.second.x-viewPort.first.x;
|
|
|
|
int w=viewPort.second.x-viewPort.first.x;
|
|
|
@ -1189,10 +1202,12 @@ void lightThreadDispatch::signalDoneOcclusion()
|
|
|
|
area.second.x=viewPort.first.x+(i+1)*slicew;
|
|
|
|
area.second.x=viewPort.first.x+(i+1)*slicew;
|
|
|
|
unprocessed.push(area);
|
|
|
|
unprocessed.push(area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
occlusionReady=true;
|
|
|
|
occlusionDone.notify_all();
|
|
|
|
occlusionDone.notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lightThreadDispatch::lightThreadDispatch( lightingEngineViewscreen* p ):parent(p),lights(parent->lights),occlusion(parent->ocupancy),lightMap(parent->lightMap),writeCount(0)
|
|
|
|
lightThreadDispatch::lightThreadDispatch( lightingEngineViewscreen* p ):parent(p),lights(parent->lights),occlusion(parent->ocupancy),
|
|
|
|
|
|
|
|
lightMap(parent->lightMap),writeCount(0),occlusionReady(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1202,6 +1217,11 @@ void lightThreadDispatch::shutdown()
|
|
|
|
for(int i=0;i<threadPool.size();i++)
|
|
|
|
for(int i=0;i<threadPool.size();i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
threadPool[i]->isDone=true;
|
|
|
|
threadPool[i]->isDone=true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
occlusionDone.notify_all();//if stuck signal that you are done with stuff.
|
|
|
|
|
|
|
|
for(int i=0;i<threadPool.size();i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
threadPool[i]->myThread->join();
|
|
|
|
threadPool[i]->myThread->join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
threadPool.clear();
|
|
|
|
threadPool.clear();
|
|
|
@ -1239,3 +1259,8 @@ void lightThreadDispatch::waitForWrites()
|
|
|
|
writesDone.wait(writeLock); //if not, wait a bit
|
|
|
|
writesDone.wait(writeLock); //if not, wait a bit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lightThreadDispatch::~lightThreadDispatch()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|