Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarCelestialDatabase.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-20 19:10:41 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-20 19:10:41 +1000
commit607be749451aa40e3619e7ceab0927d1fcec8233 (patch)
tree27bd18fa88ea129754443e916578aa4479cdfdc7 /source/game/StarCelestialDatabase.cpp
parentd0307e7aa77ddc8d15b6d1e036e563f3c9150287 (diff)
Fix server hang while looking for starter world
Diffstat (limited to 'source/game/StarCelestialDatabase.cpp')
-rw-r--r--source/game/StarCelestialDatabase.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/source/game/StarCelestialDatabase.cpp b/source/game/StarCelestialDatabase.cpp
index d5ba7df..dd0bc51 100644
--- a/source/game/StarCelestialDatabase.cpp
+++ b/source/game/StarCelestialDatabase.cpp
@@ -206,9 +206,6 @@ 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);
- // We don't need this lock, 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);
@@ -299,7 +296,12 @@ List<CelestialCoordinate> CelestialMasterDatabase::scanSystems(RectI const& regi
List<CelestialCoordinate> systems;
for (auto const& chunkLocation : chunkIndexesFor(region)) {
- auto const& chunkData = getChunk(chunkLocation);
+ auto const& chunkData = getChunk(chunkLocation, [&](std::function<void()>&& func) {
+ locker.unlock();
+ func();
+ locker.lock();
+ });
+ locker.unlock();
for (auto const& pair : chunkData.systemParameters) {
Vec3I systemLocation = pair.first;
if (region.contains(systemLocation.vec2())) {
@@ -311,6 +313,7 @@ List<CelestialCoordinate> CelestialMasterDatabase::scanSystems(RectI const& regi
systems.append(CelestialCoordinate(systemLocation));
}
}
+ locker.lock();
}
return systems;
}
@@ -378,8 +381,8 @@ Maybe<CelestialOrbitRegion> CelestialMasterDatabase::orbitRegion(
return {};
}
-CelestialChunk const& CelestialMasterDatabase::getChunk(Vec2I const& chunkIndex) {
- return m_chunkCache.get(chunkIndex, [this](Vec2I const& chunkIndex) -> CelestialChunk {
+CelestialChunk const& CelestialMasterDatabase::getChunk(Vec2I const& chunkIndex, UnlockDuringFunction unlockDuring) {
+ return m_chunkCache.get(chunkIndex, [&](Vec2I const& chunkIndex) -> CelestialChunk {
auto versioningDatabase = Root::singleton().versioningDatabase();
if (m_database.isOpen()) {
@@ -394,7 +397,12 @@ CelestialChunk const& CelestialMasterDatabase::getChunk(Vec2I const& chunkIndex)
}
}
- auto newChunk = produceChunk(chunkIndex);
+ CelestialChunk newChunk;
+ auto producer = [&]() { newChunk = produceChunk(chunkIndex); };
+ if (unlockDuring)
+ unlockDuring(producer);
+ else
+ producer();
if (m_database.isOpen()) {
auto versionedChunk = versioningDatabase->makeCurrentVersionedJson("CelestialChunk", newChunk.toJson());
m_database.insert(DataStreamBuffer::serialize(chunkIndex),