yi / node-path-finding

a simple server-side path finding module for NodeJS
9 stars 4 forks source link

Output array #1

Closed MaksJS closed 11 years ago

MaksJS commented 11 years ago

I've tried your pathfinding module @yi, it's really fast ! The fastest i've ever tried. But when I search for a path, it outputs an array with numbers and not a 2d array with coords like [[0,0], [1,0]...]

How can I get this ?

Thanks :)

MaksJS commented 11 years ago

Oh, by the way, you forgot to compile coffeescript with commented console.log ;)

yi commented 11 years ago

@MaksJS, there are two things I used to boost the speed and control memory consumption in this pathfinding module:

  1. "new" is an expensive operation in the JS VM, so I tried to avoid "create new array instance". Instead, I use a 32-bit uint to present a "x by y" location (which I called brickLoc, as "node" in Xu's Pathfinding.JS). the x is the higher 16-bit of the uint, and the y is the lower. Thus the output of the pathfinding is an Array of uints. The get the x value of a brickLoc, do: brickLoc >>> 16. To get the y value of a brickLoc, do brickLoc & 0xffff
  2. There are only 2 stats of 1 brickLoc: blocked and non-blocked. That can be perfectly presented by a bit. So I wrote a Gird base on the Buffer class in Node.JS, which provides a fast way to detect if a given brickLoc is blocked or not. The Grid class greatly reduce the memory consumption required by the pathfinding module in the runtime.

Try node tests/sync_astar_continue_test.js it does an continuously test of pathfinding on some map fixtures, and the vm memory recycled correctly.

MaksJS commented 11 years ago

Ok thanks for the details, I understand better how it works now. I think i'll go with my own fork, I need to disallow diagonals and also a setWalkableAt method

yi commented 11 years ago

Please go ahead, and let me know if any bug.

To implement setWalkableAt() method, please refere to: https://github.com/yi/node-path-finding/blob/master/src/grid.coffee#L48

and I close this issue for now.