diff --git a/library/Core.cpp b/library/Core.cpp index 111774f26..26c0acbb0 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -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); diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index d89b3688d..e8d23261b 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -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 > *keydisplay = NULL; void init_screen_module(Core *core) { #ifdef _LINUX - core = core; + renderer tmp; + if (!strict_virtual_cast((virtual_ptr)&tmp)) + cerr << "Could not fetch the renderer vtable." << std::endl; #else if (!core->vinfo->getAddress("keydisplay", keydisplay)) keydisplay = NULL; diff --git a/library/xml b/library/xml index 4bfc5b197..378f91d09 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 4bfc5b197de9ca096a11b9c1594e043bd8ae707a +Subproject commit 378f91d0964e09e3cfa0ecbea100ef2cc12a59ab diff --git a/plugins/dfstream.cpp b/plugins/dfstream.cpp index a7bc1015e..6144389d7 100644 --- a/plugins/dfstream.cpp +++ b/plugins/dfstream.cpp @@ -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 &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