Some performance fixes and tweaks. Opaque blocks can now emit light.

develop
Japa 2013-06-24 14:20:22 +05:30
parent ec913c2c5e
commit 8271725320
2 changed files with 17 additions and 7 deletions

@ -25,6 +25,7 @@ using namespace DFHack;
using df::coord2d; using df::coord2d;
const float levelDim=0.2f; const float levelDim=0.2f;
const float RootTwo = 1.4142135623730950488016887242097f;
rect2d getMapViewport() rect2d getMapViewport()
{ {
@ -94,8 +95,9 @@ void plotLine(int x0, int y0, int x1, int y1,std::function<bool(int,int,int,int)
int rdx=0; int rdx=0;
int rdy=0; int rdy=0;
for(;;){ /* loop */ for(;;){ /* loop */
if(!setPixel(rdx,rdy,x0,y0)) if(rdx!=0 || rdy!=0) //dirty hack to skip occlusion on the first tile.
return; if(!setPixel(rdx,rdy,x0,y0))
return;
if (x0==x1 && y0==y1) break; if (x0==x1 && y0==y1) break;
e2 = 2*err; e2 = 2*err;
rdx=rdy=0; rdx=rdy=0;
@ -113,8 +115,16 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx
if(tx>=mapPort.first.x && ty>=mapPort.first.y && tx<=mapPort.second.x && ty<=mapPort.second.y) if(tx>=mapPort.first.x && ty>=mapPort.first.y && tx<=mapPort.second.x && ty<=mapPort.second.y)
{ {
size_t tile=getIndex(tx,ty); size_t tile=getIndex(tx,ty);
float dsq=dx*dx+dy*dy; int dsq=dx*dx+dy*dy;
float dt=sqrt(dsq); float dt=1;
if(dsq == 1)
dt=1;
else if(dsq == 2)
dt = RootTwo;
else if(dsq == 0)
dt = 0;
else
dt=sqrt((float)dsq);
lightCell& v=ocupancy[tile]; lightCell& v=ocupancy[tile];
lightSource& ls=lights[tile]; lightSource& ls=lights[tile];
bool wallhack=false; bool wallhack=false;
@ -173,7 +183,7 @@ void lightingEngineViewscreen::doFovs()
int surrounds = 0; int surrounds = 0;
lightCell curPower; lightCell curPower;
if(lightUpCell(curPower = power, 0, 0,i+0, j+0)) lightUpCell(curPower = power, 0, 0,i+0, j+0);
{ {
surrounds += lightUpCell(curPower = power, 0, 1,i+0, j+1); surrounds += lightUpCell(curPower = power, 0, 1,i+0, j+1);
surrounds += lightUpCell(curPower = power, 1, 1,i+1, j+1); surrounds += lightUpCell(curPower = power, 1, 1,i+1, j+1);
@ -517,7 +527,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(df::global::cursor->x>-30000) if(df::global::cursor->x>-30000)
{ {
lightSource cursor(lightCell(0.96f,0.84f,0.03f),11); lightSource cursor(lightCell(0.96f,0.84f,0.03f),11);
cursor.flicker=true; cursor.flicker=false;
int wx=df::global::cursor->x-window_x+vp.first.x; int wx=df::global::cursor->x-window_x+vp.first.x;
int wy=df::global::cursor->y-window_y+vp.first.y; int wy=df::global::cursor->y-window_y+vp.first.y;
int tile=getIndex(wx,wy); int tile=getIndex(wx,wy);

@ -127,4 +127,4 @@ private:
int w,h; int w,h;
DFHack::rect2d mapPort; DFHack::rect2d mapPort;
}; };
#endif #endif