| 48 | } |
| 49 | |
| 50 | bool WorldSystem::LoadWorld(const std::string& path) |
| 51 | { |
| 52 | // Destroy the old world first so its actors release their IDs before |
| 53 | // LoadFromFile calls IDGenerator::Clear(). |
| 54 | if (m_CurrentWorld) |
| 55 | { |
| 56 | if (m_IsPlaying) |
| 57 | { |
| 58 | m_CurrentWorld->OnStop(); |
| 59 | m_IsPlaying = false; |
| 60 | } |
| 61 | m_CurrentWorld->OnShutdown(); |
| 62 | m_CurrentWorld.reset(); |
| 63 | } |
| 64 | |
| 65 | auto candidate = std::make_unique<World>(); |
| 66 | try |
| 67 | { |
| 68 | candidate->LoadFromFile(path); |
| 69 | } |
| 70 | catch (const std::exception&) |
| 71 | { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | m_CurrentWorld = std::move(candidate); |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | bool WorldSystem::SaveWorld(const std::string& path) |
| 80 | { |
no test coverage detected