layers/craters/generation/cell_cache.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/layers/craters/generation/cell_cache.h" | ||
| 2 | |||
| 3 | #include "terraingen/noise/hash.h" | ||
| 4 | #include "terraingen/util/log.h" | ||
| 5 | |||
| 6 | namespace terraingen { | ||
| 7 | |||
| 8 | 5734404 | std::size_t CraterCellCache::KeyHash::operator()(const Key& key) const { | |
| 9 | const UVec3 hash = | ||
| 10 | 5734404 | Pcg3dHash({static_cast<std::uint32_t>(key.exponent), static_cast<std::uint32_t>(key.i), | |
| 11 | 5734404 | static_cast<std::uint32_t>(key.j)}); | |
| 12 | 5734404 | return (static_cast<std::size_t>(hash.x) << 32) ^ hash.y; | |
| 13 | } | ||
| 14 | |||
| 15 | 886 | CraterCellCache::CraterCellCache(std::size_t maxCraters) | |
| 16 | 887 | : cache_( | |
| 17 | 107469 | maxCraters, [](const CraterList& craters) { return craters.Size(); }, | |
| 18 | 887 | [maxCraters](std::size_t evicted) { | |
| 19 | 369 | LogDebug("craters", "Crater cache evicted ", evicted, " cells to stay within ", | |
| 20 | 369 | maxCraters, " craters"); | |
| 21 | 1254 | }) {} | |
| 22 | |||
| 23 | 363513 | CellCraterSource CachedCellCraters(CraterCellCache& cache, const SurfaceCells& cells, | |
| 24 | const SizeFrequencyDistribution& density, | ||
| 25 | const CraterAgeModel& ages, std::uint32_t seed) { | ||
| 26 | 363513 | return [&cache, &cells, &density, &ages, seed](const CraterBand& band, const CellIndex& cell) { | |
| 27 | ✗ | return cache.Get(band.exponent, cell, [&] { | |
| 28 | 106180 | return GenerateCellCraters(cells, band, cell, density, ages, seed); | |
| 29 | 2764800 | }); | |
| 30 | 727026 | }; | |
| 31 | } | ||
| 32 | |||
| 33 | } // namespace terraingen | ||
| 34 |