From 4f7df238eae45100370861263a8e4885d6683d8f Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 23 Jun 2013 21:29:03 +0300 Subject: [PATCH] Fixed non-circular light. Do not show hidden tiles. --- plugins/rendermax/renderer_light.cpp | 23 +++++++++++++++-------- plugins/rendermax/renderer_light.hpp | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/rendermax/renderer_light.cpp b/plugins/rendermax/renderer_light.cpp index 7ad617e44..fb5f35d53 100644 --- a/plugins/rendermax/renderer_light.cpp +++ b/plugins/rendermax/renderer_light.cpp @@ -105,6 +105,7 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx { size_t tile=getIndex(tx,ty); float dsq=dx*dx+dy*dy; + float dt=sqrt(dsq); lightCell& v=ocupancy[tile]; lightSource& ls=lights[tile]; bool wallhack=false; @@ -113,9 +114,9 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx if (dsq>0 && !wallhack) { - power.r=power.r*(pow(v.r,dsq)); - power.g=power.g*(pow(v.g,dsq)); - power.b=power.b*(pow(v.b,dsq)); + power.r=power.r*(pow(v.r,dt)); + power.g=power.g*(pow(v.g,dt)); + power.b=power.b*(pow(v.b,dt)); } if(ls.radius>0 && dsq>0) { @@ -186,6 +187,7 @@ void lightingEngineViewscreen::updateWindow() if(lightMap.size()!=myRenderer->lightGrid.size()) { reinit(); + myRenderer->invalidate(); return; } std::swap(lightMap,myRenderer->lightGrid); @@ -210,7 +212,9 @@ bool lightingEngineViewscreen::addLight(int tileId,const lightSource& light) } void lightingEngineViewscreen::doOcupancyAndLights() { - + lightSource sun(lightCell(1,1,1),15); + lightSource lava(lightCell(0.8f,0.2f,0.2f),5); + rect2d vp=getMapViewport(); int window_x=*df::global::window_x; @@ -228,15 +232,18 @@ void lightingEngineViewscreen::doOcupancyAndLights() curCell=lightCell(0.85f,0.85f,0.85f); df::tiletype* type = Maps::getTileType(x,y,window_z); if(!type) + { + //unallocated, do sky + addLight(tile,sun); continue; + } df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,*type); df::tile_designation* d=Maps::getTileDesignation(x,y,window_z); df::tile_designation* d2=Maps::getTileDesignation(x,y,window_z-1); df::tile_occupancy* o=Maps::getTileOccupancy(x,y,window_z); if(!o || !d ) continue; - - if(shape==df::tiletype_shape::BROOK_BED || shape==df::tiletype_shape::WALL || shape==df::tiletype_shape::TREE ) + if(shape==df::tiletype_shape::BROOK_BED || shape==df::tiletype_shape::WALL || shape==df::tiletype_shape::TREE || d->bits.hidden ) { curCell=lightCell(0,0,0); } @@ -253,12 +260,12 @@ void lightingEngineViewscreen::doOcupancyAndLights() && d2 && d2->bits.liquid_type && d2->bits.flow_size>0) ) { - lightSource lava(lightCell(0.8f,0.2f,0.2f),5); + addLight(tile,lava); } if(d->bits.outside) { - lightSource sun(lightCell(1,1,1),15); + addLight(tile,sun); } diff --git a/plugins/rendermax/renderer_light.hpp b/plugins/rendermax/renderer_light.hpp index 541e4280f..9520380e1 100644 --- a/plugins/rendermax/renderer_light.hpp +++ b/plugins/rendermax/renderer_light.hpp @@ -59,7 +59,7 @@ public: }; virtual void resize(int32_t w, int32_t h) { renderer_wrap::resize(w,h); - reinitLightGrid(w,h); + reinitLightGrid(); } }; class lightingEngine