You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
#include <type_traits> |
|
|
|
#include <function_ref.hpp> |
|
|
|
#include "engine/displacement.hpp" |
|
|
|
namespace devilution { |
|
|
|
/** |
|
* CrawlTable specifies X- and Y-coordinate deltas from a missile target coordinate. |
|
* |
|
* n=4 |
|
* |
|
* y |
|
* ^ |
|
* | 1 |
|
* | 3#4 |
|
* | 2 |
|
* +-----> x |
|
* |
|
* n=16 |
|
* |
|
* y |
|
* ^ |
|
* | 314 |
|
* | B7 8C |
|
* | F # G |
|
* | D9 AE |
|
* | 526 |
|
* +-------> x |
|
*/ |
|
|
|
bool DoCrawl(unsigned radius, tl::function_ref<bool(Displacement)> function); |
|
bool DoCrawl(unsigned minRadius, unsigned maxRadius, tl::function_ref<bool(Displacement)> function); |
|
|
|
template <typename F> |
|
auto Crawl(unsigned radius, F function) -> std::invoke_result_t<decltype(function), Displacement> |
|
{ |
|
std::invoke_result_t<decltype(function), Displacement> result; |
|
DoCrawl(radius, [&result, &function](Displacement displacement) -> bool { |
|
result = function(displacement); |
|
return !result; |
|
}); |
|
return result; |
|
} |
|
|
|
template <typename F> |
|
auto Crawl(unsigned minRadius, unsigned maxRadius, F function) -> std::invoke_result_t<decltype(function), Displacement> |
|
{ |
|
std::invoke_result_t<decltype(function), Displacement> result; |
|
DoCrawl(minRadius, maxRadius, [&result, &function](Displacement displacement) -> bool { |
|
result = function(displacement); |
|
return !result; |
|
}); |
|
return result; |
|
} |
|
|
|
} // namespace devilution
|
|
|