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

Method celestialWorldPromise

source/game/StarUniverseServer.cpp:2159–2198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2157}
2158
2159Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::celestialWorldPromise(CelestialWorldId const& celestialWorldId) {
2160 if (!celestialWorldId)
2161 return {};
2162
2163 auto storageDirectory = m_storageDirectory;
2164 auto celestialDatabase = m_celestialDatabase;
2165 auto universeClock = m_universeClock;
2166
2167 return m_workerPool.addProducer<WorldServerThreadPtr>([this, celestialWorldId, storageDirectory, celestialDatabase, universeClock]() {
2168 WorldServerPtr worldServer;
2169 String storageFile = File::relativeTo(storageDirectory, strf("{}.world", celestialWorldId.filename()));
2170 if (File::isFile(storageFile)) {
2171 try {
2172 Logger::info("UniverseServer: Loading celestial world {}", celestialWorldId);
2173 worldServer = make_shared<WorldServer>(File::open(storageFile, IOMode::ReadWrite));
2174 } catch (std::exception const& e) {
2175 Logger::error("UniverseServer: Could not load celestial world {}, removing! Cause: {}",
2176 celestialWorldId, outputException(e, false));
2177 File::rename(storageFile, strf("{}.{}.fail", storageFile, Time::millisecondsSinceEpoch()));
2178 }
2179 }
2180
2181 if (!worldServer) {
2182 Logger::info("UniverseServer: Creating celestial world {}", celestialWorldId);
2183 auto worldTemplate = make_shared<WorldTemplate>(celestialWorldId, celestialDatabase);
2184 worldServer = make_shared<WorldServer>(worldTemplate, File::open(storageFile, IOMode::ReadWrite | IOMode::Truncate));
2185 }
2186
2187 worldServer->setUniverseSettings(m_universeSettings);
2188 worldServer->setReferenceClock(universeClock);
2189 worldServer->initLua(this);
2190
2191 auto worldThread = make_shared<WorldServerThread>(worldServer, celestialWorldId);
2192 worldThread->setPause(m_pause);
2193 worldThread->start();
2194 worldThread->setUpdateAction(bind(&UniverseServer::worldUpdated, this, _1));
2195
2196 return worldThread;
2197 });
2198}
2199
2200Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::instanceWorldPromise(InstanceWorldId const& instanceWorldId) {
2201 auto storageDirectory = m_storageDirectory;

Callers

nothing calls this directly

Calls 10

strfFunction · 0.85
errorFunction · 0.85
setUniverseSettingsMethod · 0.80
initLuaMethod · 0.80
outputExceptionFunction · 0.50
filenameMethod · 0.45
setReferenceClockMethod · 0.45
setPauseMethod · 0.45
startMethod · 0.45
setUpdateActionMethod · 0.45

Tested by

no test coverage detected