Hopefully fix server hang while finding a random starter world
This commit is contained in:
parent
b964668a38
commit
5f86e0f027
@ -206,14 +206,16 @@ bool CelestialMasterDatabase::coordinateValid(CelestialCoordinate const& coordin
|
|||||||
|
|
||||||
Maybe<CelestialCoordinate> CelestialMasterDatabase::findRandomWorld(unsigned tries, unsigned trySpatialRange,
|
Maybe<CelestialCoordinate> CelestialMasterDatabase::findRandomWorld(unsigned tries, unsigned trySpatialRange,
|
||||||
function<bool(CelestialCoordinate)> filter, Maybe<uint64_t> seed) {
|
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;
|
RandomSource randSource;
|
||||||
if (seed)
|
if (seed)
|
||||||
randSource.init(*seed);
|
randSource.init(*seed);
|
||||||
for (unsigned i = 0; i < tries; ++i) {
|
for (unsigned i = 0; i < tries; ++i) {
|
||||||
RectI range = xyRange();
|
RectI range = xyRange();
|
||||||
Vec2I randomLocation = Vec2I(randSource.randInt(range.xMin(), range.xMax()), randSource.randInt(range.yMin(), range.yMax()));
|
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))
|
if (!hasChildren(system).value(false))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user