Link the renderer vtable from libgraphics on linux.

develop
Alexander Gavrilov 2012-10-30 10:38:32 +04:00
parent cd14bdfd43
commit dc2805b1f3
4 changed files with 75 additions and 19 deletions

@ -869,7 +869,6 @@ bool Core::Init()
// Init global object pointers
df::global::InitGlobals();
init_screen_module(this);
cerr << "Initializing Console.\n";
// init the console.
@ -895,6 +894,7 @@ bool Core::Init()
*/
// initialize data defs
virtual_identity::Init(this);
init_screen_module(this);
// initialize common lua context
Lua::Core::Init(con);

@ -55,6 +55,7 @@ using namespace DFHack;
#include "df/item.h"
#include "df/job.h"
#include "df/building.h"
#include "df/renderer.h"
using namespace df::enums;
using df::global::init;
@ -312,6 +313,47 @@ class DFHACK_EXPORT enabler_inputst {
public:
std::string GetKeyDisplay(int binding);
};
class DFHACK_EXPORT renderer {
unsigned char *screen;
long *screentexpos;
char *screentexpos_addcolor;
unsigned char *screentexpos_grayscale;
unsigned char *screentexpos_cf;
unsigned char *screentexpos_cbr;
// For partial printing:
unsigned char *screen_old;
long *screentexpos_old;
char *screentexpos_addcolor_old;
unsigned char *screentexpos_grayscale_old;
unsigned char *screentexpos_cf_old;
unsigned char *screentexpos_cbr_old;
public:
virtual void update_tile(int x, int y) {};
virtual void update_all() {};
virtual void render() {};
virtual void set_fullscreen();
virtual void zoom(df::zoom_commands cmd);
virtual void resize(int w, int h) {};
virtual void grid_resize(int w, int h) {};
renderer() {
screen = NULL;
screentexpos = NULL;
screentexpos_addcolor = NULL;
screentexpos_grayscale = NULL;
screentexpos_cf = NULL;
screentexpos_cbr = NULL;
screen_old = NULL;
screentexpos_old = NULL;
screentexpos_addcolor_old = NULL;
screentexpos_grayscale_old = NULL;
screentexpos_cf_old = NULL;
screentexpos_cbr_old = NULL;
}
virtual ~renderer();
virtual bool get_mouse_coords(int &x, int &y) { return false; }
virtual bool uses_opengl();
};
#else
struct less_sz {
bool operator() (const string &a, const string &b) const {
@ -326,7 +368,9 @@ static std::map<df::interface_key,std::set<string,less_sz> > *keydisplay = NULL;
void init_screen_module(Core *core)
{
#ifdef _LINUX
core = core;
renderer tmp;
if (!strict_virtual_cast<df::renderer>((virtual_ptr)&tmp))
cerr << "Could not fetch the renderer vtable." << std::endl;
#else
if (!core->vinfo->getAddress("keydisplay", keydisplay))
keydisplay = NULL;

@ -1 +1 @@
Subproject commit 4bfc5b197de9ca096a11b9c1594e043bd8ae707a
Subproject commit 378f91d0964e09e3cfa0ecbea100ef2cc12a59ab

@ -148,19 +148,19 @@ class renderer_decorator : public df::renderer {
client_pool clients;
// The following three methods facilitate copying of state to the inner object
void set_inner_to_null() {
inner->screen = NULL;
inner->screentexpos = NULL;
inner->screentexpos_addcolor = NULL;
inner->screentexpos_grayscale = NULL;
inner->screentexpos_cf = NULL;
inner->screentexpos_cbr = NULL;
inner->screen_old = NULL;
inner->screentexpos_old = NULL;
inner->screentexpos_addcolor_old = NULL;
inner->screentexpos_grayscale_old = NULL;
inner->screentexpos_cf_old = NULL;
inner->screentexpos_cbr_old = NULL;
void set_to_null() {
screen = NULL;
screentexpos = NULL;
screentexpos_addcolor = NULL;
screentexpos_grayscale = NULL;
screentexpos_cf = NULL;
screentexpos_cbr = NULL;
screen_old = NULL;
screentexpos_old = NULL;
screentexpos_addcolor_old = NULL;
screentexpos_grayscale_old = NULL;
screentexpos_cf_old = NULL;
screentexpos_cbr_old = NULL;
}
void copy_from_inner() {
@ -259,9 +259,12 @@ public:
}
virtual ~renderer_decorator() {
*alive = false;
if (inner) set_inner_to_null();
delete inner;
inner = 0;
if (inner) {
copy_to_inner();
delete inner;
inner = 0;
}
set_to_null();
}
virtual bool get_mouse_coords(int *x, int *y) { return inner->get_mouse_coords(x, y); }
virtual bool uses_opengl() { return inner->uses_opengl(); }
@ -336,6 +339,11 @@ auto_renderer_decorator decorator;
DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCommand> &commands)
{
if (!df::renderer::_identity.can_allocate())
{
out.printerr("Cannot allocate a renderer\n");
return CR_OK;
}
if (!decorator) {
decorator = renderer_decorator::hook(active_renderer(), &decorator.alive);
}
@ -344,6 +352,10 @@ DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCom
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
if (decorator && active_renderer() == decorator.get())
{
renderer_decorator::unhook(active_renderer(), decorator.get(), out);
}
decorator.reset();
return CR_OK;
}