Thread: PTS issue, or?
View Single Post
08/29/15, 09:56 PM   #19
Fyrakin
 
Fyrakin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 129
Originally Posted by merlight View Post
Won't fix bad flop performance, but here's a common optimization for distance checks that might help you:
Lua Code:
  1. -- instead of
  2. if sqrt((x1-x2)^2 + (y1-y2)^2) < MAX_DIST then ... end
  3.  
  4. -- do
  5. local dx = x1 - x2
  6. local dy = y1 - y2
  7. local dist2 = dx*dx + dy*dy
  8. if dist2 < MAX_DIST2 then ... end
  9. -- MAX_DIST2 = MAX_DIST^2
  10. -- and needs only be computed once if you have fixed MAX_DIST

You don't have to compute sqrt for a distance check, square the threshold instead, it's cheaper. And of course, once you compute the squared distance, memoize it, don't compute it again for another check a few lines below
I found a way around without a need to scrap the root, but if I run into another performance hindrance I'll have to resort to that. My problem with distance checks is that when player moves all distances change and I have to recalculate all of them to make sure I selected the ones I need.
  Reply With Quote