Skip to content

Conversation

@cyberjunk
Copy link

To-Do

  1. Add a bool param 'forceHeuristic' to GetStepTowards to force using heuristic-movement in some cases (e.g. moves known to block, like minions moving around reached master)

Things to improve (but not not required for merge)

  1. Implement JPS

About Astar
Astar is a popular pathfinding algorithm. It offers improvements over Dijkstra's original algorithm by extending its idea with an heuristic. The heuristic will 'direct the searching more likely towards the destination' rather than increasing the evaluated area 'circular' (in Dijkstra). This leads to much less evaluated nodes (in case the destination is reachable). This implementation here operates on grids with 8 adjacent squares and uses 'Octile' heuristic. Moving is not only limited by fully blocked squares, but also dependent on up to 8 different incoming and 8 different outgoing edges from each square to adjacent neighbours.

Caching
To improve the response times and keep calculations low, there are 3 kinds of caches implemented:

  1. Edges-Cache:
  • Lives inside each worker and caches returns of 'expansive' BSPCanMoveInRoom() queries
  • Gets cleared when a sector moves or a texture changes (but NOT when blockers move)
  1. Path-Cache:
  • Lives inside the blakserv mainthread and caches path returns from the workers.
  • Gets cleared when a sector moves or a texture changes (but NOT when blockers move)
  • Steps from cached paths are validated again (due to blockers) before actually performed
  1. NoPath-Cache:
  • Lives inside the blakserv mainthread and caches returns of unreachable queries.
  • Gets cleared when a sector moves or a texture changes
  • Entries are only valid for 5 seconds, allowing blocked paths, blocked by moved objects, to be released again.

C++ 2011
This uses a couple of ::std classes, such as ::std::mutex, ::std::queue, ::std::map and others.
Except for a single 'PostThreadMessage()' in astar.c this is supposed to be fully linux compatible.

queue.h
This pull brings a new 'queue.h' file to blakserv. It contains a template class for a threadsafe queue as used in consumer&producer patterns. This could become handy for other tasks (for example the mysql module could be refactored using it).

Multithreading architecture
Multithreading is implemented based on a typical producer & consumer pattern. In this case blakserv is the producer of 'Queries' and the workers are the consumers of 'Queries'. On the other hand the workers are the producers of 'Responses' and the blakserv mainthread is the consumer of them. Both directions are fully asynchron and keep locking to a minimum.

@cyberjunk cyberjunk force-pushed the astarbsp3 branch 2 times, most recently from 561e46a to c3bcc29 Compare October 15, 2015 15:36
@treymd treymd modified the milestone: 1.0.17.0 Oct 15, 2015
@cyberjunk cyberjunk force-pushed the astarbsp3 branch 2 times, most recently from f1e3946 to 574f6ab Compare October 21, 2015 23:43
@cyberjunk cyberjunk force-pushed the astarbsp3 branch 2 times, most recently from 8903be5 to 21a2b9c Compare November 2, 2015 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants