MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / triggerWorldCreation

Method triggerWorldCreation

source/game/StarUniverseServer.cpp:2041–2068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2039}
2040
2041Maybe<WorldServerThreadPtr> UniverseServer::triggerWorldCreation(WorldId const& worldId) {
2042 if (!m_worlds.contains(worldId)) {
2043 if (auto promise = makeWorldPromise(worldId)) {
2044 m_worlds.add(worldId, promise.take());
2045 return {};
2046 } else {
2047 return WorldServerThreadPtr();
2048 }
2049 } else {
2050 auto& maybeWorldPromise = m_worlds.get(worldId);
2051 try {
2052 // If the promise is reset, this means that the promise threw an
2053 // exception, return nullptr to signify error.
2054 if (!maybeWorldPromise)
2055 return WorldServerThreadPtr();
2056
2057 if (!maybeWorldPromise->poll())
2058 return {};
2059
2060 return maybeWorldPromise->get();
2061 } catch (std::exception const& e) {
2062 maybeWorldPromise.reset();
2063 Logger::error("UniverseServer: error during world create: {}", outputException(e, true));
2064 worldDiedWithError(worldId);
2065 return WorldServerThreadPtr();
2066 }
2067 }
2068}
2069
2070Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::makeWorldPromise(WorldId const& worldId) {
2071 if (auto celestialWorld = worldId.ptr<CelestialWorldId>())

Callers

nothing calls this directly

Calls 8

errorFunction · 0.85
outputExceptionFunction · 0.50
containsMethod · 0.45
addMethod · 0.45
takeMethod · 0.45
getMethod · 0.45
pollMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected