Re: distance approximation in 3D
- From: "copx" <copx@xxxxxxxxx>
- Date: Mon, 9 Jun 2008 07:42:51 +0200
"Ray Dillinger" <bear@xxxxxxxxx> schrieb im Newsbeitrag
news:484cbac5$0$17152$742ec2ed@xxxxxxxxxxxxxxxxx
copx wrote:
This is meant to be used as the heuristic of an A* pathfinder.This is
speed critical. On a big 3D map with many actors this function will be
called countless times.
Pathfinding is probably the single most CPU intense task of the entire
code base.
If it is, then I humbly suggest that this may be a case of solving
the wrong problem. Rather than looking for a cheaper distance metric,
you should be looking for a cheaper way to do A*. Or even a cheaper
way to do "chase and follow the player", which may not need A*.
There are ways to optimize A* that allow you to do it without big
CPU hits.
You can divide the dungeon into "segments" (each room a segment;
each hallway chunk without branches or doors a segment) and run
A* on the basis of segment traversal rather than square traversal
for an order of magnitude or more of speed.
You can cache A* results for monsters in the same origin segment
to use when going to the same destination segment. This will get
you another two orders of magnitude (or more, the longer the map
is in use).
Or you can do effective pathfinding without A*. If you accept
that some monsters are sorta dumb and won't do absolutely
perfect pathfinding, you can give them pretty darn good
pathfinding that's O(1). Here's how. When checking the
player's line-of-sight you can calculate a "gradient" score
(something like 32x the turn number minus the distance from
which the square is seen by the player) and store it on the
square. That allows a monster to look at just its surrounding
squares and pick the one with the greatest gradient score
to go into, the effect being that the monster very convincingly
and effectively (though not perfectly like A*) chases the player.
Stop thinking previous gen :P
Start thinking about a world that is not centered around a single character
and where actors need to find paths completely unrelated to the PC. Oh, and
start thinking dynamic maps instead of static ones. One could still
recalculate segments all the time but the whole segment stuff would only add
a lot of complexity. I prefer a clean, general solution to map dependent
hackery.
.
- Follow-Ups:
- Re: distance approximation in 3D
- From: Ray Dillinger
- Re: distance approximation in 3D
- References:
- distance approximation in 3D
- From: copx
- Re: distance approximation in 3D
- From: David Damerell
- Re: distance approximation in 3D
- From: Simon Richard Clarkstone
- Re: distance approximation in 3D
- From: copx
- Re: distance approximation in 3D
- From: Ray Dillinger
- distance approximation in 3D
- Prev by Date: Re: distance approximation in 3D
- Next by Date: Re: Stile source code
- Previous by thread: Re: distance approximation in 3D
- Next by thread: Re: distance approximation in 3D
- Index(es):
Relevant Pages
|