From 58dfc55ca3314cfbbc5b017a427233b7b20d9256 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:50:27 +0200 Subject: [PATCH] only calc minimaps once --- client/windows/CMapOverview.cpp | 55 ++++++++++++++------------------- client/windows/CMapOverview.h | 6 ++-- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index bf4d893de..7fdad167e 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -99,9 +99,9 @@ Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr> CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource, Point size) const +std::vector CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource) const { - std::vector> ret = std::vector>(); + std::vector ret = std::vector(); CMapService mapService; std::unique_ptr map; @@ -114,22 +114,15 @@ std::vector> CMapOverview::CMapOverviewWidget::createMin return ret; } - return createMinimaps(map, size); + return createMinimaps(map); } -std::vector> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map, Point size) const +std::vector CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map) const { - std::vector> ret = std::vector>(); + std::vector ret = std::vector(); for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) - { - Canvas canvas = createMinimapForLayer(map, i); - Canvas canvasScaled = Canvas(size); - canvasScaled.drawScaled(canvas, Point(0, 0), size); - std::shared_ptr img = GH.renderHandler().createImage(canvasScaled.getInternalSurface()); - - ret.push_back(img); - } + ret.push_back(createMinimapForLayer(map, i)); return ret; } @@ -141,9 +134,23 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con auto rect = readRect(config["rect"]); auto id = config["id"].Integer(); - if(!renderImage) + if(id >= minimaps.size()) return nullptr; + Canvas canvasScaled = Canvas(Point(rect.w, rect.h)); + canvasScaled.drawScaled(minimaps[id], Point(0, 0), Point(rect.w, rect.h)); + std::shared_ptr img = GH.renderHandler().createImage(canvasScaled.getInternalSurface()); + + return std::make_shared(img, Point(rect.x, rect.y)); +} + +CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): + InterfaceObjectConfigurable(), p(parent) +{ + drawPlayerElements = p.tabType == ESelectionScreen::newGame; + renderImage = settings["lobby"]["mapPreview"].Bool(); + + // create minimaps ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); std::unique_ptr campaignMap = nullptr; if(p.tabType != ESelectionScreen::newGame) @@ -159,26 +166,12 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario()); res = ResourcePath(startInfo->fileURI, EResType::MAP); } - - std::vector> images; if(!campaignMap) - images = createMinimaps(res, Point(rect.w, rect.h)); + minimaps = createMinimaps(res); else - images = createMinimaps(campaignMap, Point(rect.w, rect.h)); - - - if(id >= images.size()) - return nullptr; - - return std::make_shared(images[id], Point(rect.x, rect.y)); -} - -CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): - InterfaceObjectConfigurable(), p(parent) -{ - drawPlayerElements = p.tabType == ESelectionScreen::newGame; - renderImage = settings["lobby"]["mapPreview"].Bool(); + minimaps = createMinimaps(campaignMap); + // config const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 0628852d7..c9d4197f9 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -34,9 +34,11 @@ class CMapOverview : public CWindowObject bool drawPlayerElements; bool renderImage; + std::vector minimaps; + Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; - std::vector> createMinimaps(ResourcePath resource, Point size) const; - std::vector> createMinimaps(std::unique_ptr & map, Point size) const; + std::vector createMinimaps(ResourcePath resource) const; + std::vector createMinimaps(std::unique_ptr & map) const; std::shared_ptr buildDrawMinimap(const JsonNode & config) const; public: