Renamed lightCell to rgbf

develop
Warmist 2013-06-30 15:05:59 +03:00
parent ee1bad84fc
commit f34a4ce34e
4 changed files with 127 additions and 127 deletions

@ -47,7 +47,7 @@ lightingEngineViewscreen::~lightingEngineViewscreen()
threading.shutdown(); threading.shutdown();
} }
lightSource::lightSource(lightCell power,int radius):power(power),flicker(false) lightSource::lightSource(rgbf power,int radius):power(power),flicker(false)
{ {
if(radius >= 0) if(radius >= 0)
this->radius = radius; this->radius = radius;
@ -118,7 +118,7 @@ void lightingEngineViewscreen::reinit()
w=gps->dimx; w=gps->dimx;
h=gps->dimy; h=gps->dimy;
size_t size=w*h; size_t size=w*h;
lightMap.resize(size,lightCell(1,1,1)); lightMap.resize(size,rgbf(1,1,1));
ocupancy.resize(size); ocupancy.resize(size);
lights.resize(size); lights.resize(size);
} }
@ -149,7 +149,7 @@ void plotSquare(int xm, int ym, int r,std::function<void(int,int)> setPixel)
setPixel(xm-x, ym+r); /* IV.2 Quadrant */ setPixel(xm-x, ym+r); /* IV.2 Quadrant */
} }
} }
void plotLine(int x0, int y0, int x1, int y1,lightCell power,std::function<lightCell(lightCell,int,int,int,int)> setPixel) void plotLine(int x0, int y0, int x1, int y1,rgbf power,std::function<rgbf(rgbf,int,int,int,int)> setPixel)
{ {
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1; int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
@ -171,7 +171,7 @@ void plotLine(int x0, int y0, int x1, int y1,lightCell power,std::function<light
} }
} }
void plotLineAA(int x0, int y0, int x1, int y1,lightCell power,std::function<lightCell(lightCell,int,int,int,int)> setPixelAA) void plotLineAA(int x0, int y0, int x1, int y1,rgbf power,std::function<rgbf(rgbf,int,int,int,int)> setPixelAA)
{ {
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
@ -180,7 +180,7 @@ void plotLineAA(int x0, int y0, int x1, int y1,lightCell power,std::function<lig
int rdx=0; int rdx=0;
int rdy=0; int rdy=0;
int lrdx,lrdy; int lrdx,lrdy;
lightCell sumPower; rgbf sumPower;
for ( ; ; ){ /* pixel loop */ for ( ; ; ){ /* pixel loop */
float strsum=0; float strsum=0;
float str=1-abs(err-dx+dy)/(float)ed; float str=1-abs(err-dx+dy)/(float)ed;
@ -220,17 +220,17 @@ void plotLineAA(int x0, int y0, int x1, int y1,lightCell power,std::function<lig
power=sumPower; power=sumPower;
} }
} }
lightCell blendMax(lightCell a,lightCell b) rgbf blendMax(rgbf a,rgbf b)
{ {
return lightCell(std::max(a.r,b.r),std::max(a.g,b.g),std::max(a.b,b.b)); return rgbf(std::max(a.r,b.r),std::max(a.g,b.g),std::max(a.b,b.b));
} }
lightCell blend(lightCell a,lightCell b) rgbf blend(rgbf a,rgbf b)
{ {
return blendMax(a,b); return blendMax(a,b);
} }
void lightingEngineViewscreen::clear() void lightingEngineViewscreen::clear()
{ {
lightMap.assign(lightMap.size(),lightCell(1,1,1)); lightMap.assign(lightMap.size(),rgbf(1,1,1));
tthread::lock_guard<tthread::fast_mutex> guard(myRenderer->dataMutex); tthread::lock_guard<tthread::fast_mutex> guard(myRenderer->dataMutex);
if(lightMap.size()==myRenderer->lightGrid.size()) if(lightMap.size()==myRenderer->lightGrid.size())
{ {
@ -241,8 +241,8 @@ void lightingEngineViewscreen::clear()
void lightingEngineViewscreen::calculate() void lightingEngineViewscreen::calculate()
{ {
rect2d vp=getMapViewport(); rect2d vp=getMapViewport();
const lightCell dim(levelDim,levelDim,levelDim); const rgbf dim(levelDim,levelDim,levelDim);
lightMap.assign(lightMap.size(),lightCell(1,1,1)); lightMap.assign(lightMap.size(),rgbf(1,1,1));
lights.assign(lights.size(),lightSource()); lights.assign(lights.size(),lightSource());
for(int i=vp.first.x;i<vp.second.x;i++) for(int i=vp.first.x;i<vp.second.x;i++)
for(int j=vp.first.y;j<vp.second.y;j++) for(int j=vp.first.y;j<vp.second.y;j++)
@ -289,16 +289,16 @@ bool lightingEngineViewscreen::addLight(int tileId,const lightSource& light)
lights[tileId].flicker=true; lights[tileId].flicker=true;
return wasLight; return wasLight;
} }
void lightingEngineViewscreen::addOclusion(int tileId,const lightCell& c,float thickness) void lightingEngineViewscreen::addOclusion(int tileId,const rgbf& c,float thickness)
{ {
if(thickness > 0.999 && thickness < 1.001) if(thickness > 0.999 && thickness < 1.001)
ocupancy[tileId]*=c; ocupancy[tileId]*=c;
else else
ocupancy[tileId]*=(c.pow(thickness)); ocupancy[tileId]*=(c.pow(thickness));
} }
lightCell getStandartColor(int colorId) rgbf getStandartColor(int colorId)
{ {
return lightCell(df::global::enabler->ccolor[colorId][0]/255.0f, return rgbf(df::global::enabler->ccolor[colorId][0]/255.0f,
df::global::enabler->ccolor[colorId][1]/255.0f, df::global::enabler->ccolor[colorId][1]/255.0f,
df::global::enabler->ccolor[colorId][2]/255.0f); df::global::enabler->ccolor[colorId][2]/255.0f);
} }
@ -343,7 +343,7 @@ void lightingEngineViewscreen::applyMaterial(int tileId,const matLightDef& mat,f
addOclusion(tileId,mat.transparency,thickness); addOclusion(tileId,mat.transparency,thickness);
} }
else else
ocupancy[tileId]=lightCell(0,0,0); ocupancy[tileId]=rgbf(0,0,0);
if(mat.isEmiting) if(mat.isEmiting)
addLight(tileId,mat.makeSource(size)); addLight(tileId,mat.makeSource(size));
} }
@ -361,11 +361,11 @@ bool lightingEngineViewscreen::applyMaterial(int tileId,int matType,int matIndex
} }
return false; return false;
} }
lightCell lightingEngineViewscreen::propogateSun(MapExtras::Block* b, int x,int y,const lightCell& in,bool lastLevel) rgbf lightingEngineViewscreen::propogateSun(MapExtras::Block* b, int x,int y,const rgbf& in,bool lastLevel)
{ {
//TODO unify under addLight/addOclusion //TODO unify under addLight/addOclusion
const lightCell matStairCase(0.9f,0.9f,0.9f); const rgbf matStairCase(0.9f,0.9f,0.9f);
lightCell ret=in; rgbf ret=in;
coord2d innerCoord(x,y); coord2d innerCoord(x,y);
df::tiletype type = b->staticTiletypeAt(innerCoord); df::tiletype type = b->staticTiletypeAt(innerCoord);
df::tile_designation d = b->DesignationAt(innerCoord); df::tile_designation d = b->DesignationAt(innerCoord);
@ -440,7 +440,7 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
for(int blockX=blockVp.first.x;blockX<=blockVp.second.x;blockX++) for(int blockX=blockVp.first.x;blockX<=blockVp.second.x;blockX++)
for(int blockY=blockVp.first.y;blockY<=blockVp.second.y;blockY++) for(int blockY=blockVp.first.y;blockY<=blockVp.second.y;blockY++)
{ {
lightCell cellArray[16][16]; rgbf cellArray[16][16];
for(int block_x = 0; block_x < 16; block_x++) for(int block_x = 0; block_x < 16; block_x++)
for(int block_y = 0; block_y < 16; block_y++) for(int block_y = 0; block_y < 16; block_y++)
cellArray[block_x][block_y] = sky.power; cellArray[block_x][block_y] = sky.power;
@ -455,7 +455,7 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
for(int block_x = 0; block_x < 16; block_x++) for(int block_x = 0; block_x < 16; block_x++)
for(int block_y = 0; block_y < 16; block_y++) for(int block_y = 0; block_y < 16; block_y++)
{ {
lightCell& curCell=cellArray[block_x][block_y]; rgbf& curCell=cellArray[block_x][block_y];
curCell=propogateSun(b,block_x,block_y,curCell,z==window_z); curCell=propogateSun(b,block_x,block_y,curCell,z==window_z);
if(curCell.dot(curCell)<0.003f) if(curCell.dot(curCell)<0.003f)
emptyCell++; emptyCell++;
@ -466,7 +466,7 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
for(int block_x = 0; block_x < 16; block_x++) for(int block_x = 0; block_x < 16; block_x++)
for(int block_y = 0; block_y < 16; block_y++) for(int block_y = 0; block_y < 16; block_y++)
{ {
lightCell& curCell=cellArray[block_x][block_y]; rgbf& curCell=cellArray[block_x][block_y];
df::coord2d pos; df::coord2d pos;
pos.x = blockX*16+block_x; pos.x = blockX*16+block_x;
pos.y = blockY*16+block_y; pos.y = blockY*16+block_y;
@ -479,12 +479,12 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
} }
} }
} }
lightCell lightingEngineViewscreen::getSkyColor(float v) rgbf lightingEngineViewscreen::getSkyColor(float v)
{ {
if(dayColors.size()<2) if(dayColors.size()<2)
{ {
v=abs(fmod(v+0.5,1)-0.5)*2; v=abs(fmod(v+0.5,1)-0.5)*2;
return lightCell(v,v,v); return rgbf(v,v,v);
} }
else else
{ {
@ -509,11 +509,11 @@ void lightingEngineViewscreen::doOcupancyAndLights()
else else
daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h
lightCell sky_col=getSkyColor(daycol); rgbf sky_col=getSkyColor(daycol);
lightSource sky(sky_col, -1);//auto calculate best size lightSource sky(sky_col, -1);//auto calculate best size
lightSource candle(lightCell(0.96f,0.84f,0.03f),5); lightSource candle(rgbf(0.96f,0.84f,0.03f),5);
lightSource torch(lightCell(0.9f,0.75f,0.3f),8); lightSource torch(rgbf(0.9f,0.75f,0.3f),8);
//perfectly blocking material //perfectly blocking material
@ -551,7 +551,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(!isInRect(pos,vp)) if(!isInRect(pos,vp))
continue; continue;
int tile=getIndex(pos.x,pos.y); int tile=getIndex(pos.x,pos.y);
lightCell& curCell=ocupancy[tile]; rgbf& curCell=ocupancy[tile];
curCell=matAmbience.transparency; curCell=matAmbience.transparency;
@ -559,7 +559,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
df::tile_designation d = b->DesignationAt(gpos); df::tile_designation d = b->DesignationAt(gpos);
if(d.bits.hidden) if(d.bits.hidden)
{ {
curCell=lightCell(0,0,0); curCell=rgbf(0,0,0);
continue; // do not process hidden stuff, TODO other hidden stuff continue; // do not process hidden stuff, TODO other hidden stuff
} }
//df::tile_occupancy o = b->OccupancyAt(gpos); //df::tile_occupancy o = b->OccupancyAt(gpos);
@ -574,7 +574,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
lightDef=&matWall; lightDef=&matWall;
if(shape==df::tiletype_shape::BROOK_BED ) if(shape==df::tiletype_shape::BROOK_BED )
{ {
curCell=lightCell(0,0,0); curCell=rgbf(0,0,0);
} }
else if(shape==df::tiletype_shape::WALL) else if(shape==df::tiletype_shape::WALL)
{ {
@ -621,18 +621,18 @@ void lightingEngineViewscreen::doOcupancyAndLights()
int tile=getIndex(pos.x,pos.y); int tile=getIndex(pos.x,pos.y);
if(isInRect(pos,vp)) if(isInRect(pos,vp))
{ {
lightCell fireColor; rgbf fireColor;
if(f->density>60) if(f->density>60)
{ {
fireColor=lightCell(0.98f,0.91f,0.30f); fireColor=rgbf(0.98f,0.91f,0.30f);
} }
else if(f->density>30) else if(f->density>30)
{ {
fireColor=lightCell(0.93f,0.16f,0.16f); fireColor=rgbf(0.93f,0.16f,0.16f);
} }
else else
{ {
fireColor=lightCell(0.64f,0.0f,0.0f); fireColor=rgbf(0.64f,0.0f,0.0f);
} }
lightSource fire(fireColor,f->density/5); lightSource fire(fireColor,f->density/5);
addLight(tile,fire); addLight(tile,fire);
@ -776,9 +776,9 @@ void lightingEngineViewscreen::doOcupancyAndLights()
} }
} }
lightCell lua_parseLightCell(lua_State* L) rgbf lua_parseLightCell(lua_State* L)
{ {
lightCell ret; rgbf ret;
lua_pushnumber(L,1); lua_pushnumber(L,1);
lua_gettable(L,-2); lua_gettable(L,-2);
@ -955,20 +955,20 @@ int lightingEngineViewscreen::parseBuildings(lua_State* L)
} }
void lightingEngineViewscreen::defaultSettings() void lightingEngineViewscreen::defaultSettings()
{ {
matAmbience=matLightDef(lightCell(0.85f,0.85f,0.85f)); matAmbience=matLightDef(rgbf(0.85f,0.85f,0.85f));
matLava=matLightDef(lightCell(0.8f,0.2f,0.2f),lightCell(0.8f,0.2f,0.2f),5); matLava=matLightDef(rgbf(0.8f,0.2f,0.2f),rgbf(0.8f,0.2f,0.2f),5);
matWater=matLightDef(lightCell(0.6f,0.6f,0.8f)); matWater=matLightDef(rgbf(0.6f,0.6f,0.8f));
matIce=matLightDef(lightCell(0.7f,0.7f,0.9f)); matIce=matLightDef(rgbf(0.7f,0.7f,0.9f));
matCursor=matLightDef(lightCell(0.96f,0.84f,0.03f),11); matCursor=matLightDef(rgbf(0.96f,0.84f,0.03f),11);
matCursor.flicker=true; matCursor.flicker=true;
matWall=matLightDef(lightCell(0,0,0)); matWall=matLightDef(rgbf(0,0,0));
matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6); matCitizen=matLightDef(rgbf(0.8f,0.8f,0.9f),6);
levelDim=0.2f; levelDim=0.2f;
dayHour=-1; dayHour=-1;
daySpeed=1; daySpeed=1;
dayColors.push_back(lightCell(0,0,0)); dayColors.push_back(rgbf(0,0,0));
dayColors.push_back(lightCell(1,1,1)); dayColors.push_back(rgbf(1,1,1));
dayColors.push_back(lightCell(0,0,0)); dayColors.push_back(rgbf(0,0,0));
} }
void lightingEngineViewscreen::loadSettings() void lightingEngineViewscreen::loadSettings()
{ {
@ -1070,7 +1070,7 @@ void lightThread::run()
void lightThread::work() void lightThread::work()
{ {
canvas.assign(canvas.size(),lightCell(0,0,0)); canvas.assign(canvas.size(),rgbf(0,0,0));
for(int i=myRect.first.x;i<myRect.second.x;i++) for(int i=myRect.first.x;i<myRect.second.x;i++)
for(int j=myRect.first.y;j<myRect.second.y;j++) for(int j=myRect.first.y;j<myRect.second.y;j++)
{ {
@ -1082,13 +1082,13 @@ void lightThread::combine()
{ {
for(int i=0;i<canvas.size();i++) for(int i=0;i<canvas.size();i++)
{ {
lightCell& c=dispatch.lightMap[i]; rgbf& c=dispatch.lightMap[i];
c=blend(c,canvas[i]); c=blend(c,canvas[i]);
} }
} }
lightCell lightThread::lightUpCell(lightCell power,int dx,int dy,int tx,int ty) rgbf lightThread::lightUpCell(rgbf power,int dx,int dy,int tx,int ty)
{ {
int h=dispatch.getH(); int h=dispatch.getH();
if(isInRect(coord2d(tx,ty),dispatch.viewPort)) if(isInRect(coord2d(tx,ty),dispatch.viewPort))
@ -1104,7 +1104,7 @@ lightCell lightThread::lightUpCell(lightCell power,int dx,int dy,int tx,int ty)
dt = 0; dt = 0;
else else
dt=sqrt((float)dsq); dt=sqrt((float)dsq);
lightCell& v=dispatch.occlusion[tile]; rgbf& v=dispatch.occlusion[tile];
lightSource& ls=dispatch.lights[tile]; lightSource& ls=dispatch.lights[tile];
bool wallhack=false; bool wallhack=false;
if(v.r+v.g+v.b==0) if(v.r+v.g+v.b==0)
@ -1117,23 +1117,23 @@ lightCell lightThread::lightUpCell(lightCell power,int dx,int dy,int tx,int ty)
if(ls.radius>0 && dsq>0) if(ls.radius>0 && dsq>0)
{ {
if(power<=ls.power) if(power<=ls.power)
return lightCell(); return rgbf();
} }
//float dt=sqrt(dsq); //float dt=sqrt(dsq);
lightCell oldCol=canvas[tile]; rgbf oldCol=canvas[tile];
lightCell ncol=blendMax(power,oldCol); rgbf ncol=blendMax(power,oldCol);
canvas[tile]=ncol; canvas[tile]=ncol;
if(wallhack) if(wallhack)
return lightCell(); return rgbf();
return power; return power;
} }
else else
return lightCell(); return rgbf();
} }
void lightThread::doRay(lightCell power,int cx,int cy,int tx,int ty) void lightThread::doRay(rgbf power,int cx,int cy,int tx,int ty)
{ {
using namespace std::placeholders; using namespace std::placeholders;
@ -1146,7 +1146,7 @@ void lightThread::doLight( int x,int y )
lightSource& csource=dispatch.lights[x*dispatch.getH()+y]; lightSource& csource=dispatch.lights[x*dispatch.getH()+y];
if(csource.radius>0) if(csource.radius>0)
{ {
lightCell power=csource.power; rgbf power=csource.power;
int radius =csource.radius; int radius =csource.radius;
if(csource.flicker) if(csource.flicker)
{ {
@ -1154,7 +1154,7 @@ void lightThread::doLight( int x,int y )
radius*=flicker; radius*=flicker;
power=power*flicker; power=power*flicker;
} }
lightCell surrounds; rgbf surrounds;
lightUpCell( power, 0, 0,x, y); lightUpCell( power, 0, 0,x, y);
for(int i=-1;i<2;i++) for(int i=-1;i<2;i++)
for(int j=-1;j<2;j++) for(int j=-1;j<2;j++)

@ -17,7 +17,7 @@ private:
float *fg = p->fg + tile * 4 * 6; float *fg = p->fg + tile * 4 * 6;
float *bg = p->bg + tile * 4 * 6; float *bg = p->bg + tile * 4 * 6;
float *tex = p->tex + tile * 2 * 6; float *tex = p->tex + tile * 2 * 6;
lightCell light=lightGrid[tile]; rgbf light=lightGrid[tile];
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
*(fg++) *= light.r; *(fg++) *= light.r;
*(fg++) *= light.g; *(fg++) *= light.g;
@ -41,7 +41,7 @@ private:
} }
public: public:
tthread::fast_mutex dataMutex; tthread::fast_mutex dataMutex;
std::vector<lightCell> lightGrid; std::vector<rgbf> lightGrid;
renderer_light(renderer* parent):renderer_wrap(parent) renderer_light(renderer* parent):renderer_wrap(parent)
{ {
reinitLightGrid(); reinitLightGrid();
@ -87,14 +87,14 @@ protected:
}; };
struct lightSource struct lightSource
{ {
lightCell power; rgbf power;
int radius; int radius;
bool flicker; bool flicker;
lightSource():power(0,0,0),radius(0),flicker(false) lightSource():power(0,0,0),radius(0),flicker(false)
{ {
} }
lightSource(lightCell power,int radius); lightSource(rgbf power,int radius);
float powerSquared()const float powerSquared()const
{ {
return power.r*power.r+power.g*power.g+power.b*power.b; return power.r*power.r+power.g*power.g+power.b*power.b;
@ -105,16 +105,16 @@ struct lightSource
struct matLightDef struct matLightDef
{ {
bool isTransparent; bool isTransparent;
lightCell transparency; rgbf transparency;
bool isEmiting; bool isEmiting;
bool flicker; bool flicker;
lightCell emitColor; rgbf emitColor;
int radius; int radius;
matLightDef():isTransparent(false),isEmiting(false),transparency(0,0,0),emitColor(0,0,0),radius(0){} matLightDef():isTransparent(false),isEmiting(false),transparency(0,0,0),emitColor(0,0,0),radius(0){}
matLightDef(lightCell transparency,lightCell emit,int rad):isTransparent(true),isEmiting(true), matLightDef(rgbf transparency,rgbf emit,int rad):isTransparent(true),isEmiting(true),
transparency(transparency),emitColor(emit),radius(rad){} transparency(transparency),emitColor(emit),radius(rad){}
matLightDef(lightCell emit,int rad):isTransparent(false),isEmiting(true),emitColor(emit),radius(rad),transparency(0,0,0){} matLightDef(rgbf emit,int rad):isTransparent(false),isEmiting(true),emitColor(emit),radius(rad),transparency(0,0,0){}
matLightDef(lightCell transparency):isTransparent(true),isEmiting(false),transparency(transparency){} matLightDef(rgbf transparency):isTransparent(true),isEmiting(false),transparency(transparency){}
lightSource makeSource(float size=1) const lightSource makeSource(float size=1) const
{ {
if(size>0.999 && size<1.001) if(size>0.999 && size<1.001)
@ -147,10 +147,10 @@ public:
tthread::condition_variable occlusionDone; //all threads wait for occlusion to finish tthread::condition_variable occlusionDone; //all threads wait for occlusion to finish
tthread::mutex unprocessedMutex; tthread::mutex unprocessedMutex;
std::stack<DFHack::rect2d> unprocessed; //stack of parts of map where lighting is not finished std::stack<DFHack::rect2d> unprocessed; //stack of parts of map where lighting is not finished
std::vector<lightCell>& occlusion; std::vector<rgbf>& occlusion;
tthread::mutex writeLock; //mutex for lightMap tthread::mutex writeLock; //mutex for lightMap
std::vector<lightCell>& lightMap; std::vector<rgbf>& lightMap;
tthread::condition_variable writesDone; tthread::condition_variable writesDone;
int writeCount; int writeCount;
@ -166,7 +166,7 @@ public:
}; };
class lightThread class lightThread
{ {
std::vector<lightCell> canvas; std::vector<rgbf> canvas;
lightThreadDispatch& dispatch; lightThreadDispatch& dispatch;
DFHack::rect2d myRect; DFHack::rect2d myRect;
void work(); //main light calculation function void work(); //main light calculation function
@ -179,8 +179,8 @@ public:
void run(); void run();
private: private:
void doLight(int x,int y); void doLight(int x,int y);
void doRay(lightCell power,int cx,int cy,int tx,int ty); void doRay(rgbf power,int cx,int cy,int tx,int ty);
lightCell lightUpCell(lightCell power,int dx,int dy,int tx,int ty); rgbf lightUpCell(rgbf power,int dx,int dy,int tx,int ty);
}; };
class lightingEngineViewscreen:public lightingEngine class lightingEngineViewscreen:public lightingEngine
{ {
@ -203,13 +203,13 @@ private:
void doSun(const lightSource& sky,MapExtras::MapCache& map); void doSun(const lightSource& sky,MapExtras::MapCache& map);
void doOcupancyAndLights(); void doOcupancyAndLights();
lightCell propogateSun(MapExtras::Block* b, int x,int y,const lightCell& in,bool lastLevel); rgbf propogateSun(MapExtras::Block* b, int x,int y,const rgbf& in,bool lastLevel);
void doRay(std::vector<lightCell> & target, lightCell power,int cx,int cy,int tx,int ty); void doRay(std::vector<rgbf> & target, rgbf power,int cx,int cy,int tx,int ty);
void doFovs(); void doFovs();
void doLight(std::vector<lightCell> & target, int index); void doLight(std::vector<rgbf> & target, int index);
lightCell lightUpCell(std::vector<lightCell> & target, lightCell power,int dx,int dy,int tx,int ty); rgbf lightUpCell(std::vector<rgbf> & target, rgbf power,int dx,int dy,int tx,int ty);
bool addLight(int tileId,const lightSource& light); bool addLight(int tileId,const lightSource& light);
void addOclusion(int tileId,const lightCell& c,float thickness); void addOclusion(int tileId,const rgbf& c,float thickness);
matLightDef* getMaterial(int matType,int matIndex); matLightDef* getMaterial(int matType,int matIndex);
buildingLightDef* getBuilding(df::building* bld); buildingLightDef* getBuilding(df::building* bld);
@ -228,8 +228,8 @@ private:
return df::coord2d(index/h, index%h); return df::coord2d(index/h, index%h);
} }
//maps //maps
std::vector<lightCell> lightMap; std::vector<rgbf> lightMap;
std::vector<lightCell> ocupancy; std::vector<rgbf> ocupancy;
std::vector<lightSource> lights; std::vector<lightSource> lights;
//Threading stuff //Threading stuff
@ -242,13 +242,13 @@ private:
public: public:
void lightWorkerThread(void * arg); void lightWorkerThread(void * arg);
private: private:
lightCell getSkyColor(float v); rgbf getSkyColor(float v);
bool doDebug; bool doDebug;
//settings //settings
float daySpeed; float daySpeed;
float dayHour; //<0 to cycle float dayHour; //<0 to cycle
std::vector<lightCell> dayColors; // a gradient of colors, first to 0, last to 24 std::vector<rgbf> dayColors; // a gradient of colors, first to 0, last to 24
///set up sane settings if setting file does not exist. ///set up sane settings if setting file does not exist.
void defaultSettings(); void defaultSettings();
@ -272,6 +272,6 @@ private:
DFHack::rect2d mapPort; DFHack::rect2d mapPort;
friend lightThreadDispatch; friend lightThreadDispatch;
}; };
lightCell blend(lightCell a,lightCell b); rgbf blend(rgbf a,rgbf b);
lightCell blendMax(lightCell a,lightCell b); rgbf blendMax(rgbf a,rgbf b);
#endif #endif

@ -185,73 +185,73 @@ public:
}; };
}; };
struct lightCell struct rgbf
{ {
float r,g,b; float r,g,b;
lightCell():r(0),g(0),b(0) rgbf():r(0),g(0),b(0)
{ {
} }
lightCell(float r,float g,float b):r(r),g(g),b(b) rgbf(float r,float g,float b):r(r),g(g),b(b)
{ {
} }
lightCell operator-(const lightCell& cell) const rgbf operator-(const rgbf& cell) const
{ {
return lightCell(r-cell.r,g-cell.g,b-cell.b); return rgbf(r-cell.r,g-cell.g,b-cell.b);
} }
lightCell operator*(float val)const rgbf operator*(float val)const
{ {
return lightCell(r*val,g*val,b*val); return rgbf(r*val,g*val,b*val);
} }
lightCell operator/(float val) const rgbf operator/(float val) const
{ {
return lightCell(r/val,g/val,b/val); return rgbf(r/val,g/val,b/val);
} }
lightCell operator*(const lightCell& cell) const rgbf operator*(const rgbf& cell) const
{ {
return lightCell(r*cell.r,g*cell.g,b*cell.b); return rgbf(r*cell.r,g*cell.g,b*cell.b);
} }
lightCell operator*=(float val) rgbf operator*=(float val)
{ {
r*=val; r*=val;
g*=val; g*=val;
b*=val; b*=val;
return *this; return *this;
} }
lightCell operator*=(const lightCell& cell) rgbf operator*=(const rgbf& cell)
{ {
r*=cell.r; r*=cell.r;
g*=cell.g; g*=cell.g;
b*=cell.b; b*=cell.b;
return *this; return *this;
} }
lightCell operator+=(const lightCell& cell) rgbf operator+=(const rgbf& cell)
{ {
r+=cell.r; r+=cell.r;
g+=cell.g; g+=cell.g;
b+=cell.b; b+=cell.b;
return *this; return *this;
} }
lightCell operator+(const lightCell& other) const rgbf operator+(const rgbf& other) const
{ {
return lightCell(r+other.r,g+other.g,b+other.b); return rgbf(r+other.r,g+other.g,b+other.b);
} }
bool operator<=(const lightCell& other) const bool operator<=(const rgbf& other) const
{ {
return r<=other.r && g<=other.g && b<=other.b; return r<=other.r && g<=other.g && b<=other.b;
} }
float dot(const lightCell& other) const float dot(const rgbf& other) const
{ {
return r*other.r+g*other.g+b*other.b; return r*other.r+g*other.g+b*other.b;
} }
lightCell pow(const float exp) const rgbf pow(const float exp) const
{ {
return lightCell(std::pow(r, exp), std::pow(g, exp), std::pow(b, exp)); return rgbf(std::pow(r, exp), std::pow(g, exp), std::pow(b, exp));
} }
lightCell pow(const int exp) const rgbf pow(const int exp) const
{ {
return lightCell(std::pow(r, exp), std::pow(g, exp), std::pow(b, exp)); return rgbf(std::pow(r, exp), std::pow(g, exp), std::pow(b, exp));
} }
}; };
struct renderer_test : public renderer_wrap { struct renderer_test : public renderer_wrap {
@ -263,7 +263,7 @@ private:
float *fg = p->fg + tile * 4 * 6; float *fg = p->fg + tile * 4 * 6;
float *bg = p->bg + tile * 4 * 6; float *bg = p->bg + tile * 4 * 6;
float *tex = p->tex + tile * 2 * 6; float *tex = p->tex + tile * 2 * 6;
lightCell light=lightGrid[tile]; rgbf light=lightGrid[tile];
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
*(fg++) *= light.r; *(fg++) *= light.r;
*(fg++) *= light.g; *(fg++) *= light.g;
@ -287,7 +287,7 @@ private:
} }
public: public:
tthread::fast_mutex dataMutex; tthread::fast_mutex dataMutex;
std::vector<lightCell> lightGrid; std::vector<rgbf> lightGrid;
renderer_test(renderer* parent):renderer_wrap(parent) renderer_test(renderer* parent):renderer_wrap(parent)
{ {
reinitLightGrid(); reinitLightGrid();
@ -332,11 +332,11 @@ private:
float *fg = p->fg + tile * 4 * 6; float *fg = p->fg + tile * 4 * 6;
float *bg = p->bg + tile * 4 * 6; float *bg = p->bg + tile * 4 * 6;
float *tex = p->tex + tile * 2 * 6; float *tex = p->tex + tile * 2 * 6;
lightCell fm=foreMult[tile]; rgbf fm=foreMult[tile];
lightCell fo=foreOffset[tile]; rgbf fo=foreOffset[tile];
lightCell bm=backMult[tile]; rgbf bm=backMult[tile];
lightCell bo=backOffset[tile]; rgbf bo=backOffset[tile];
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
rgba* fore=reinterpret_cast<rgba*>(fg); rgba* fore=reinterpret_cast<rgba*>(fg);
fore->r=fore->r*fm.r+fo.r; fore->r=fore->r*fm.r+fo.r;
@ -365,8 +365,8 @@ private:
} }
public: public:
tthread::fast_mutex dataMutex; tthread::fast_mutex dataMutex;
std::vector<lightCell> foreOffset,foreMult; std::vector<rgbf> foreOffset,foreMult;
std::vector<lightCell> backOffset,backMult; std::vector<rgbf> backOffset,backMult;
inline int xyToTile(int x, int y) inline int xyToTile(int x, int y)
{ {
return x*(df::global::gps->dimy) + y; return x*(df::global::gps->dimy) + y;

@ -121,10 +121,10 @@ static void resetGrids()
renderer_lua* r=reinterpret_cast<renderer_lua*>(df::global::enabler->renderer); renderer_lua* r=reinterpret_cast<renderer_lua*>(df::global::enabler->renderer);
for(size_t i=0;i<r->foreMult.size();i++) for(size_t i=0;i<r->foreMult.size();i++)
{ {
r->foreMult[i]=lightCell(1,1,1); r->foreMult[i]=rgbf(1,1,1);
r->foreOffset[i]=lightCell(0,0,0); r->foreOffset[i]=rgbf(0,0,0);
r->backMult[i]=lightCell(1,1,1); r->backMult[i]=rgbf(1,1,1);
r->backOffset[i]=lightCell(0,0,0); r->backOffset[i]=rgbf(0,0,0);
} }
} }
static int getGridsSize(lua_State* L) static int getGridsSize(lua_State* L)
@ -144,10 +144,10 @@ static int getCell(lua_State* L)
int x=luaL_checknumber(L,1); int x=luaL_checknumber(L,1);
int y=luaL_checknumber(L,2); int y=luaL_checknumber(L,2);
int id=r->xyToTile(x,y); int id=r->xyToTile(x,y);
lightCell fo=r->foreOffset[id]; rgbf fo=r->foreOffset[id];
lightCell fm=r->foreMult[id]; rgbf fm=r->foreMult[id];
lightCell bo=r->backOffset[id]; rgbf bo=r->backOffset[id];
lightCell bm=r->backMult[id]; rgbf bm=r->backMult[id];
lua_newtable(L); lua_newtable(L);
lua_newtable(L); lua_newtable(L);
@ -195,7 +195,7 @@ static int setCell(lua_State* L)
int x=luaL_checknumber(L,1); int x=luaL_checknumber(L,1);
int y=luaL_checknumber(L,2); int y=luaL_checknumber(L,2);
lightCell fo; rgbf fo;
lua_getfield(L,3,"fo"); lua_getfield(L,3,"fo");
lua_getfield(L,-1,"r"); lua_getfield(L,-1,"r");
fo.r=lua_tonumber(L,-1);lua_pop(L,1); fo.r=lua_tonumber(L,-1);lua_pop(L,1);
@ -203,7 +203,7 @@ static int setCell(lua_State* L)
fo.g=lua_tonumber(L,-1);lua_pop(L,1); fo.g=lua_tonumber(L,-1);lua_pop(L,1);
lua_getfield(L,-1,"b"); lua_getfield(L,-1,"b");
fo.b=lua_tonumber(L,-1);lua_pop(L,1); fo.b=lua_tonumber(L,-1);lua_pop(L,1);
lightCell fm; rgbf fm;
lua_getfield(L,3,"fm"); lua_getfield(L,3,"fm");
lua_getfield(L,-1,"r"); lua_getfield(L,-1,"r");
fm.r=lua_tonumber(L,-1);lua_pop(L,1); fm.r=lua_tonumber(L,-1);lua_pop(L,1);
@ -212,7 +212,7 @@ static int setCell(lua_State* L)
lua_getfield(L,-1,"b"); lua_getfield(L,-1,"b");
fm.b=lua_tonumber(L,-1);lua_pop(L,1); fm.b=lua_tonumber(L,-1);lua_pop(L,1);
lightCell bo; rgbf bo;
lua_getfield(L,3,"bo"); lua_getfield(L,3,"bo");
lua_getfield(L,-1,"r"); lua_getfield(L,-1,"r");
bo.r=lua_tonumber(L,-1);lua_pop(L,1); bo.r=lua_tonumber(L,-1);lua_pop(L,1);
@ -221,7 +221,7 @@ static int setCell(lua_State* L)
lua_getfield(L,-1,"b"); lua_getfield(L,-1,"b");
bo.b=lua_tonumber(L,-1);lua_pop(L,1); bo.b=lua_tonumber(L,-1);lua_pop(L,1);
lightCell bm; rgbf bm;
lua_getfield(L,3,"bm"); lua_getfield(L,3,"bm");
lua_getfield(L,-1,"r"); lua_getfield(L,-1,"r");
bm.r=lua_tonumber(L,-1);lua_pop(L,1); bm.r=lua_tonumber(L,-1);lua_pop(L,1);
@ -307,9 +307,9 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
} }
if(current_mode==MODE_TRUECOLOR && parameters.size()==2) if(current_mode==MODE_TRUECOLOR && parameters.size()==2)
{ {
lightCell red(1,0,0),green(0,1,0),blue(0,0,1),white(1,1,1); rgbf red(1,0,0),green(0,1,0),blue(0,0,1),white(1,1,1);
lightCell cur=white; rgbf cur=white;
lightCell dim(0.2f,0.2f,0.2f); rgbf dim(0.2f,0.2f,0.2f);
string col=parameters[1]; string col=parameters[1];
if(col=="red") if(col=="red")
cur=red; cur=red;