Forgot to add the plugin itself. Also some improvements

develop
Warmist 2013-06-22 13:29:58 +03:00
parent 55d845992c
commit f68852b721
2 changed files with 148 additions and 1 deletions

@ -1,4 +1,7 @@
//original file from https://github.com/Baughn/Dwarf-Fortress--libgraphics- //original file from https://github.com/Baughn/Dwarf-Fortress--libgraphics-
#include "tinythread.h"
#include "fast_mutex.h"
#include "Core.h" #include "Core.h"
#include <VTableInterpose.h> #include <VTableInterpose.h>
#include "df/renderer.h" #include "df/renderer.h"
@ -165,20 +168,65 @@ public:
}; };
struct renderer_test : public renderer_wrap { struct renderer_test : public renderer_wrap {
private: private:
void colorizeTile(int x,int y)
{
const int tile = x*(df::global::gps->dimy) + y;
old_opengl* p=reinterpret_cast<old_opengl*>(parent);
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];
for (int i = 0; i < 6; i++) {
*(fg++) *= v;
*(fg++) *= v;
*(fg++) *= v;
*(fg++) = 1;
*(bg++) *= v;
*(bg++) *= v;
*(bg++) *= v;
*(bg++) = 1;
}
}
void reinitOpacity(int w,int h)
{
tthread::lock_guard<tthread::fast_mutex> guard(dataMutex);
opacity.resize(w*h);
}
void reinitOpacity()
{
reinitOpacity(df::global::gps->dimy,df::global::gps->dimx);
}
public: public:
tthread::fast_mutex dataMutex;
std::vector<float> opacity;
renderer_test(renderer* parent):renderer_wrap(parent) renderer_test(renderer* parent):renderer_wrap(parent)
{ {
reinitOpacity();
} }
virtual void update_tile(int32_t x, int32_t y) { virtual void update_tile(int32_t x, int32_t y) {
renderer_wrap::update_tile(x,y); renderer_wrap::update_tile(x,y);
tthread::lock_guard<tthread::fast_mutex> guard(dataMutex);
colorizeTile(x,y);
//some sort of mutex or sth? //some sort of mutex or sth?
//and then map read //and then map read
}; };
virtual void update_all() { virtual void update_all() {
renderer_wrap::update_all(); renderer_wrap::update_all();
tthread::lock_guard<tthread::fast_mutex> guard(dataMutex);
for (int x = 0; x < df::global::gps->dimx; x++)
for (int y = 0; y < df::global::gps->dimy; y++)
colorizeTile(x,y);
//some sort of mutex or sth? //some sort of mutex or sth?
//and then map read //and then map read
//same stuff for all of them i guess... //same stuff for all of them i guess...
}; };
virtual void grid_resize(int32_t w, int32_t h) {
renderer_wrap::grid_resize(w,h);
reinitOpacity(w,h);
};
virtual void resize(int32_t w, int32_t h) {
renderer_wrap::resize(w,h);
reinitOpacity(w,h);
}
}; };

@ -0,0 +1,99 @@
#include <vector>
#include <string>
#include "Core.h"
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include <VTableInterpose.h>
#include "df/renderer.h"
#include "df/enabler.h"
#include "renderer_opengl.hpp"
using namespace DFHack;
using std::vector;
using std::string;
enum RENDERER_MODE
{
MODE_DEFAULT,MODE_TRIPPY,MODE_TRUECOLOR
};
RENDERER_MODE current_mode=MODE_DEFAULT;
static command_result rendermax(color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("rendermax");
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand(
"rendermax", "switch rendering engine.", rendermax, false,
" rendermax trippy\n"
" rendermax disable\n"
));
return CR_OK;
}
void removeOld()
{
if(current_mode!=MODE_DEFAULT)
delete df::global::enabler->renderer;
current_mode=MODE_DEFAULT;
}
void installNew(df::renderer* r,RENDERER_MODE newMode)
{
df::global::enabler->renderer=r;
current_mode=newMode;
}
static command_result rendermax(color_ostream &out, vector <string> & parameters)
{
if(parameters.size()==0)
return CR_WRONG_USAGE;
string cmd=parameters[0];
if(cmd=="trippy")
{
removeOld();
installNew(new renderer_trippy(df::global::enabler->renderer),MODE_TRIPPY);
return CR_OK;
}
else if(cmd=="test")
{
if(current_mode==MODE_TRUECOLOR && parameters.size()==2)
{
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;
int w=df::global::gps->dimx;
int cx=w/2;
int cy=h/2;
int rad=cx;
if(rad>cy)rad=cy;
rad/=2;
int radsq=rad*rad;
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;
}
return CR_OK;
}
else
{
removeOld();
installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR);
return CR_OK;
}
}
else if(cmd=="disable")
{
if(current_mode==MODE_DEFAULT)
out.print("%s\n","Not installed, doing nothing.");
else
removeOld();
return CR_OK;
}
return CR_WRONG_USAGE;
}