Hopefully fix server hang while finding a random starter world

This commit is contained in:
Kae 2023-07-20 17:53:17 +10:00
parent b964668a38
commit 5f86e0f027

View File

@ -206,14 +206,16 @@ bool CelestialMasterDatabase::coordinateValid(CelestialCoordinate const& coordin
Maybe<CelestialCoordinate> CelestialMasterDatabase::findRandomWorld(unsigned tries, unsigned trySpatialRange,
function<bool(CelestialCoordinate)> filter, Maybe<uint64_t> seed) {
RecursiveMutexLocker locker(m_mutex);
//RecursiveMutexLocker locker(m_mutex);
// We don't need this mutex, the other calls are locking anyway.
// Having this here is just stopping other threads from having a go in here until we've found a world.
RandomSource randSource;
if (seed)
randSource.init(*seed);
for (unsigned i = 0; i < tries; ++i) {
RectI range = xyRange();
Vec2I randomLocation = Vec2I(randSource.randInt(range.xMin(), range.xMax()), randSource.randInt(range.yMin(), range.yMax()));
for (auto system : scanSystems(RectI::withCenter(randomLocation, Vec2I::filled(trySpatialRange)))) {
for (auto& system : scanSystems(RectI::withCenter(randomLocation, Vec2I::filled(trySpatialRange)))) {
if (!hasChildren(system).value(false))
continue;