At 11/4/11 09:20 PM, PrettyMuchBryce wrote:
I was doing some polling and it was pretty inefficient.
Yuck! For realtime multiplayer?
You probably already know, but you gotta go socket server with that. Oh, and by the way, there are a few optimizations you can still do for your A* thing, like not using Array.sort(), Array.shift(), and Array.splice() (Not sure if you're doing that even though...), and also treating the Open list as more like an Object pool rather than an Array.
So instead of adding to the array, you do openList[ len] = newObject, where "len" is a separate variable denoting the arrays length (You manually increment it).
To delete an object from the array, you swap the object that's being deleted with the last element in the array, and decrement len by one.
Also, there's no point in sorting the entire array, since you only need the Node with the lowest F value. It's faster to for loop through it and find it that way than using Array.sort().
This is from an engine I had and a few recent tests to double check the performance costs. Array functions are little fuckers when it comes to performance sometimes, best avoid them.
Plus it's my birthday! :O