| 533 | } |
| 534 | |
| 535 | void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache& map) |
| 536 | { |
| 537 | //TODO fix this mess |
| 538 | int window_x=*df::global::window_x; |
| 539 | int window_y=*df::global::window_y; |
| 540 | coord2d window2d(window_x,window_y); |
| 541 | int window_z=*df::global::window_z; |
| 542 | rect2d vp=getMapViewport(); |
| 543 | coord2d vpSize=rect_size(vp); |
| 544 | rect2d blockVp; |
| 545 | blockVp.first=window2d/16; |
| 546 | blockVp.second=(window2d+vpSize)/16; |
| 547 | blockVp.second.x=std::min(blockVp.second.x,(int16_t)df::global::world->map.x_count_block); |
| 548 | blockVp.second.y=std::min(blockVp.second.y,(int16_t)df::global::world->map.y_count_block); |
| 549 | //endof mess |
| 550 | for(int blockX=blockVp.first.x;blockX<=blockVp.second.x;blockX++) |
| 551 | for(int blockY=blockVp.first.y;blockY<=blockVp.second.y;blockY++) |
| 552 | { |
| 553 | rgbf cellArray[16][16]; |
| 554 | for(int block_x = 0; block_x < 16; block_x++) |
| 555 | for(int block_y = 0; block_y < 16; block_y++) |
| 556 | cellArray[block_x][block_y] = sky.power; |
| 557 | |
| 558 | int emptyCell=0; |
| 559 | for(int z=window_z;z< df::global::world->map.z_count && emptyCell<256;z++) |
| 560 | { |
| 561 | MapExtras::Block* b=map.BlockAt(DFCoord(blockX,blockY,z)); |
| 562 | if(!b) |
| 563 | continue; |
| 564 | emptyCell=0; |
| 565 | for(int block_x = 0; block_x < 16; block_x++) |
| 566 | for(int block_y = 0; block_y < 16; block_y++) |
| 567 | { |
| 568 | rgbf& curCell=cellArray[block_x][block_y]; |
| 569 | curCell=propogateSun(b,block_x,block_y,curCell,z==window_z); |
| 570 | if(curCell.dot(curCell)<0.003f) |
| 571 | emptyCell++; |
| 572 | } |
| 573 | } |
| 574 | if(emptyCell==256) |
| 575 | continue; |
| 576 | for(int block_x = 0; block_x < 16; block_x++) |
| 577 | for(int block_y = 0; block_y < 16; block_y++) |
| 578 | { |
| 579 | rgbf& curCell=cellArray[block_x][block_y]; |
| 580 | df::coord2d pos; |
| 581 | pos.x = blockX*16+block_x; |
| 582 | pos.y = blockY*16+block_y; |
| 583 | pos=worldToViewportCoord(pos,vp,window2d); |
| 584 | if(isInRect(pos,vp) && curCell.dot(curCell)>0.003f) |
| 585 | { |
| 586 | lightSource sun=lightSource(curCell,15); |
| 587 | addLight(getIndex(pos.x,pos.y),sun); |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | rgbf lightingEngineViewscreen::getSkyColor(float v) |
nothing calls this directly
no test coverage detected