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.
74 lines
1.9 KiB
74 lines
1.9 KiB
#include "crawl.hpp" |
|
|
|
#include <type_traits> |
|
|
|
#include <function_ref.hpp> |
|
|
|
#include "engine/displacement.hpp" |
|
|
|
namespace devilution { |
|
namespace { |
|
|
|
bool CrawlFlipsX(Displacement mirrored, tl::function_ref<bool(Displacement)> function) |
|
{ |
|
for (const Displacement displacement : { mirrored.flipX(), mirrored }) { |
|
if (!function(displacement)) |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
bool CrawlFlipsY(Displacement mirrored, tl::function_ref<bool(Displacement)> function) |
|
{ |
|
for (const Displacement displacement : { mirrored, mirrored.flipY() }) { |
|
if (!function(displacement)) |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
bool CrawlFlipsXY(Displacement mirrored, tl::function_ref<bool(Displacement)> function) |
|
{ |
|
for (const Displacement displacement : { mirrored.flipX(), mirrored, mirrored.flipXY(), mirrored.flipY() }) { |
|
if (!function(displacement)) |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
} // namespace |
|
|
|
bool DoCrawl(unsigned radius, tl::function_ref<bool(Displacement)> function) |
|
{ |
|
if (radius == 0) |
|
return function(Displacement { 0, 0 }); |
|
|
|
if (!CrawlFlipsY({ 0, static_cast<int>(radius) }, function)) |
|
return false; |
|
for (unsigned i = 1; i < radius; i++) { |
|
if (!CrawlFlipsXY({ static_cast<int>(i), static_cast<int>(radius) }, function)) |
|
return false; |
|
} |
|
if (radius > 1) { |
|
if (!CrawlFlipsXY({ static_cast<int>(radius) - 1, static_cast<int>(radius) - 1 }, function)) |
|
return false; |
|
} |
|
if (!CrawlFlipsX({ static_cast<int>(radius), 0 }, function)) |
|
return false; |
|
for (unsigned i = 1; i < radius; i++) { |
|
if (!CrawlFlipsXY({ static_cast<int>(radius), static_cast<int>(i) }, function)) |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
bool DoCrawl(unsigned minRadius, unsigned maxRadius, tl::function_ref<bool(Displacement)> function) |
|
{ |
|
for (unsigned i = minRadius; i <= maxRadius; i++) { |
|
if (!DoCrawl(i, function)) |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
} // namespace devilution
|
|
|