/// <summary> /// Causes the world to unloaded in full form as soon as possible. /// Allows inputting a callback to be fired when the unload completes. /// Might not necessarily be immediate. /// Will terminate the world thread. /// </summary> /// <param name="wrapUp">The action to fire when the unload completes.</param> public void UnloadFully(Action wrapUp) { if (wrapUp != null) { UnloadCallback = wrapUp; } NeedShutdown = true; if (Thread.CurrentThread != Execution) { return; } Config.Set("general.time", GlobalTickTime); // TODO: update this value and save occasionally, even if the config is unedited - in case of bad shutdown! string cfg = Config.SaveToString(); // TODO: Journaling save. lock (SaveWorldCFGLock) { TheServer.Files.WriteText("saves/" + Name + "/world.fds", cfg); } long cid; lock (TheServer.CIDLock) { cid = TheServer.cID; } TheServer.Files.WriteText("saves/" + Name + "/eid.txt", cid.ToString()); MainRegion.UnloadFully(); MainRegion = null; UnloadCallback?.Invoke(); // TODO: Should we really just be aborting the current thread? Execution.Abort(); Execution = null; }
/// <summary> /// Causes the world to unloaded in full form as soon as possible. /// Allows inputting a callback to be fired when the unload completes. /// Might not necessarily be immediate. /// Will terminate the world thread. /// </summary> /// <param name="wrapUp">The action to fire when the unload completes.</param> public void UnloadFully(Action wrapUp) { if (wrapUp != null) { UnloadCallback = wrapUp; } NeedShutdown.Cancel(); if (Thread.CurrentThread != Execution) { return; } SaveConfig(); MainRegion.UnloadFully(); MainRegion = null; UnloadCallback?.Invoke(); }
public void UnloadFully(Action wrapUp) { if (wrapUp != null) { UnloadCallback = wrapUp; } NeedShutdown = true; if (Thread.CurrentThread != Execution) { return; } // TODO: Lock safely! MainRegion.UnloadFully(); MainRegion = null; UnloadCallback?.Invoke(); Execution.Abort(); Execution = null; }