View Single Post
07-10-19, 08:48 AM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Because the C_Map.GetPlayerMapPosition always create a new table as the result, so the memory usage will constantly increasing.

Here is a solution from other author:

Lua Code:
  1. local MapRects                  = {}
  2. function GetPlayerMapPos()
  3.     local mapid                 = C_Map.GetBestMapForUnit('player')
  4.     if not mapid then return end
  5.  
  6.     local rects                 = MapRects[mapid]
  7.  
  8.     if not rects then
  9.         rects                   = {}
  10.         local _, topleft        = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(0,0))
  11.         local _, bottomright    = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(1,1))
  12.  
  13.         bottomright:Subtract(topleft)
  14.         rects                   = { topleft.x, topleft.y, bottomright.x, bottomright.y }
  15.         MapRects[mapid]         = rects
  16.     end
  17.  
  18.     local x, y                  = UnitPosition("player")
  19.     if not x then return end
  20.  
  21.     x, y                        = x - rects[1], y - rects[2]
  22.  
  23.     return y / rects[4], x / rects[3]
  24. end
  Reply With Quote