GPathfinding
A generic, cell-based "A*" pathfinding dll for gamemaker
last update: 25/1/2010
What makes this dll exceptional
This dll has the intention to extend the very limited functionality from mp_grids, while keeping it's speed, it especially has support for "cost-based" pathfinding, and to give the user better "time-management" to prevent lagging. Also it allows for a great number of import and export options to insert those "costs" (and extract paths).
The good thing is that it doesn't come with much lag. Creating a 200 * 200 cells room (thus 40 000 cells) where the end is "blocked" by 8 cells, and using 8-directions-based movement. Which is the worst case: it still can perform 85 dll-calls a second. Similar, the same world using mp_grid_path() calls we can perform 100 calls a step.
downloads
(version 1)The download is a zip file containing 5 files:
GPath.dll - The main dll.
GPF_Tutorial.pdf - An extensive manual about all features of GPathfinding
Gpath7.gmk - an gamemaker 7 example file,
Gpath8.gmk - an gamemaker 8 example file (almost the same as above, only a supporting script is slightly different).
GPathfinding.gmres - A gamemaker 8 resource file, containing all scripts and constants for the heuristic-distance function
updates
- Redone/renamed the entire function list
- added full compatibility for gm8
- build a tutorial
- build an example program
- added a few smaller functions
- fixed a lot of small bugs
Important features
These are a few of the features currently in the dll. (If the feature is followed by {GMX} there is a number it means it's only for X version of gamemaker)
- cells can have different costs (or -1 meaning "infinite")
- 4, or 8 way development
- Not-infinite pathfinding calls. (You can define the maximum depth a call should make, and at a later call continue the search)
- Handles correctly bigger objects (objects which are larger than 1 cell)
- setting of multiple nodes at once
- setting while inputting 'real world' rectangles or ellipses
- Importing objects as "obstacles" with a cost
- Importing ds_girds
- Export to paths, lists, queues and stacks
- Multiple pathfinding systems at the same time
- Custom (in gamemaker written) heuristic functions
Basic help
The pdf tutorial inside the zip-package should be considered vital for anyone, and as quick reference you can use the in-script comments.
But it all comes down to simply those 5 steps:
- Load the dll: GPF_Init(dllname)
- create a pathfinding system: pid = GPF_Create(xstart,ystart, xend,yend, gridwidth,gridheight, cellwidth,cellheight, xoffset,yoffset)
- Add obstacles to the system-grid: GPF_Set(pid,x,y,value)
- Calculate the path: GPF_Calculate(pid,-1,false)
- Export the path: GPF_ExportPath(pid,gmpath)
Function list
There are at the moment of writing about 70 scripts which you can use, here is a quick overview.
GPF_Create(xstart,ystart,xend,yend,w,h, xoffset,yoffset,cellw,cellh)GPF_CopySystem(pid)GPF_Release(pid)GPF_ReleaseAll()GPF_Resize(pid,w,h)GPF_SetDimensions(pid,w,h,xoffset,yoffset,cellw,cellh)GPF_SetNumdir(pid,numdir)GPF_SetDistancefunc(pid,disfunc)GPF_SetCutcorners(pid,cutcorners)GPF_SetPathfindingoptions(pid,numdir,disfunc,cutcorners)GPF_SetMover(pid,width,height)GPF_GetWidth(pid)GPF_GetHeight(pid)GPF_GetCellWidth(pid)GPF_GetCellHeight(pid)GPF_GetXoffset(pid)GPF_GetYoffset(pid)GPF_Set(pid,x,y,v)GPF_SetArea(pid,x,y,x2,y2,v)GPF_Add(pid,x,y,v)GPF_AddArea(pid,x,y,x2,y2,v)GPF_Rem(pid,x,y,v)GPF_RemArea(pid,x,y,x2,y2,v)GPF_SetRectangle(pid,x,y,x2,y2,v)GPF_SetCircle(pid,x,y,r,v)GPF_SetEllipse(pid,x,y,x2,y2,v)GPF_AddRectangle(pid,x,y,x2,y2,v)GPF_AddCircle(pid,x,y,r,v)GPF_AddEllipse(pid,x,y,x2,y2,v)GPF_RemRectangle(pid,x,y,x2,y2,v)GPF_RemCircle(pid,x,y,r,v)GPF_RemEllipse(pid,x,y,x2,y2,v)GPF_SetObjectRect(pid,objid,v)GPF_AddObjectRect(pid,objid,v)GPF_RemObjectRect(pid,objid,v)GPF_SetObjectEllip(pid,objid,v)GPF_AddObjectEllip(pid,objid,v)GPF_RemObjectEllip(pid,objid,v)GPF_ImportGmGrid(pid,grid)GPF_SetGmGrid(pid,grid)GPF_AddGmGrid(pid,grid)GPF_Fill(pid,v)GPF_SetStart(pid,x,y)GPF_SetEnd(pid,x,y)GPF_GetStartX(pid)GPF_GetStartY(pid)GPF_GetStart(pid)GPF_GetEndX(pid)GPF_GetEndY(pid)GPF_GetEnd(pid)GPF_GetCost(pid,x,y)GPF_CalculatePath(pid,steps,update)GPF_GetState(pid)GPF_GetCalc(pid)GPF_GetFound(pid)GPF_Cleanup(pid)GPF_PathNumPoints(pid)GPF_PathLength(pid)GPF_PathCost(pid)GPF_PathPointX(pid,num)GPF_PathPointY(pid,num)GPF_PathPoint(pid,num)GPF_ExportPath(pid,gmpath)GPF_ExportPathExt(pid,gmpath)GPF_ExportList(pid,list)GPF_ExportStack(pid,stack)GPF_ExportQueue(pid,queue)GPF_DebugDraw(pid,maxv)
Planned updates
The gm7 version should be considered "finished": I will only fix possible bugs, and add functions which are necessary for the dll to work completely. - But new features will be added to the gm8 version (and if they work for gm7, that's a nice extra). But what I like to add:
The way objects are added with GPF_SetObject... I don't find satisfying (basically the fact that it is an object is ignored after the adding). What I like to make is that the dll remembers the objects added, and their value. That should allow for easier removal, and could possibly combined with motion prediction.. (To create paths who work correctly with moving objects).
Another item of interest is to add the possibility for "wierd" ends: where the end-point is not a simple item but instead a list of points - or possibly a polygon.
Different pathfinding-algorithms are also in my to-do list.. (Some other algorithms have specific uses).
Also I'm open for any other suggestions!
Thanks, and have fun enhancing the AI of your game with these dlls,
Paul Weijtens
Edited by paul23, 10 February 2010 - 12:14 PM.











