Merge pull request #2513 from myk002/myk_more

Get extremely basic ascii rendering working
develop
Myk 2022-12-20 14:17:10 -08:00 committed by GitHub
commit 0766d85759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 33 deletions

@ -68,6 +68,7 @@ static int32_t eventLastTick[EventType::EVENT_MAX];
static const int32_t ticksPerYear = 403200; static const int32_t ticksPerYear = 403200;
void DFHack::EventManager::registerListener(EventType::EventType e, EventHandler handler, Plugin* plugin) { void DFHack::EventManager::registerListener(EventType::EventType e, EventHandler handler, Plugin* plugin) {
DEBUG(log).print("registering handler %p from plugin %s for event %d\n", handler.eventHandler, plugin->getName().c_str(), e);
handlers[e].insert(pair<Plugin*, EventHandler>(plugin, handler)); handlers[e].insert(pair<Plugin*, EventHandler>(plugin, handler));
} }
@ -83,6 +84,7 @@ int32_t DFHack::EventManager::registerTick(EventHandler handler, int32_t when, P
} }
handler.freq = when; handler.freq = when;
tickQueue.insert(pair<int32_t, EventHandler>(handler.freq, handler)); tickQueue.insert(pair<int32_t, EventHandler>(handler.freq, handler));
DEBUG(log).print("registering handler %p from plugin %s for event TICK\n", handler.eventHandler, plugin->getName().c_str());
handlers[EventType::TICK].insert(pair<Plugin*,EventHandler>(plugin,handler)); handlers[EventType::TICK].insert(pair<Plugin*,EventHandler>(plugin,handler));
return when; return when;
} }
@ -108,6 +110,7 @@ void DFHack::EventManager::unregister(EventType::EventType e, EventHandler handl
i++; i++;
continue; continue;
} }
DEBUG(log).print("unregistering handler %p from plugin %s for event %d\n", handler.eventHandler, plugin->getName().c_str(), e);
i = handlers[e].erase(i); i = handlers[e].erase(i);
if ( e == EventType::TICK ) if ( e == EventType::TICK )
removeFromTickQueue(handler); removeFromTickQueue(handler);
@ -115,6 +118,7 @@ void DFHack::EventManager::unregister(EventType::EventType e, EventHandler handl
} }
void DFHack::EventManager::unregisterAll(Plugin* plugin) { void DFHack::EventManager::unregisterAll(Plugin* plugin) {
DEBUG(log).print("unregistering all handlers for plugin %s\n", plugin->getName().c_str());
for ( auto i = handlers[EventType::TICK].find(plugin); i != handlers[EventType::TICK].end(); i++ ) { for ( auto i = handlers[EventType::TICK].find(plugin); i != handlers[EventType::TICK].end(); i++ ) {
if ( (*i).first != plugin ) if ( (*i).first != plugin )
break; break;

@ -2150,19 +2150,13 @@ bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t
df::coord Gui::getMousePos() df::coord Gui::getMousePos()
{ {
df::coord pos; df::coord pos;
/* TODO: understand how this changes for v50 if (gps && gps->mouse_x_pixel > -1) {
if (gps && gps->mouse_x > -1) {
// return invalid coords if the cursor is not over the map
DwarfmodeDims dims = getDwarfmodeViewDims();
if (gps->mouse_x < dims.map_x1 || gps->mouse_x > dims.map_x2 ||
gps->mouse_y < dims.map_y1 || gps->mouse_y > dims.map_y2) {
return pos;
}
pos = getViewportPos(); pos = getViewportPos();
pos.x += gps->mouse_x - 1; /* TODO: understand how this changes for v50
pos.y += gps->mouse_y - 1; pos.x += gps->mouse_x_pixel / tile_width;
} pos.y += gps->mouse_y_pixel / tile_height;
*/ */
}
return pos; return pos;
} }

@ -76,26 +76,20 @@ using std::string;
* Screen painting API. * Screen painting API.
*/ */
// returns text grid coordinates, even if the game map is scaled differently // returns ui grid coordinates, even if the game map is scaled differently
df::coord2d Screen::getMousePos() df::coord2d Screen::getMousePos()
{ {
int32_t pixelx = 0, pixely = 0, tilex = 0, tiley = 0; if (!gps)
if (!enabler || !enabler->renderer->get_mouse_coords(
&pixelx, &pixely, &tilex, &tiley)) {
return df::coord2d(-1, -1); return df::coord2d(-1, -1);
} return df::coord2d(gps->mouse_x_tile, gps->mouse_y_tile);
return df::coord2d(tilex, tiley);
} }
// returns the screen pixel coordinates // returns the screen pixel coordinates
df::coord2d Screen::getMousePixels() df::coord2d Screen::getMousePixels()
{ {
int32_t pixelx = 0, pixely = 0, tilex = 0, tiley = 0; if (!gps)
if (!enabler || !enabler->renderer->get_mouse_coords(
&pixelx, &pixely, &tilex, &tiley)) {
return df::coord2d(-1, -1); return df::coord2d(-1, -1);
} return df::coord2d(gps->mouse_x_pixel, gps->mouse_y_pixel);
return df::coord2d(pixelx, pixely);
} }
df::coord2d Screen::getWindowSize() df::coord2d Screen::getWindowSize()
@ -120,18 +114,22 @@ static bool doSetTile_default(const Pen &pen, int x, int y, bool map)
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y) if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return false; return false;
/* TODO: understand how this changes for v50 // TODO: understand how this changes for v50
int index = ((x * gps->dimy) + y); int index = ((x * gps->dimy) + y);
auto screen = gps->screen + index*4; gps->screen1_opt_tile[index] = uint8_t(pen.ch);
screen[0] = uint8_t(pen.ch); // we need a new way to represent color
screen[1] = uint8_t(pen.fg) & 15; //auto argb = &gps->screen1_asciirgb[index * 8];
screen[2] = uint8_t(pen.bg) & 15; /* old code
screen[3] = uint8_t(pen.bold) & 1; // auto screen = gps->screen + index*4;
gps->screentexpos[index] = pen.tile; // screen[0] = uint8_t(pen.ch);
gps->screentexpos_addcolor[index] = (pen.tile_mode == Screen::Pen::CharColor); // screen[1] = uint8_t(pen.fg) & 15;
gps->screentexpos_grayscale[index] = (pen.tile_mode == Screen::Pen::TileColor); // screen[2] = uint8_t(pen.bg) & 15;
gps->screentexpos_cf[index] = pen.tile_fg; // screen[3] = uint8_t(pen.bold) & 1;
gps->screentexpos_cbr[index] = pen.tile_bg; // gps->screentexpos[index] = pen.tile;
// gps->screentexpos_addcolor[index] = (pen.tile_mode == Screen::Pen::CharColor);
// gps->screentexpos_grayscale[index] = (pen.tile_mode == Screen::Pen::TileColor);
// gps->screentexpos_cf[index] = pen.tile_fg;
// gps->screentexpos_cbr[index] = pen.tile_bg;
*/ */
return true; return true;
} }