From 9f1cd69480113de747835e1f24452a6177a9fa26 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 7 Jan 2025 14:06:09 +0000 Subject: [PATCH] Fix visualization of AI object graph --- AI/Nullkiller/Pathfinding/AINodeStorage.h | 2 +- client/mapView/MapOverlayLogVisualizer.cpp | 19 ++++++++----------- client/mapView/MapView.cpp | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.h b/AI/Nullkiller/Pathfinding/AINodeStorage.h index eb2a53827..7d497b681 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.h +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.h @@ -11,7 +11,7 @@ #pragma once #define NKAI_PATHFINDER_TRACE_LEVEL 0 -constexpr int NKAI_GRAPH_TRACE_LEVEL = 0; +constexpr int NKAI_GRAPH_TRACE_LEVEL = 0; // To actually enable graph visualization, enter `/vslog graph` in game chat #define NKAI_TRACE_LEVEL 0 #include "../../../lib/pathfinder/CGPathNode.h" diff --git a/client/mapView/MapOverlayLogVisualizer.cpp b/client/mapView/MapOverlayLogVisualizer.cpp index 7e1678230..f75a1cf91 100644 --- a/client/mapView/MapOverlayLogVisualizer.cpp +++ b/client/mapView/MapOverlayLogVisualizer.cpp @@ -17,6 +17,7 @@ #include "../render/Colors.h" #include "../render/EFont.h" #include "../render/IFont.h" +#include "../render/IScreenHandler.h" #include "../render/IRenderHandler.h" #include "../render/Graphics.h" #include "../gui/TextAlignment.h" @@ -30,24 +31,20 @@ MapOverlayLogVisualizer::MapOverlayLogVisualizer(Canvas & target, std::shared_pt void MapOverlayLogVisualizer::drawLine(int3 start, int3 end) { - const Point offset = Point(30, 30); - auto level = model->getLevel(); if(start.z != level || end.z != level) return; - auto pStart = model->getTargetTileArea(start).topLeft(); - auto pEnd = model->getTargetTileArea(end).topLeft(); - auto viewPort = target.getRenderArea(); + int scaling = GH.screenHandler().getScalingFactor(); + auto pStart = model->getTargetTileArea(start).center(); + auto pEnd = model->getTargetTileArea(end).center(); + Rect viewPortRaw = target.getRenderArea(); + Rect viewPort(viewPortRaw.topLeft() / scaling, viewPortRaw.dimensions() / scaling ); - pStart.x += 3; - pEnd.x -= 3; + Point workaroundOffset(8,8); // not sure why it is needed. Removing leads to incorrect clipping near view edges - pStart += offset; - pEnd += offset; - - if(viewPort.isInside(pStart) && viewPort.isInside(pEnd)) + if(viewPort.isInside(pStart + workaroundOffset) && viewPort.isInside(pEnd + workaroundOffset)) { target.drawLine(pStart, pEnd, ColorRGBA(255, 255, 0), ColorRGBA(255, 0, 0)); } diff --git a/client/mapView/MapView.cpp b/client/mapView/MapView.cpp index 522cca227..3c2cccf84 100644 --- a/client/mapView/MapView.cpp +++ b/client/mapView/MapView.cpp @@ -65,7 +65,7 @@ void BasicMapView::render(Canvas & target, bool fullUpdate) tilesCache->update(controller->getContext()); tilesCache->render(controller->getContext(), targetClipped, fullUpdate); - MapOverlayLogVisualizer r(target, model); + MapOverlayLogVisualizer r(targetClipped, model); logVisual->visualize(r); }