Example #1
0
        /// <summary>
        /// Starts saving the game in the background. This function is not reentrant!
        /// </summary>
        /// <param name="filename">The file name where the save should be stored.</param>
        public void StartSave(string filename)
        {
            var  buffer = new MemoryStream(BUFFER_SIZE);
            var  inst   = SaveLoader.Instance;
            bool save   = true;

            if (inst != null)
            {
                if (FastSaveOptions.Instance.DelegateSave)
                {
                    FastSerializationManager.ClearSmart();
                }
                else
                {
                    KSerialization.Manager.Clear();
                }
#if DEBUG
                PUtil.LogDebug("Starting serialization of save");
#endif
                bool compress = true;
                // This field is currently always true
                if (COMPRESS_SAVE_DATA != null)
                {
                    try {
                        compress = COMPRESS_SAVE_DATA.Get(inst);
                    } catch { }
                }
                // Keep this part on the foreground
                try {
                    SAVE.Invoke(inst, new BinaryWriter(buffer));
                } catch (Exception e) {
                    buffer.Dispose();
                    PUtil.LogError("Error when saving game:");
                    PUtil.LogException(e);
                    save = false;
                }
                // In Unity 4 GetComponent no longer works on background threads
                if (save)
                {
                    StartSave(new BackgroundSaveData(buffer, compress, filename));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Applied before Clear runs.
 /// </summary>
 internal static bool Prefix()
 {
     FastSerializationManager.ClearSmart();
     return(false);
 }