Thread: PTS issue, or?
View Single Post
08/28/15, 04:30 AM   #18
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Fyrakin View Post
After some internal tests I was able to pinpoint weak spots.

I have a suspicion that either math.sqrt is working not like on live or normalized coordinate values for wayshrines and player position have more decimal places, what I am seeing is that a simple distance formula sqrt ((x1-x2)^2+(y1-y2)^2) takes a lot more power to complete on pts. This results in signiffican performance loss FPS drops UI lags, etc. Also SetMapToPlayerLocation() works much slower than on live, it is another source of performance loss.
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
  Reply With Quote