Thread Tools Display Modes
Prev Previous Post   Next Post Next
08/30/15, 10:35 AM   #19
Fyrakin
 
Fyrakin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 129
Originally Posted by merlight View Post
I tried to explain that there's no reason to compute the root if you only need it for comparison against some distance threshold. Additionally, each sub-expression should only be computed once -- it's both more efficient and readable.

Like this function, it does way too many avoidable table lookups and an unnecessary sqrt:
Lua Code:
  1. local function IsCoordinateInRange(x, y)
  2.     if not FyrMM.currentMap.TrueMapSize or not FyrMM.currentMap.PlayerNX or not FyrMM.SV.CustomPinViewRange or not FyrMM.SV.ViewRangeFiltering then return true end
  3.     return FyrMM.currentMap.TrueMapSize * math.sqrt((x-FyrMM.currentMap.PlayerNX)*(x-FyrMM.currentMap.PlayerNX)+(y-FyrMM.currentMap.PlayerNY)*(y-FyrMM.currentMap.PlayerNY)) <= FyrMM.SV.CustomPinViewRange
  4. end

Lua Code:
  1. -- this is used so heavily that I'd localize it at the file level
  2. local g_currentMap = FyrMM.currentMap
  3.  
  4. local function IsCoordinateInRange(x, y)
  5.     local mapSize = g_currentMap.TrueMapSize
  6.     local nx = g_currentMap.PlayerNX
  7.     local pinViewRange = FyrMM.SV.CustomPinViewRange
  8.     if not (mapSize and nx and pinViewRange) then return true end
  9.  
  10.     local dx = x - nx
  11.     local dy = y - g_currentMap.PlayerNY
  12.     return (dx * dx + dy * dy) * mapSize * mapSize <= pinViewRange * pinViewRange
  13. end
It is a very fast changing environment, btw this particular function works fine no difference between live and pts. I made heavy changes during past week meantime testing it against pts and speeds are looking acceptable. Though it runs much smoother on live.

PS I also have noticed a faster garbage collection growth while using local variables. This is very worrying.

Last edited by Fyrakin : 08/30/15 at 10:37 AM.
  Reply With Quote
 

ESOUI » Developer Discussions » General Authoring Discussion » PTS issue, or?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off