Updated A-star resource
by Phil Shenk · in Torque Game Builder · 06/25/2006 (9:15 pm) · 11 replies
I updated my A-Star resource with a few minor bug fixes, and updated the demo script to work with the latest TGB release. No new features at this time though.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
About the author
#3
06/26/2006 (6:30 am)
Looks good, added it to my Torque Favourites list.
#4
10/23/2006 (6:15 am)
Just wanted to extend a gigantic THANK YOU for this resource! It has saved me tons of time and many headaches not having to implement it on my own.
#5
10/23/2006 (9:47 pm)
I'm so glad you're finding it helpful! Hopefully one of these days I'll get around to working on it again. FOr now, my real job is too demanding :(
#6
10/23/2006 (9:58 pm)
I also added this resource to my build of TGB today, and it seems to be working great! Another big thanks from me to you ;)
#7
10/23/2006 (9:58 pm)
Sweet!
#8
Thank you very much.
Will greatly help me to try out my idea (and see all the things I missed when thinking about it ^^)
10/25/2006 (11:54 am)
Definitely a great ressource.Thank you very much.
Will greatly help me to try out my idea (and see all the things I missed when thinking about it ^^)
#9
Till now i found only one strange thing, but maybe it's also just an wrong usage-problem. ^^
Whenever i change the TileCustomData the automatic update of mPassable within the mpPathGrid2dManager doesn't seem to work.
some example code:
I use setTileCustomData to change a specific tile during run-time from passable to impassable.
--> pLayer.setTileCustomData(%tilex, %tiley, $PASSABLE);
If the next movment-target is this tile, it's still marked as impassable.
--> PathAStar2d::calculate( sX / sY, dX / dY ) - start or end points are blocked
At the moment my "workaround" is to call the setTileLayer()-function after changing the TileCustomData.
(which re-reads all customdata from the layer)
Anybody noticed the same behavior or got ideas?
10/25/2006 (1:37 pm)
Very good resource, thank you!Till now i found only one strange thing, but maybe it's also just an wrong usage-problem. ^^
Whenever i change the TileCustomData the automatic update of mPassable within the mpPathGrid2dManager doesn't seem to work.
some example code:
I use setTileCustomData to change a specific tile during run-time from passable to impassable.
--> pLayer.setTileCustomData(%tilex, %tiley, $PASSABLE);
If the next movment-target is this tile, it's still marked as impassable.
--> PathAStar2d::calculate( sX / sY, dX / dY ) - start or end points are blocked
At the moment my "workaround" is to call the setTileLayer()-function after changing the TileCustomData.
(which re-reads all customdata from the layer)
Anybody noticed the same behavior or got ideas?
#10
I'm glad you find the resource useful!
I wanted to make it explicit when and where you reset the passable map, so I didn't automatically do it whenever you make a new path. I had a hunch that would just be too slow. Your workaround will work, but you can also call clearMap() to force the pathGrid to re-get the passable info from the tileLayer. setTileLayer does this as part of it's setup anyway... this function is the only part that you need to make it work though.
So, for example:
$myPathGrid.clearMap();
(the function defaults to "true"... you can pass in "true" if you like.)
At least I think that's the way it works... it's been awhile since I used it. I should probably have made that a bit more intuitive, or at least put it in the docs.
If I had been thinking about it more clearly, I could have put a flag in the pathAStar2d::calculate function, to force a re-get of the passable info. That would be an easy thing to add, if you care to do it on your own... just call that same clearMap().
Somewhere in the begining of the calculate function, put in something like:
mpPathGrid2dManager->clearMap();
The best way to do this would be to tie it to a bool parameter that you pass into calculate. If you do it ALL the time, like by default, I'd expect it to be slower... since it's having to read all that customTileData each time it makes a path. Probably not something you'd want to do if you're making lots and lots of paths all the time.
Let me know if this doesn't work for you.
10/25/2006 (11:58 pm)
Hey Markus,I'm glad you find the resource useful!
I wanted to make it explicit when and where you reset the passable map, so I didn't automatically do it whenever you make a new path. I had a hunch that would just be too slow. Your workaround will work, but you can also call clearMap() to force the pathGrid to re-get the passable info from the tileLayer. setTileLayer does this as part of it's setup anyway... this function is the only part that you need to make it work though.
So, for example:
$myPathGrid.clearMap();
(the function defaults to "true"... you can pass in "true" if you like.)
At least I think that's the way it works... it's been awhile since I used it. I should probably have made that a bit more intuitive, or at least put it in the docs.
If I had been thinking about it more clearly, I could have put a flag in the pathAStar2d::calculate function, to force a re-get of the passable info. That would be an easy thing to add, if you care to do it on your own... just call that same clearMap().
Somewhere in the begining of the calculate function, put in something like:
mpPathGrid2dManager->clearMap();
The best way to do this would be to tie it to a bool parameter that you pass into calculate. If you do it ALL the time, like by default, I'd expect it to be slower... since it's having to read all that customTileData each time it makes a path. Probably not something you'd want to do if you're making lots and lots of paths all the time.
Let me know if this doesn't work for you.
#11
thank you for the fast and detailed answer.
I extended the pathAStar2d::calculate() (and the corresponding ConsoleMethod) by the boolean parameter and the call of clearMap() - it works great.
Additionaly i added a ConsoleMethod for pathGrid2d::clearMap() to try also the other possible solution.
--- edit ---
As a little addon i implemented a ConsoleMethod to update directly the changed tile,
may be performance-relevant sometime ... or not ;-)
--- edit ---
10/26/2006 (5:34 am)
Hey Phil, thank you for the fast and detailed answer.
I extended the pathAStar2d::calculate() (and the corresponding ConsoleMethod) by the boolean parameter and the call of clearMap() - it works great.
Additionaly i added a ConsoleMethod for pathGrid2d::clearMap() to try also the other possible solution.
--- edit ---
As a little addon i implemented a ConsoleMethod to update directly the changed tile,
may be performance-relevant sometime ... or not ;-)
//-----------------------------------------------------------------------------
// HEM: updatePassData.
//-----------------------------------------------------------------------------
ConsoleMethod(pathGrid2d, updatePassData, bool, 3, 3, "() - updatePassData")
{
// check parameters
if ( t2dSceneObject::getStringElementCount(argv[2]) < 2)
{
Con::warnf("pathGrid2d::updatePassData( dX / dy ) - Invalid number of parameters!");
return false;
}
// set up the coords
Point2I dest( dAtof(t2dSceneObject::getStringElement(argv[2], 0)), dAtof(t2dSceneObject::getStringElement(argv[2], 1)) );
object->getPassData( dest );
}--- edit ---
Torque 3D Owner Rodney Rindels - Torqued
Divide By Zero
This is a great starter resource for learning a* as well as implementing a good movement system for many types of games . I personally vote this one , resource of the year!