Added help for truecolor light testing thing. Also added colors.

develop
Warmist 2013-06-22 14:14:35 +03:00
parent f68852b721
commit 584640f12c
2 changed files with 63 additions and 23 deletions

@ -166,6 +166,27 @@ public:
colorizeTile(x,y);
};
};
struct lightCell
{
float r,g,b;
lightCell():r(0),g(0),b(0)
{
}
lightCell(float r,float g,float b):r(r),g(g),b(b)
{
}
lightCell operator*(float val)
{
return lightCell(r*val,g*val,b*val);
}
lightCell operator+(const lightCell& other)
{
return lightCell(r+other.r,g+other.g,b+other.b);
}
};
struct renderer_test : public renderer_wrap {
private:
void colorizeTile(int x,int y)
@ -175,34 +196,34 @@ private:
float *fg = p->fg + tile * 4 * 6;
float *bg = p->bg + tile * 4 * 6;
float *tex = p->tex + tile * 2 * 6;
float v=opacity[tile];
lightCell light=lightGrid[tile];
for (int i = 0; i < 6; i++) {
*(fg++) *= v;
*(fg++) *= v;
*(fg++) *= v;
*(fg++) *= light.r;
*(fg++) *= light.g;
*(fg++) *= light.b;
*(fg++) = 1;
*(bg++) *= v;
*(bg++) *= v;
*(bg++) *= v;
*(bg++) *= light.r;
*(bg++) *= light.g;
*(bg++) *= light.b;
*(bg++) = 1;
}
}
void reinitOpacity(int w,int h)
void reinitLightGrid(int w,int h)
{
tthread::lock_guard<tthread::fast_mutex> guard(dataMutex);
opacity.resize(w*h);
lightGrid.resize(w*h);
}
void reinitOpacity()
void reinitLightGrid()
{
reinitOpacity(df::global::gps->dimy,df::global::gps->dimx);
reinitLightGrid(df::global::gps->dimy,df::global::gps->dimx);
}
public:
tthread::fast_mutex dataMutex;
std::vector<float> opacity;
std::vector<lightCell> lightGrid;
renderer_test(renderer* parent):renderer_wrap(parent)
{
reinitOpacity();
reinitLightGrid();
}
virtual void update_tile(int32_t x, int32_t y) {
renderer_wrap::update_tile(x,y);
@ -223,10 +244,10 @@ public:
};
virtual void grid_resize(int32_t w, int32_t h) {
renderer_wrap::grid_resize(w,h);
reinitOpacity(w,h);
reinitLightGrid(w,h);
};
virtual void resize(int32_t w, int32_t h) {
renderer_wrap::resize(w,h);
reinitOpacity(w,h);
reinitLightGrid(w,h);
}
};

@ -30,6 +30,7 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
commands.push_back(PluginCommand(
"rendermax", "switch rendering engine.", rendermax, false,
" rendermax trippy\n"
" rendermax truecolor red|green|blue|white\n"
" rendermax disable\n"
));
return CR_OK;
@ -56,10 +57,26 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
installNew(new renderer_trippy(df::global::enabler->renderer),MODE_TRIPPY);
return CR_OK;
}
else if(cmd=="test")
else if(cmd=="truecolor")
{
if(current_mode!=MODE_TRUECOLOR)
{
removeOld();
installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR);
}
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);
lightCell cur=white;
lightCell dim(0.2,0.2,0.2);
string col=parameters[1];
if(col=="red")
cur=red;
else if(col=="green")
cur=green;
else if(col=="blue")
cur=blue;
renderer_test* r=reinterpret_cast<renderer_test*>(df::global::enabler->renderer);
tthread::lock_guard<tthread::fast_mutex> guard(r->dataMutex);
int h=df::global::gps->dimy;
@ -70,20 +87,22 @@ static command_result rendermax(color_ostream &out, vector <string> & parameters
if(rad>cy)rad=cy;
rad/=2;
int radsq=rad*rad;
for(size_t i=0;i<r->lightGrid.size();i++)
{
r->lightGrid[i]=dim;
}
for(int i=-rad;i<rad;i++)
for(int j=-rad;j<rad;j++)
{
if((i*i+j*j)<radsq)
r->opacity[(cx+i)*h+(cy+j)]=(radsq-i*i-j*j)/(float)radsq;
{
float val=(radsq-i*i-j*j)/(float)radsq;
r->lightGrid[(cx+i)*h+(cy+j)]=dim+cur*val;
}
}
return CR_OK;
}
else
{
removeOld();
installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR);
return CR_OK;
}
}
else if(cmd=="disable")