From ca65ff8ae227bd1dafd3f78a4054449fc027f2e1 Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Thu, 3 Sep 2026 21:17:54 +0200 Subject: [PATCH 1/2] Optimize WorldMap coordinate updates with ClassicAPI --- mods/worldmap-coordinates.lua | 47 ++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/mods/worldmap-coordinates.lua b/mods/worldmap-coordinates.lua index aa0f0d5..1ade423 100644 --- a/mods/worldmap-coordinates.lua +++ b/mods/worldmap-coordinates.lua @@ -1,5 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["WorldMap Coordinates"], @@ -42,6 +43,8 @@ module.enable = function(self) WorldMapButton.player.text:SetJustifyH("RIGHT") WorldMapButton.coords.elapsed = 0 + WorldMapButton.coords.lastCursorText = nil + WorldMapButton.coords.lastPlayerText = nil WorldMapButton.coords:SetScript("OnUpdate", function() -- Coordinates do not need a full render-frame refresh. 10 Hz keeps the -- display responsive while avoiding repeated map/cursor queries and @@ -50,28 +53,44 @@ module.enable = function(self) if this.elapsed < .1 then return end this.elapsed = 0 - local width = WorldMapButton:GetWidth() - local height = WorldMapButton:GetHeight() - local mx, my = WorldMapButton:GetCenter() - local scale = WorldMapButton:GetEffectiveScale() - local x, y = GetCursorPosition() + local cursorText + if API and API.regionmouseover and API.IsMouseOver(WorldMapButton) then + local width = WorldMapButton:GetWidth() + local height = WorldMapButton:GetHeight() + local mx, my = WorldMapButton:GetCenter() + local scale = WorldMapButton:GetEffectiveScale() + local x, y = GetCursorPosition() - if mx and my then - mx = (( x / scale ) - ( mx - width / 2)) / width * 100 - my = (( my + height / 2 ) - ( y / scale )) / height * 100 + if mx and my then + mx = (( x / scale ) - ( mx - width / 2)) / width * 100 + my = (( my + height / 2 ) - ( y / scale )) / height * 100 + end + + if mx and my then + cursorText = string.format("|cffffcc00" .. T["Cursor"] .. ": |r%.1f / %.1f", mx, my) + end + end + + if not cursorText then + cursorText = "|cffffcc00" .. T["Cursor"] .. ": |r" .. T["N/A"] + end + + if this.lastCursorText ~= cursorText then + this.lastCursorText = cursorText + WorldMapButton.coords.text:SetText(cursorText) end local px, py = GetPlayerMapPosition("player") + local playerText if px > 0 and py > 0 then - WorldMapButton.player.text:SetText(string.format("|cffffcc00" .. T["Player"] .. ": |r%.1f / %.1f", px*100, py*100)) + playerText = string.format("|cffffcc00" .. T["Player"] .. ": |r%.1f / %.1f", px*100, py*100) else - WorldMapButton.player.text:SetText(string.format("|cffffcc00" .. T["Player"] .. ": |r" .. T["N/A"])) + playerText = "|cffffcc00" .. T["Player"] .. ": |r" .. T["N/A"] end - if mx and my and MouseIsOver(WorldMapButton) then - WorldMapButton.coords.text:SetText(string.format("|cffffcc00" .. T["Cursor"] .. ": |r%.1f / %.1f", mx, my)) - else - WorldMapButton.coords.text:SetText(string.format("|cffffcc00" .. T["Cursor"] .. ": |r" .. T["N/A"])) + if this.lastPlayerText ~= playerText then + this.lastPlayerText = playerText + WorldMapButton.player.text:SetText(playerText) end end) end From daf8aed77a12409a08ceffc319bddae4824569eb Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Thu, 3 Sep 2026 21:18:21 +0200 Subject: [PATCH 2/2] Avoid repeated WorldMap coordinate string allocations --- mods/worldmap-coordinates.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mods/worldmap-coordinates.lua b/mods/worldmap-coordinates.lua index 1ade423..b942506 100644 --- a/mods/worldmap-coordinates.lua +++ b/mods/worldmap-coordinates.lua @@ -42,6 +42,12 @@ module.enable = function(self) WorldMapButton.player.text:SetTextColor(1, 1, 1) WorldMapButton.player.text:SetJustifyH("RIGHT") + local canMouseOver = API and API.regionmouseover + local cursorFormat = "|cffffcc00" .. T["Cursor"] .. ": |r%.1f / %.1f" + local playerFormat = "|cffffcc00" .. T["Player"] .. ": |r%.1f / %.1f" + local cursorNA = "|cffffcc00" .. T["Cursor"] .. ": |r" .. T["N/A"] + local playerNA = "|cffffcc00" .. T["Player"] .. ": |r" .. T["N/A"] + WorldMapButton.coords.elapsed = 0 WorldMapButton.coords.lastCursorText = nil WorldMapButton.coords.lastPlayerText = nil @@ -54,7 +60,7 @@ module.enable = function(self) this.elapsed = 0 local cursorText - if API and API.regionmouseover and API.IsMouseOver(WorldMapButton) then + if canMouseOver and API.IsMouseOver(WorldMapButton) then local width = WorldMapButton:GetWidth() local height = WorldMapButton:GetHeight() local mx, my = WorldMapButton:GetCenter() @@ -67,12 +73,12 @@ module.enable = function(self) end if mx and my then - cursorText = string.format("|cffffcc00" .. T["Cursor"] .. ": |r%.1f / %.1f", mx, my) + cursorText = string.format(cursorFormat, mx, my) end end if not cursorText then - cursorText = "|cffffcc00" .. T["Cursor"] .. ": |r" .. T["N/A"] + cursorText = cursorNA end if this.lastCursorText ~= cursorText then @@ -83,9 +89,9 @@ module.enable = function(self) local px, py = GetPlayerMapPosition("player") local playerText if px > 0 and py > 0 then - playerText = string.format("|cffffcc00" .. T["Player"] .. ": |r%.1f / %.1f", px*100, py*100) + playerText = string.format(playerFormat, px*100, py*100) else - playerText = "|cffffcc00" .. T["Player"] .. ": |r" .. T["N/A"] + playerText = playerNA end if this.lastPlayerText ~= playerText then