Move some checks in paintTile/readTile after hooks are called

develop
lethosor 2017-06-02 00:40:14 -04:00
parent 346e8b91a9
commit 43c4a88068
3 changed files with 23 additions and 23 deletions

@ -298,7 +298,7 @@ namespace DFHack
namespace Hooks { namespace Hooks {
GUI_HOOK_DECLARE(get_tile, Pen, (int x, int y, bool map)); GUI_HOOK_DECLARE(get_tile, Pen, (int x, int y, bool map));
GUI_HOOK_DECLARE(set_tile, void, (const Pen &pen, int x, int y, bool map)); GUI_HOOK_DECLARE(set_tile, bool, (const Pen &pen, int x, int y, bool map));
} }
} }

@ -95,8 +95,12 @@ bool Screen::inGraphicsMode()
return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS); return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS);
} }
static void doSetTile_default(const Pen &pen, int x, int y, bool map) static bool doSetTile_default(const Pen &pen, int x, int y, bool map)
{ {
auto dim = Screen::getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return false;
int index = ((x * gps->dimy) + y); int index = ((x * gps->dimy) + y);
auto screen = gps->screen + index*4; auto screen = gps->screen + index*4;
screen[0] = uint8_t(pen.ch); screen[0] = uint8_t(pen.ch);
@ -108,10 +112,12 @@ static void doSetTile_default(const Pen &pen, int x, int y, bool map)
gps->screentexpos_grayscale[index] = (pen.tile_mode == Screen::Pen::TileColor); gps->screentexpos_grayscale[index] = (pen.tile_mode == Screen::Pen::TileColor);
gps->screentexpos_cf[index] = pen.tile_fg; gps->screentexpos_cf[index] = pen.tile_fg;
gps->screentexpos_cbr[index] = pen.tile_bg; gps->screentexpos_cbr[index] = pen.tile_bg;
return true;
} }
GUI_HOOK_DEFINE(Screen::Hooks::set_tile, doSetTile_default); GUI_HOOK_DEFINE(Screen::Hooks::set_tile, doSetTile_default);
static void doSetTile(const Pen &pen, int x, int y, bool map) static bool doSetTile(const Pen &pen, int x, int y, bool map)
{ {
GUI_HOOK_TOP(Screen::Hooks::set_tile)(pen, x, y, map); GUI_HOOK_TOP(Screen::Hooks::set_tile)(pen, x, y, map);
} }
@ -120,9 +126,6 @@ bool Screen::paintTile(const Pen &pen, int x, int y, bool map)
{ {
if (!gps || !pen.valid()) return false; if (!gps || !pen.valid()) return false;
auto dim = getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y) return false;
doSetTile(pen, x, y, map); doSetTile(pen, x, y, map);
return true; return true;
} }
@ -130,8 +133,14 @@ bool Screen::paintTile(const Pen &pen, int x, int y, bool map)
static Pen doGetTile_default(int x, int y, bool map) static Pen doGetTile_default(int x, int y, bool map)
{ {
auto dim = Screen::getWindowSize(); auto dim = Screen::getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return Pen(0,0,0,-1);
int index = x*dim.y + y; int index = x*dim.y + y;
auto screen = gps->screen + index*4; auto screen = gps->screen + index*4;
if (screen[3] & 0x80)
return Pen(0,0,0,-1);
Pen pen( Pen pen(
screen[0], screen[1], screen[2], screen[3]?true:false, screen[0], screen[1], screen[2], screen[3]?true:false,
gps->screentexpos[index] gps->screentexpos[index]
@ -164,15 +173,6 @@ Pen Screen::readTile(int x, int y, bool map)
{ {
if (!gps) return Pen(0,0,0,-1); if (!gps) return Pen(0,0,0,-1);
auto dim = getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return Pen(0,0,0,-1);
int index = x*dim.y + y;
auto screen = gps->screen + index*4;
if (screen[3] & 0x80)
return Pen(0,0,0,-1);
return doGetTile(x, y, map); return doGetTile(x, y, map);
} }

@ -19,9 +19,9 @@ struct {
uint8_t tick; uint8_t tick;
} config; } config;
void color_text_tile(const Screen::Pen &pen, int x, int y, bool map); bool color_text_tile(const Screen::Pen &pen, int x, int y, bool map);
GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, color_text_hook, color_text_tile); GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, color_text_hook, color_text_tile);
void color_text_tile(const Screen::Pen &pen, int x, int y, bool map) bool color_text_tile(const Screen::Pen &pen, int x, int y, bool map)
{ {
Screen::Pen pen2 = pen; Screen::Pen pen2 = pen;
uint8_t color = config.flicker ? config.tick % 8 : config.color; uint8_t color = config.flicker ? config.tick % 8 : config.color;
@ -40,24 +40,24 @@ void color_text_tile(const Screen::Pen &pen, int x, int y, bool map)
return color_text_hook.next()(pen2, x, y, map); return color_text_hook.next()(pen2, x, y, map);
} }
void aaaaa_set_tile(const Screen::Pen &pen, int x, int y, bool map); bool aaaaa_set_tile(const Screen::Pen &pen, int x, int y, bool map);
GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, aaaaa_set_tile_hook, aaaaa_set_tile); GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, aaaaa_set_tile_hook, aaaaa_set_tile);
void aaaaa_set_tile(const Screen::Pen &pen, int x, int y, bool map) bool aaaaa_set_tile(const Screen::Pen &pen, int x, int y, bool map)
{ {
Screen::Pen pen2 = pen; Screen::Pen pen2 = pen;
if ((pen.ch >= 'A' && pen.ch <= 'Z') || (pen.ch >= '0' && pen.ch <= '9')) if ((pen.ch >= 'A' && pen.ch <= 'Z') || (pen.ch >= '0' && pen.ch <= '9'))
pen2.ch = 'A'; pen2.ch = 'A';
else if (pen.ch >= 'a' && pen.ch <= 'z') else if (pen.ch >= 'a' && pen.ch <= 'z')
pen2.ch = 'a'; pen2.ch = 'a';
aaaaa_set_tile_hook.next()(pen2, x, y, map); return aaaaa_set_tile_hook.next()(pen2, x, y, map);
} }
void shift_set_tile(const Screen::Pen &pen, int x, int y, bool map); bool shift_set_tile(const Screen::Pen &pen, int x, int y, bool map);
GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, shift_set_tile_hook, shift_set_tile); GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, shift_set_tile_hook, shift_set_tile);
void shift_set_tile(const Screen::Pen &pen, int x, int y, bool map) bool shift_set_tile(const Screen::Pen &pen, int x, int y, bool map)
{ {
x = (x + 1) % gps->dimx; x = (x + 1) % gps->dimx;
shift_set_tile_hook.next()(pen, x, y, map); return shift_set_tile_hook.next()(pen, x, y, map);
} }
DFhackCExport command_result plugin_enable (color_ostream &out, bool enable) DFhackCExport command_result plugin_enable (color_ostream &out, bool enable)