Fixed non-circular light. Do not show hidden tiles.

develop
Warmist 2013-06-23 21:29:03 +03:00
parent cb6130066d
commit 4f7df238ea
2 changed files with 16 additions and 9 deletions

@ -105,6 +105,7 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx
{ {
size_t tile=getIndex(tx,ty); size_t tile=getIndex(tx,ty);
float dsq=dx*dx+dy*dy; float dsq=dx*dx+dy*dy;
float dt=sqrt(dsq);
lightCell& v=ocupancy[tile]; lightCell& v=ocupancy[tile];
lightSource& ls=lights[tile]; lightSource& ls=lights[tile];
bool wallhack=false; bool wallhack=false;
@ -113,9 +114,9 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx
if (dsq>0 && !wallhack) if (dsq>0 && !wallhack)
{ {
power.r=power.r*(pow(v.r,dsq)); power.r=power.r*(pow(v.r,dt));
power.g=power.g*(pow(v.g,dsq)); power.g=power.g*(pow(v.g,dt));
power.b=power.b*(pow(v.b,dsq)); power.b=power.b*(pow(v.b,dt));
} }
if(ls.radius>0 && dsq>0) if(ls.radius>0 && dsq>0)
{ {
@ -186,6 +187,7 @@ void lightingEngineViewscreen::updateWindow()
if(lightMap.size()!=myRenderer->lightGrid.size()) if(lightMap.size()!=myRenderer->lightGrid.size())
{ {
reinit(); reinit();
myRenderer->invalidate();
return; return;
} }
std::swap(lightMap,myRenderer->lightGrid); std::swap(lightMap,myRenderer->lightGrid);
@ -210,6 +212,8 @@ bool lightingEngineViewscreen::addLight(int tileId,const lightSource& light)
} }
void lightingEngineViewscreen::doOcupancyAndLights() void lightingEngineViewscreen::doOcupancyAndLights()
{ {
lightSource sun(lightCell(1,1,1),15);
lightSource lava(lightCell(0.8f,0.2f,0.2f),5);
rect2d vp=getMapViewport(); rect2d vp=getMapViewport();
@ -228,15 +232,18 @@ void lightingEngineViewscreen::doOcupancyAndLights()
curCell=lightCell(0.85f,0.85f,0.85f); curCell=lightCell(0.85f,0.85f,0.85f);
df::tiletype* type = Maps::getTileType(x,y,window_z); df::tiletype* type = Maps::getTileType(x,y,window_z);
if(!type) if(!type)
{
//unallocated, do sky
addLight(tile,sun);
continue; continue;
}
df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,*type); df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,*type);
df::tile_designation* d=Maps::getTileDesignation(x,y,window_z); df::tile_designation* d=Maps::getTileDesignation(x,y,window_z);
df::tile_designation* d2=Maps::getTileDesignation(x,y,window_z-1); df::tile_designation* d2=Maps::getTileDesignation(x,y,window_z-1);
df::tile_occupancy* o=Maps::getTileOccupancy(x,y,window_z); df::tile_occupancy* o=Maps::getTileOccupancy(x,y,window_z);
if(!o || !d ) if(!o || !d )
continue; continue;
if(shape==df::tiletype_shape::BROOK_BED || shape==df::tiletype_shape::WALL || shape==df::tiletype_shape::TREE || d->bits.hidden )
if(shape==df::tiletype_shape::BROOK_BED || shape==df::tiletype_shape::WALL || shape==df::tiletype_shape::TREE )
{ {
curCell=lightCell(0,0,0); curCell=lightCell(0,0,0);
} }
@ -253,12 +260,12 @@ void lightingEngineViewscreen::doOcupancyAndLights()
&& d2 && d2->bits.liquid_type && d2->bits.flow_size>0) && d2 && d2->bits.liquid_type && d2->bits.flow_size>0)
) )
{ {
lightSource lava(lightCell(0.8f,0.2f,0.2f),5);
addLight(tile,lava); addLight(tile,lava);
} }
if(d->bits.outside) if(d->bits.outside)
{ {
lightSource sun(lightCell(1,1,1),15);
addLight(tile,sun); addLight(tile,sun);
} }

@ -59,7 +59,7 @@ public:
}; };
virtual void resize(int32_t w, int32_t h) { virtual void resize(int32_t w, int32_t h) {
renderer_wrap::resize(w,h); renderer_wrap::resize(w,h);
reinitLightGrid(w,h); reinitLightGrid();
} }
}; };
class lightingEngine class lightingEngine