I'm new in programming, so I might be wrong and my code can be too massy, but i tried to replace OnUpdate with C_Timer.After(0.2seconds,function). And on my PC i got 30% less CPU usage of this feature with 30 FPS capped (i used ChocolateBar+libQtip+BrokerCPU to track performance). i think for players with 60+ FPS the difference in performance will be more significant.
Lua Code:
local CoordText = WorldMapFrame.BorderFrame.TitleText
local update, frame
local function WorldMapDetailFrameUpdate_OnHide()
update = false
end
local function WorldMapDetailFrameUpdate_OnShow()
update = true
end
function WorldMapDetailFrameUpdate(self)
if not frame then
frame = self
end
if(WorldMapScrollFrame:IsMouseOver()) then
local scale = frame:GetEffectiveScale()
local centerX, centerY = frame:GetCenter()
local width, height = frame:GetSize()
local x, y = GetCursorPosition()
x = ((x / scale) - (centerX - (width / 2))) / width
y = (centerY + (height / 2) - (y / scale)) / height
CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
CoordText:SetTextColor(0, 1, 0)
else
local x, y = GetPlayerMapPosition('player')
CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
CoordText:SetTextColor(1, 1, 0)
end
if update then
C_Timer.After(0.2, WorldMapDetailFrameUpdate );
end
end
WorldMapFrame:HookScript('OnShow', WorldMapDetailFrameUpdate_OnShow)
WorldMapFrame:HookScript('OnHide', WorldMapDetailFrameUpdate_OnHide)
WorldMapFrame:HookScript('OnShow', WorldMapDetailFrameUpdate)
If you can make my code even run faster and looks better, and point on my mistakes, i will very appreciate it.