From 839e927f9b48d52c57c60423e7f9d6606c3ad1d8 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 21 Dec 2022 14:06:58 -0800 Subject: [PATCH 1/4] comment out problematic code from Renderer --- library/include/modules/Renderer.h | 10 +++------- library/modules/Renderer.cpp | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/library/include/modules/Renderer.h b/library/include/modules/Renderer.h index 65a9694ab..e01af17cd 100644 --- a/library/include/modules/Renderer.h +++ b/library/include/modules/Renderer.h @@ -5,13 +5,6 @@ #pragma once namespace DFHack { namespace Renderer { - // If the the 'x' parameter points to this value, then the 'y' parameter will - // be interpreted as a boolean flag for whether to return map coordinates (false) - // or text tile coordinates (true). Only TWBT implements this logic, and this - // sentinel value can be removed once DF provides an API for retrieving the - // two sets of coordinates. - DFHACK_EXPORT extern const int32_t GET_MOUSE_COORDS_SENTINEL; - struct DFHACK_EXPORT renderer_wrap : public df::renderer { void set_to_null(); void copy_from_parent(); @@ -32,6 +25,8 @@ namespace DFHack { namespace Renderer { virtual bool get_mouse_coords(int32_t *x, int32_t *y); virtual bool uses_opengl(); }; + + /* TODO: we can't cat enabler->renderer to renderer_wrap and expect it to work // Returns the renderer instance given on success, or deletes it and returns NULL on failure // Usage: renderer_foo *r = AddRenderer(new renderer_foo) DFHACK_EXPORT renderer_wrap *AddRenderer(renderer_wrap*, bool refresh_screen = false); @@ -42,4 +37,5 @@ namespace DFHack { namespace Renderer { { return (renderer_wrap*)(df::global::enabler ? df::global::enabler->renderer : NULL); } + */ }} diff --git a/library/modules/Renderer.cpp b/library/modules/Renderer.cpp index b746a149c..e134fa4f3 100644 --- a/library/modules/Renderer.cpp +++ b/library/modules/Renderer.cpp @@ -7,10 +7,9 @@ using df::global::enabler; using df::global::gps; using DFHack::Renderer::renderer_wrap; +/* static renderer_wrap *original_renderer = NULL; -const int32_t Renderer::GET_MOUSE_COORDS_SENTINEL = 0xcd1aa471; - bool init() { if (!original_renderer) @@ -156,3 +155,4 @@ bool Renderer::renderer_wrap::get_mouse_coords(int32_t* x, int32_t* y) { bool Renderer::renderer_wrap::uses_opengl() { return parent->uses_opengl(); }; +*/ From 93c875fb5636e38bd43d62be025be547f46449f0 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 21 Dec 2022 14:07:36 -0800 Subject: [PATCH 2/4] adjust to new variable names --- library/modules/Gui.cpp | 2 +- library/modules/Screen.cpp | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index e75ab41af..d3055c5af 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -2150,7 +2150,7 @@ bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t df::coord Gui::getMousePos() { df::coord pos; - if (gps && gps->mouse_x_pixel > -1) { + if (gps && gps->precise_mouse_x > -1) { pos = getViewportPos(); /* TODO: understand how this changes for v50 pos.x += gps->mouse_x_pixel / tile_width; diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 351515740..f3fce920a 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -87,7 +87,7 @@ df::coord2d Screen::getMousePos() { if (!gps) return df::coord2d(-1, -1); - return df::coord2d(gps->mouse_x_tile, gps->mouse_y_tile); + return df::coord2d(gps->mouse_x, gps->mouse_y); } // returns the screen pixel coordinates @@ -95,7 +95,7 @@ df::coord2d Screen::getMousePixels() { if (!gps) return df::coord2d(-1, -1); - return df::coord2d(gps->mouse_x_pixel, gps->mouse_y_pixel); + return df::coord2d(gps->precise_mouse_x, gps->precise_mouse_y); } df::coord2d Screen::getWindowSize() @@ -114,21 +114,6 @@ bool Screen::inGraphicsMode() return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS); } -static int32_t flood_clear(int32_t target, size_t index, size_t max_idx) { - if (index >= max_idx || !gps->screen1_offset_tile[index] - || gps->screen1_offset_tile[index] != target) - return 0; - gps->screen1_offset_tile[index] = 0; - gps->screen1_offset_x[index] = 0; - gps->screen1_offset_y[index] = 0; - int32_t cleared = 1; - cleared += flood_clear(target, index - 1, max_idx); - cleared += flood_clear(target, index + 1, max_idx); - cleared += flood_clear(target, index - gps->dimy, max_idx); - cleared += flood_clear(target, index + gps->dimy, max_idx); - return cleared; -} - static bool doSetTile_default(const Pen &pen, int x, int y, bool map) { auto dim = Screen::getWindowSize(); @@ -136,6 +121,7 @@ static bool doSetTile_default(const Pen &pen, int x, int y, bool map) return false; // TODO: understand how this changes for v50 +/* size_t index = ((x * gps->dimy) + y); if (!map) { // don't let DF overlay interface elements draw over us @@ -160,6 +146,7 @@ static bool doSetTile_default(const Pen &pen, int x, int y, bool map) argb[4] = bg[0]; argb[5] = bg[1]; argb[6] = bg[2]; +*/ /* old code // auto screen = gps->screen + index*4; // screen[0] = uint8_t(pen.ch); From 48a9e1c5183613db816e9adecdf5584d61995c51 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 21 Dec 2022 20:14:12 -0800 Subject: [PATCH 3/4] more new var names --- library/include/modules/Renderer.h | 9 --------- library/modules/Screen.cpp | 10 ++++++---- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/library/include/modules/Renderer.h b/library/include/modules/Renderer.h index e01af17cd..864efd8c1 100644 --- a/library/include/modules/Renderer.h +++ b/library/include/modules/Renderer.h @@ -12,18 +12,9 @@ namespace DFHack { namespace Renderer { renderer_wrap *parent; renderer_wrap *child; - virtual void update_tile(int32_t x, int32_t y); - virtual void update_all(); - virtual void render(); - virtual void set_fullscreen(); - virtual void zoom(df::zoom_commands z); - virtual void resize(int32_t w, int32_t h); - virtual void grid_resize(int32_t w, int32_t h); virtual ~renderer_wrap() { // All necessary cleanup should be handled by RemoveRenderer() }; - virtual bool get_mouse_coords(int32_t *x, int32_t *y); - virtual bool uses_opengl(); }; /* TODO: we can't cat enabler->renderer to renderer_wrap and expect it to work diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index f3fce920a..c15a41afc 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -54,6 +54,7 @@ using namespace DFHack; #include "df/tile_page.h" #include "df/interfacest.h" #include "df/enabler.h" +#include "df/graphic_map_portst.h" #include "df/unit.h" #include "df/item.h" #include "df/job.h" @@ -116,10 +117,11 @@ bool Screen::inGraphicsMode() 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; - + df::graphic_map_portst *vp = gps->main_map_port; + if (x >= vp->clipx[0] && x <= vp->clipx[1] + && y >= vp->clipy[0] && y <= vp->clipy[1]) { + vp->screentexpos_interface[x + y*vp->dim_x] = pen.tile; + } // TODO: understand how this changes for v50 /* size_t index = ((x * gps->dimy) + y); From 52c1e49197c90d7fae7d0a5795fc19a213107f45 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 21 Dec 2022 22:13:05 -0800 Subject: [PATCH 4/4] get the text rendering back --- library/modules/Screen.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index c15a41afc..2d51b8e20 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -117,30 +117,18 @@ bool Screen::inGraphicsMode() static bool doSetTile_default(const Pen &pen, int x, int y, bool map) { - df::graphic_map_portst *vp = gps->main_map_port; - if (x >= vp->clipx[0] && x <= vp->clipx[1] - && y >= vp->clipy[0] && y <= vp->clipy[1]) { - vp->screentexpos_interface[x + y*vp->dim_x] = pen.tile; - } // TODO: understand how this changes for v50 -/* size_t index = ((x * gps->dimy) + y); if (!map) { // don't let DF overlay interface elements draw over us - gps->screen1_forced_tile[index] = 0; - gps->screen1_flags[index] = 0; - // the DF renderer can't handle partial offset tiles. make sure we clear - // the whole thing if we hit any part of it - int32_t cleared = flood_clear(gps->screen1_offset_tile[index], index, - (gps->dimx*gps->dimy)-1); - if (cleared) { - DEBUG(screen).print("offset tiles cleared: %d\n", cleared); - } + gps->screentexpos_anchored[index] = 0; + gps->screentexpos_top[index] = 0; + gps->screentexpos_flag[index] = 0; } //gps->screen1_opt_tile[index] = uint8_t(pen.tile); - auto fg = &gps->palette[pen.fg][0]; - auto bg = &gps->palette[pen.bg][0]; - auto argb = &gps->screen1_asciirgb[index * 8]; + auto fg = &gps->uccolor[pen.fg][0]; + auto bg = &gps->uccolor[pen.bg][0]; + auto argb = &gps->screen[index * 8]; argb[0] = uint8_t(pen.ch); argb[1] = fg[0]; argb[2] = fg[1]; @@ -148,7 +136,6 @@ static bool doSetTile_default(const Pen &pen, int x, int y, bool map) argb[4] = bg[0]; argb[5] = bg[1]; argb[6] = bg[2]; -*/ /* old code // auto screen = gps->screen + index*4; // screen[0] = uint8_t(pen.ch);