| 106 | } |
| 107 | |
| 108 | void WorldSystem::Stop() |
| 109 | { |
| 110 | if (!m_CurrentWorld || !m_IsPlaying) |
| 111 | return; |
| 112 | m_CurrentWorld->OnStop(); |
| 113 | m_IsPlaying = false; |
| 114 | |
| 115 | // Restore the world to its pre-play state. |
| 116 | if (!m_PlaySnapshot.empty() && std::filesystem::exists(m_PlaySnapshot)) |
| 117 | { |
| 118 | // Destroy the play world BEFORE loading the snapshot so that |
| 119 | // Actor::~Actor() releases IDs before LoadFromFile calls IDGenerator::Clear(). |
| 120 | m_CurrentWorld->OnShutdown(); |
| 121 | m_CurrentWorld.reset(); |
| 122 | |
| 123 | auto restored = std::make_unique<World>(); |
| 124 | restored->LoadFromFile(m_PlaySnapshot); |
| 125 | restored->SetCurrentPath(m_PrePlayPath); |
| 126 | m_CurrentWorld = std::move(restored); |
| 127 | // LoadFromFile already ran OnInit (Pass 3) — no second call needed. |
| 128 | std::filesystem::remove(m_PlaySnapshot); |
| 129 | m_PlaySnapshot.clear(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void WorldSystem::RequestSceneTransition(const std::string& path) |
| 134 | { |
no test coverage detected