Use texture-based minimap rendering in-game

This commit is contained in:
Charles Dang 2024-02-20 22:38:09 -05:00
parent eae3b89bd0
commit 434aac98a1
2 changed files with 13 additions and 22 deletions

View file

@ -165,7 +165,7 @@ display::display(const display_context* dc,
, zoom_index_(0)
, fake_unit_man_(new fake_unit_manager(*this))
, builder_(new terrain_builder(level, (dc_ ? &dc_->map() : nullptr), theme_.border().tile_image, theme_.border().show_border))
, minimap_(nullptr)
, minimap_renderer_(nullptr)
, minimap_location_(sdl::empty_rect)
, redraw_background_(false)
, invalidateAll_(true)
@ -1666,11 +1666,12 @@ void display::recalculate_minimap()
return;
}
minimap_ = texture(image::getMinimap(
area.w, area.h, get_map(),
minimap_renderer_ = image::prep_minimap_for_rendering(
get_map(),
dc_->teams().empty() ? nullptr : &dc_->teams()[currentTeam_],
nullptr,
(selectedHex_.valid() && !is_blindfolded()) ? &reach_map_ : nullptr
));
);
redraw_minimap();
}
@ -1688,7 +1689,7 @@ void display::draw_minimap()
return;
}
if(!minimap_) {
if(!minimap_renderer_) {
ERR_DP << "trying to draw null minimap";
return;
}
@ -1698,23 +1699,15 @@ void display::draw_minimap()
// Draw the minimap background.
draw::fill(area, 31, 31, 23);
// Update the minimap location for mouse and units functions
minimap_location_.x = area.x + (area.w - minimap_.w()) / 2;
minimap_location_.y = area.y + (area.h - minimap_.h()) / 2;
minimap_location_.w = minimap_.w();
minimap_location_.h = minimap_.h();
// Draw the minimap.
if (minimap_) {
draw::blit(minimap_, minimap_location_);
}
// Draw the minimap and update its location for mouse and units functions
minimap_location_ = std::invoke(minimap_renderer_, area);
draw_minimap_units();
// calculate the visible portion of the map:
// scaling between minimap and full map images
double xscaling = 1.0*minimap_.w() / (get_map().w()*hex_width());
double yscaling = 1.0*minimap_.h() / (get_map().h()*hex_size());
double xscaling = 1.0 * minimap_location_.w / (get_map().w() * hex_width());
double yscaling = 1.0 * minimap_location_.h / (get_map().h() * hex_size());
// we need to shift with the border size
// and the 0.25 from the minimap balanced drawing
@ -2502,11 +2495,9 @@ void display::render()
// update the minimap texture, if necessary
// TODO: highdpi - high DPI minimap
const rect& area = minimap_area();
if(!area.empty() &&
(!minimap_ || minimap_.w() > area.w || minimap_.h() > area.h))
{
if(!area.empty() && !minimap_renderer_) {
recalculate_minimap();
if(!minimap_) {
if(!minimap_renderer_) {
ERR_DP << "error creating minimap";
return;
}

View file

@ -742,7 +742,7 @@ protected:
static unsigned int last_zoom_;
const std::unique_ptr<fake_unit_manager> fake_unit_man_;
const std::unique_ptr<terrain_builder> builder_;
texture minimap_;
std::function<rect(rect)> minimap_renderer_;
SDL_Rect minimap_location_;
bool redraw_background_;
bool invalidateAll_;