| 2319 | } |
| 2320 | |
| 2321 | SystemWorldServerThreadPtr UniverseServer::createSystemWorld(Vec3I const& location) { |
| 2322 | if (!m_systemWorlds.contains(location)) { |
| 2323 | SystemWorldServerPtr systemWorld; |
| 2324 | |
| 2325 | String storageFile = File::relativeTo(m_storageDirectory, strf("{}_{}_{}.system", location[0], location[1], location[2])); |
| 2326 | bool loadedFromStorage = false; |
| 2327 | if (File::isFile(storageFile)) { |
| 2328 | Logger::info("UniverseServer: Loading system world {} from disk storage", location); |
| 2329 | try { |
| 2330 | auto versioningDatabase = Root::singleton().versioningDatabase(); |
| 2331 | VersionedJson versionedStore = VersionedJson::readFile(storageFile); |
| 2332 | Json store = versioningDatabase->loadVersionedJson(versionedStore, "System"); |
| 2333 | |
| 2334 | systemWorld = make_shared<SystemWorldServer>(store, m_universeClock, m_celestialDatabase); |
| 2335 | loadedFromStorage = true; |
| 2336 | } catch (std::exception const& e) { |
| 2337 | Logger::error("UniverseServer: Failed to load system {} from disk storage, re-creating. Cause: {}", location, outputException(e, false)); |
| 2338 | File::rename(storageFile, strf("{}.{}.fail", storageFile, Time::millisecondsSinceEpoch())); |
| 2339 | loadedFromStorage = false; |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | if (!loadedFromStorage) { |
| 2344 | Logger::info("UniverseServer: Creating new system world at location {}", location); |
| 2345 | systemWorld = make_shared<SystemWorldServer>(location, m_universeClock, m_celestialDatabase); |
| 2346 | } |
| 2347 | |
| 2348 | auto systemThread = make_shared<SystemWorldServerThread>(location, systemWorld, storageFile); |
| 2349 | systemThread->setUpdateAction(bind(&UniverseServer::systemWorldUpdated, this, _1)); |
| 2350 | systemThread->start(); |
| 2351 | m_systemWorlds.set(location, systemThread); |
| 2352 | } |
| 2353 | |
| 2354 | return m_systemWorlds.get(location); |
| 2355 | } |
| 2356 | |
| 2357 | bool UniverseServer::instanceWorldStoredOrActive(InstanceWorldId const& worldId) const { |
| 2358 | String storageFile = File::relativeTo(m_storageDirectory, strf("unique-{}.world", worldId.instance)); |
nothing calls this directly
no test coverage detected