Progress reports on funded work
#101
Posted 08 December 2011 - 10:22 PM
If someone needs a fast path, they should be using waypoints.
Kieran P [ aka k776 ]
Wildfire Games Open Source Development Manager
Contact me: kieran@wildfiregames.com
#102
Posted 09 December 2011 - 08:18 AM
Ykkrosh, on 08 December 2011 - 02:24 PM, said:
Day 9
Did some research into pathfinding. Independent of the ongoing discussions about formations etc, it seems we could benefit significantly from a faster long-range pathfinder. In particular, the pathfinder needs to quickly plan an efficient route from one side of the map to the other, avoiding impassable terrain (cliffs, rivers, etc) and buildings. It doesn't need to be a perfectly smooth path, and it doesn't need to avoid other units - that's the responsibility of a lower-level module that computes the frame-by-frame movement of each individual unit as it follows the high-level planned path.
(I said a while ago that I was only planning to look at the short-range pathfinder, but performance data suggests the long-range one matters, and changes to the long-range one might change the requirements for the short-range one, so I'm focusing on that for a while.)
The current pathfinder is a pretty basic implementation of the A* algorithm, with the terrain and buildings stored as a 2D grid of passable/impassable tiles. It's reasonably fast - after a few minor simplifications and optimisations compared to the code the game currently uses, it can process about 4 million tiles per second on a fast CPU. But a standard map in the game might have 40,000 tiles or more, and in the worst case (when there's a very long and complex path) the pathfinder might have to process every one of those tiles, taking about 10msec. If you send multiple groups of units to attack the enemy at the same time, that adds up to a reasonably significant amount of CPU usage.
That's still not terrible, but a secondary problem is that tiles are quite large. Our typical units are less than half a tile wide, but if two buildings are separated by as much as two tiles then it's possible for there to be no fully-passable tile between them, so the unit won't be able to find a path between them. If we could replace every tile with, say, a 4x4 grid of sub-tiles, then we'll be able to represent gaps that are a quarter of a tile wide, allowing much more accurate movement of units through complex environments. But then the pathfinder will be about 16 times slower, so we'd need to balance it by optimising the pathfinder much more heavily.
There's quite a bit of existing work on pathfinding over tiles, from both practical and academic perspectives. Navigation meshes are common in non-tile-based games, but they're a bit tricky to update dynamically (e.g. when a building is constructed, or a tree is cut down), and the use of tiles allows us to use more specialised algorithms. Navmeshes might not always find the optimal shortest path between two points; they're just designed to find paths that are 'good enough' in most cases. MM-Abstraction (PDF) (designed for the game Dragon Age) is basically tile-based (non-convex) navmeshes. HPA* (PDF) is a bit like MM-Abstraction with higher-quality (closer to optimal) paths, at the expense of performance; you can adjust the tradeoff by tweaking the algorithm. (In particular you can choose the number and location of nodes on entrances into each region, whereas MM-Abstraction assumes a single node somewhere near the middle of each region). Jump Point Search guarantees optimal paths by simply computing the standard A* algorithm in a more efficient way (skipping redundant work).
One concern is that most of this published work is based on maze-style maps, with a series of rooms connected by corridors. In an RTS game we generally have the opposite: most of the world is open space, with trees and buildings dotted around it, and a few very large obstructions (rivers, mountains, walls, etc), and no rooms or corridors. Some algorithms are explicitly designed to identify rooms, so they'll be useless here, and for others we need to be careful that they have the desired performance characteristics.
Another concern is that some algorithms assume movement cost is uniform across the entire map. There are some interesting features you can get with non-uniform costs. E.g. you can make roads very cheap to travel along, which means units will prefer routes that use roads instead of slightly shorter routes that don't use the road. Or you could identify 'dangerous' tiles (within range of enemy defensive buildings) and make them more expensive to travel along, so the pathfinder will prefer paths that avoid dangerous tiles even if they have to travel slightly further. The game's current pathfinder supports non-uniform costs, but I'm now thinking that it's not really all that useful a feature, and it may add significant complexity, so it's probably best to abandon it and focus on getting basic uniform-cost movement working well.
What I'm currently planning to do is experiment with JPS and see if it actually works in practice - it's nice to have optimal paths (to reduce the chances of players noticing weird behaviour), and it claims to be competitive with HPA*, but I think that will depend significantly on implementation details, so it would be valuable to have an implementation to test and optimise.
What about restricting buildings on a 2D grid (it obliviously complicate rotations but many RTS do this, letting them rotate only by 45/90 degrees) and/or adding to every building a border around it (except on some side of buildings like walls that must be connected) to impose a minimum distance and avoiding creating large obstacles to pathfinder? Will these help?
#103
Posted 09 December 2011 - 04:32 PM
ac892006, on 08 December 2011 - 06:25 PM, said:
errt, on 08 December 2011 - 09:30 PM, said:
Quote
Sylvain Gadrat, on 08 December 2011 - 09:52 PM, said:
Quote
Quote
Quote
For normal large units (siege, ships, etc), I think we should probably encode the size as part of the passability class. We already effectively compute a separate passability map per class, so we'd just need to expand obstructions by the class's size when rasterising to the passability map.
fabio, on 09 December 2011 - 08:18 AM, said:
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
#104
Posted 09 December 2011 - 05:40 PM
0 A.D. Gameplay and UI Developer
#105
Posted 09 December 2011 - 06:05 PM
WhiteTreePaladin, on 09 December 2011 - 05:40 PM, said:
Wildfire Games Project Leader
Contact me: michaeldhafer[at]gmail.com
Support Wildfire Games!
#106
Posted 09 December 2011 - 07:02 PM
0 A.D. Gameplay and UI Developer
#107
Posted 09 December 2011 - 07:08 PM
WhiteTreePaladin, on 09 December 2011 - 07:02 PM, said:
Wildfire Games Project Leader
Contact me: michaeldhafer[at]gmail.com
Support Wildfire Games!
#108
Posted 10 December 2011 - 02:36 PM
Philip I can't really participate in the discussion but there's some interesting things that you brought up, keep 'em coming
#109
Posted 14 December 2011 - 03:38 AM
Experimented with implementing and optimising the aforementioned JPS algorithm and some related pathfinding things.

These are on the 512x512-tile Peloponnese map, with a path (shown in blue) going north around the gulf. The coloured tiles are the ones processed by the A* algorithm (in particular the red ones are on the closed list, and yellow on the open list). In the first image, the standard A* algorithm searches outwards in a roughly circular pattern from the start point, so the red tiles go a long way south, until it gets to around Plataea and heads north-west to the target. The second image, with the JPS optimisation of A*, searches a similar area but it leaves a load of tiles unexplored (white) inside that area, because it realises they're never going to be interesting tiles (there's always an equally good path that doesn't use those tiles).
(The chosen path is slightly different in the two cases, but of the same length. There are lots of equally good paths and JPS always prefers one that goes diagonally as early as possible before going vertically/horizontally.)
In this particular example and this particular implementation (with various optimisations and hopefully no major bugs), the standard A* takes about 6msec to compute the path, and JPS takes about 1.5msec, so it's 4 times faster.
Because our terrain tiles are quite large, and might mark a passage as blocked when actually a unit could easily fit through, it may be useful to use a higher-resolution version of the map:
Here it's scaled to 2048x2048 cells (i.e. 16x as many as before), so it can represent much narrower gaps. Standard A* takes about 130msec (22x slower than with the low-res map); JPS takes about 11msec (7x slower than low-res). Bumping it up again to 4096x4096, standard A* takes about 680msec (another 5x slower), JPS about 22msec (another 2x slower).
The nice thing about JPS in this situation is that it doesn't care too much about the number of tiles - what matters is the number of 'corners' (in some non-technical sense) that the map contains. That means it'll depend heavily on the number of trees in the map (since each tree adds four corners that paths can wrap around), but if the number of trees remains constant then higher-res maps won't be hugely more expensive.
There's two problems with my current implementations of standard A* (simplified and optimised compared to what's currently in the game) and JPS. (Warning: getting somewhat more technical now). Firstly, they assume the target of the path is a single point. In practice it might be a large square (units want to get within e.g. 1 metre of a square building in order to attack it) or a very large circle (archers want to get between minimum and maximum range of a target unit). That makes it harder to tell when the algorithm has reached the goal, and harder (or at least more computationally expensive) to compute the heuristic distance to the target. Secondly, JPS doesn't behave usefully if the target is unreachable - the standard A* can discover whichever reachable tile is closest to the target but JPS might have never looked at that tile.
Reachability is a problem with the game's current pathfinder already; units are happy to try forever to reach a target that they'll never be able to, and the pathfinder is very slow at determining the target is unreachable. I think the sensible solution would be to do something like the MM-Abstraction method to precompute a graph of connected regions, then find all regions connected to the source, and then find the closest tile to the target out of all the tiles in those reachable regions. That'll help equally for standard A* and JPS.
For non-point targets, I think the easiest efficient solution may be to simply swap the source and target of the path. The source is always a single point (typically the unit that's moving), so it's easy to run A* towards that point. The target may be multiple tiles, but I think it's easy to make A* start with multiple cells (just shove them all onto the algorithm's open list with g=0 at the start). So finding paths from multiple target tiles towards the single source point should be straightforward, unless I'm getting confused as to how this all works. Then it needs to be integrated with the reachability thing for the previous problem, since the target shape might be half reachable and half not.
That's probably all doable; just needs some more work to actually do it.
The other big problem is how to make units follow the long-range paths while avoiding dynamic obstacles (e.g. other units), and also to not constrain units to moving along tile boundaries (which would look very unnatural). Currently that's the job of the short-range points-of-visibility pathfinder, which uses the detailed obstruction geometry (squares with arbitrary (non-tile-based) location and rotation). To fix discrepancies between long and short pathfinders, it would probably be better if it used the same high-res obstruction tile map that the long pathfinder uses, and then it can add on the dynamic unit obstructions (which can have non-tile-based positions but don't support rotation) to find a usable route, with the added benefit that it will now only have to deal with perfectly horizontal/vertical lines. Alternatively, maybe it would be simpler and/or faster to reuse the tile-based A* over a short range with the dynamic obstructions added onto it (perhaps at an even higher resolution). I don't really know about that - I suppose I need to experiment a bit more.
(In any case, this won't get finished before the next alpha release, so I'll have to leave it until afterwards - that's kind of annoying but I think it's worth taking the time to solve the problem properly. Got a PhD viva next week so I won't be able to concentrate on game stuff until then, but I'll try cleaning up some of the quicker problems with saved games and other bugs.)
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
#110
Posted 14 December 2011 - 05:10 AM
Ykkrosh, on 14 December 2011 - 03:38 AM, said:
Oh and it may be assumed, but your latest changes require uniform terrain cost?
Wildfire Games Programmer
Contact me: ben@wildfiregames.com
#111
Posted 15 December 2011 - 02:16 PM
Quote
Does that mean you've got more than one?? Anyway good luck! Maybe you guys could push back the Alpha 8 deadline a bit to allow for Philip's pathfinding awesomeness to be implemented in time
#112
Posted 15 December 2011 - 10:08 PM
Android_, on 15 December 2011 - 02:16 PM, said:
Erik Johansson [ aka feneur ]
Wildfire Games
Contact me: feneur@wildfiregames.com
Support Wildfire Games!
#113
Posted 18 January 2012 - 10:15 PM
I hate to be a downer but I'm a bit disappointed by the fundraising campaign. Both Pledgies were explicitly set up to hire a full-time programmer in order to speed up development:
Quote
It seems this is not quite what is happening though. It's not that I'm unhappy with Philip's work, not at all, and I do understand he is a busy man, it's just that we donated for a full-time month.
#114
Posted 18 January 2012 - 10:32 PM
Android_, on 18 January 2012 - 10:15 PM, said:
I hate to be a downer but I'm a bit disappointed by the fundraising campaign. Both Pledgies were explicitly set up to hire a full-time programmer in order to speed up development:
It seems this is not quite what is happening though. It's not that I'm unhappy with Philip's work, not at all, and I do understand he is a busy man, it's just that we donated for a full-time month.
http://trac.wildfiregames.com/timeline
#115
Posted 18 January 2012 - 10:38 PM
Quote
Edited by Android_, 18 January 2012 - 10:39 PM.
#116
Posted 18 January 2012 - 10:39 PM
#117
Posted 18 January 2012 - 11:50 PM
liamdawe, on 18 January 2012 - 10:39 PM, said:
It is good that you care though, and I hope seeing your comments will encourage Philip to prioritize working on the game. As I said though, Philip is only getting paid after work has been done, so it's not like he's gotten money for a full month already and just hasn't done all the work yet. If against all odds Philip will not be able to work all the days we have gotten donations for we will find someone else of the programmers who are able to do the same, so even though in the worst case it might take some time the money will go to developing the game and nothing else. With the caveat mentioned on the Pledgie page:
Quote
If the donations go above the target, then we’ll use that excess to pay the developer for as many 8 hour work days as possible until funds run out.
Anything left over will be put aside to help with website, forum, and SVN server maintenance.
However, we should definitely update the Pledgie page to highlight the fact that the month of full time work means 20 days of eight hours of work each, and not necessarily a calendar month. We had originally hoped, and I'm sure Philip had as well, that it would more or less completely correspond to a calendar month which meant we didn't think it was necessary to mention. As things are we should definitely be more clear about it.
Erik Johansson [ aka feneur ]
Wildfire Games
Contact me: feneur@wildfiregames.com
Support Wildfire Games!
#118
Posted 19 January 2012 - 12:05 AM
Quote
Basically this seems to be a communication issue. WFG should have come to terms with what the work would be going to entail; whether it would be a calender month or 30 working days etc. beforehand. And then the Pledgies should have been perfectly clear about that. They have been formulated so that it is clear you were aiming for a calender month.
I think there is not much you can do about it now (all you could possibly do is hiring another programmer who will work full-time, but that doesn't make too much sense either). However, this should definitely be avoided in the future.
#119 Guest_afeder_*
Posted 19 January 2012 - 01:02 AM
liamdawe, on 18 January 2012 - 10:39 PM, said:
#120
Posted 19 January 2012 - 01:41 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














