| 1252 | } |
| 1253 | |
| 1254 | void lightThread::run() |
| 1255 | { |
| 1256 | while(!isDone) |
| 1257 | { |
| 1258 | //TODO: get area to process, and then process (by rounds): 1. occlusions, 2.sun, 3.lights(could be difficult, units/items etc...) |
| 1259 | {//wait for occlusion (and lights) to be ready |
| 1260 | std::unique_lock<std::mutex> guard(dispatch.occlusionMutex); |
| 1261 | if(!dispatch.occlusionReady) |
| 1262 | dispatch.occlusionDone.wait(guard);//wait for work |
| 1263 | if(dispatch.unprocessed.size()==0 || !dispatch.occlusionReady) //spurious wake-up |
| 1264 | continue; |
| 1265 | if(dispatch.occlusion.size()!=canvas.size()) //oh no somebody resized stuff |
| 1266 | canvas.resize(dispatch.occlusion.size()); |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | { //get my rectangle (any will do) |
| 1271 | std::lock_guard<std::mutex> guard(dispatch.unprocessedMutex); |
| 1272 | if (dispatch.unprocessed.size()==0) |
| 1273 | { |
| 1274 | //wtf?? why?! |
| 1275 | continue; |
| 1276 | } |
| 1277 | myRect=dispatch.unprocessed.top(); |
| 1278 | dispatch.unprocessed.pop(); |
| 1279 | if (dispatch.unprocessed.size()==0) |
| 1280 | { |
| 1281 | dispatch.occlusionReady=false; |
| 1282 | } |
| 1283 | |
| 1284 | } |
| 1285 | work(); |
| 1286 | { |
| 1287 | std::lock_guard<std::mutex> guard(dispatch.writeLock); |
| 1288 | combine();//write it back |
| 1289 | dispatch.writeCount++; |
| 1290 | } |
| 1291 | dispatch.writesDone.notify_one();//tell about it to the dispatch. |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | void lightThread::work() |
| 1296 | { |