View Single Post
09-07-15, 10:24 PM   #6
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
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:
  1. local CoordText = WorldMapFrame.BorderFrame.TitleText
  2. local update, frame
  3.  
  4. local function WorldMapDetailFrameUpdate_OnHide()
  5.     update = false
  6. end
  7. local function WorldMapDetailFrameUpdate_OnShow()
  8.     update = true
  9. end
  10.  
  11. function WorldMapDetailFrameUpdate(self)
  12.     if not frame then
  13.         frame = self
  14.     end
  15.     if(WorldMapScrollFrame:IsMouseOver()) then
  16.         local scale = frame:GetEffectiveScale()
  17.         local centerX, centerY = frame:GetCenter()
  18.         local width, height = frame:GetSize()
  19.         local x, y = GetCursorPosition()
  20.  
  21.         x = ((x / scale) - (centerX - (width / 2))) / width
  22.         y = (centerY + (height / 2) - (y / scale)) / height
  23.  
  24.         CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  25.         CoordText:SetTextColor(0, 1, 0)
  26.     else
  27.         local x, y = GetPlayerMapPosition('player')
  28.         CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  29.         CoordText:SetTextColor(1, 1, 0)
  30.     end
  31.     if update then
  32.         C_Timer.After(0.2, WorldMapDetailFrameUpdate );
  33.     end
  34. end
  35.  
  36. WorldMapFrame:HookScript('OnShow', WorldMapDetailFrameUpdate_OnShow)
  37. WorldMapFrame:HookScript('OnHide', WorldMapDetailFrameUpdate_OnHide)
  38. 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.
  Reply With Quote