public ZwinderStateManager(ZwinderStateManagerSettings settings)
        {
            Settings = settings;

            _current = new ZwinderBuffer(new RewindConfig
            {
                UseCompression    = settings.CurrentUseCompression,
                BufferSize        = settings.CurrentBufferSize,
                TargetFrameLength = settings.CurrentTargetFrameLength
            });
            _recent = new ZwinderBuffer(new RewindConfig
            {
                UseCompression    = settings.RecentUseCompression,
                BufferSize        = settings.RecentBufferSize,
                TargetFrameLength = settings.RecentTargetFrameLength
            });

            _highPriority = new ZwinderBuffer(new RewindConfig
            {
                UseCompression    = settings.PriorityUseCompression,
                BufferSize        = settings.PriorityBufferSize,
                TargetFrameLength = settings.PriorityTargetFrameLength
            });

            _ancientInterval = settings.AncientStateInterval;
            _originalState   = NonState;
        }
        public static ZwinderStateManager Create(BinaryReader br, ZwinderStateManagerSettings settings, Func <int, bool> reserveCallback)
        {
            // Initial format had no version number, but I think it's a safe bet no valid file has buffer size 2^56 or more so this should work.
            int version = br.ReadByte();

            var current = ZwinderBuffer.Create(br, settings.Current(), version == 0);
            var recent  = ZwinderBuffer.Create(br, settings.Recent());
            var gaps    = ZwinderBuffer.Create(br, settings.GapFiller());

            if (version == 0)
            {
                settings.AncientStateInterval = br.ReadInt32();
            }

            var ret = new ZwinderStateManager(current, recent, gaps, reserveCallback, settings);

            var ancientCount = br.ReadInt32();

            for (var i = 0; i < ancientCount; i++)
            {
                var key    = br.ReadInt32();
                var length = br.ReadInt32();
                var data   = br.ReadBytes(length);
                ret._reserved.Add(key, data);
            }

            ret.RebuildStateCache();

            return(ret);
        }
Beispiel #3
0
        public static ZwinderStateManager Create(BinaryReader br, ZwinderStateManagerSettings settings, Func <int, bool> reserveCallback)
        {
            var current = ZwinderBuffer.Create(br);
            var recent  = ZwinderBuffer.Create(br);
            var gaps    = ZwinderBuffer.Create(br);

            var ancientInterval = br.ReadInt32();

            var ret = new ZwinderStateManager(current, recent, gaps, ancientInterval, reserveCallback)
            {
                Settings = settings
            };

            var ancientCount = br.ReadInt32();

            for (var i = 0; i < ancientCount; i++)
            {
                var key    = br.ReadInt32();
                var length = br.ReadInt32();
                var data   = br.ReadBytes(length);
                ret._reserved.Add(key, data);
            }

            ret.RebuildStateCache();

            return(ret);
        }
 private ZwinderStateManager(ZwinderBuffer current, ZwinderBuffer recent, ZwinderBuffer gapFiller, Func <int, bool> reserveCallback, ZwinderStateManagerSettings settings)
 {
     _current         = current;
     _recent          = recent;
     _gapFiller       = gapFiller;
     _reserveCallback = reserveCallback;
     Settings         = settings;
     _ancientInterval = settings.AncientStateInterval;
     // init the reserved dictionary
     RebuildReserved();
 }
Beispiel #5
0
        public void UpdateSettings(ZwinderStateManagerSettings settings, bool keepOldStates = false)
        {
            Settings = settings;

            _current   = UpdateBuffer(_current, settings.Current(), keepOldStates);
            _recent    = UpdateBuffer(_recent, settings.Recent(), keepOldStates);
            _gapFiller = UpdateBuffer(_gapFiller, settings.GapFiller(), keepOldStates);

            if (keepOldStates)
            {
                // For ancients ... lets just make sure we aren't keeping states with a gap below the new interval
                if (settings.AncientStateInterval > _ancientInterval)
                {
                    int        lastReserved   = 0;
                    List <int> framesToRemove = new List <int>();
                    foreach (int f in _reserved.Keys)
                    {
                        if (!_reserveCallback(f) && f - lastReserved < settings.AncientStateInterval)
                        {
                            framesToRemove.Add(f);
                        }
                        else
                        {
                            lastReserved = f;
                        }
                    }
                    foreach (int f in framesToRemove)
                    {
                        if (f != 0)
                        {
                            EvictReserved(f);
                        }
                    }
                }
            }
            else
            {
                List <int> framesToRemove = new List <int>();
                foreach (int f in _reserved.Keys)
                {
                    if (f != 0 && !_reserveCallback(f))
                    {
                        framesToRemove.Add(f);
                    }
                }
                foreach (int f in framesToRemove)
                {
                    EvictReserved(f);
                }
            }

            _ancientInterval = settings.AncientStateInterval;
            RebuildStateCache();
        }
Beispiel #6
0
        public ZwinderStateManagerSettings(ZwinderStateManagerSettings settings)
        {
            CurrentUseCompression    = settings.CurrentUseCompression;
            CurrentBufferSize        = settings.CurrentBufferSize;
            CurrentTargetFrameLength = settings.CurrentTargetFrameLength;

            RecentUseCompression    = settings.RecentUseCompression;
            RecentBufferSize        = settings.RecentBufferSize;
            RecentTargetFrameLength = settings.RecentTargetFrameLength;

            GapsUseCompression    = settings.GapsUseCompression;
            GapsBufferSize        = settings.GapsBufferSize;
            GapsTargetFrameLength = settings.GapsTargetFrameLength;

            AncientStateInterval = settings.AncientStateInterval;
        }
        private void LoadTasprojExtras(ZipStateLoader bl)
        {
            bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
            {
                LagLog.Load(tr);
            });

            bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
            {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        Markers.Add(new TasMovieMarker(line));
                    }
                }
            });

            if (GetClientSettingsOnLoad != null)
            {
                string clientSettings = "";
                bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            clientSettings = line;
                        }
                    }
                });

                if (!string.IsNullOrWhiteSpace(clientSettings))
                {
                    GetClientSettingsOnLoad(clientSettings);
                }
            }

            bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr)
            {
                VerificationLog.Clear();
                while (true)
                {
                    var line = tr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }

                    if (line.StartsWith("|"))
                    {
                        VerificationLog.Add(line);
                    }
                }
            });

            Branches.Load(bl, this);

            bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
            {
                var json = tr.ReadToEnd();
                try
                {
                    TasSession = JsonConvert.DeserializeObject <TasSession>(json);
                }
                catch
                {
                    // Do nothing, and use default settings instead
                }
            });

            ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings();

            bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
            {
                var json = tr.ReadToEnd();
                try
                {
                    settings = JsonConvert.DeserializeObject <ZwinderStateManagerSettings>(json);
                }
                catch
                {
                    // Do nothing, and use default settings instead
                }
            });

            bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
            {
                TasStateManager?.Dispose();
                TasStateManager = ZwinderStateManager.Create(br, settings, IsReserved);
            });
        }
        internal ZwinderStateManager(ZwinderStateManagerSettings settings, Func <int, bool> reserveCallback)
        {
            UpdateSettings(settings, false);

            _reserveCallback = reserveCallback;
        }
 public void UpdateSettings(ZwinderStateManagerSettings settings) => Settings = settings;
Beispiel #10
0
        private void LoadTasprojExtras(ZipStateLoader bl)
        {
            bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
            {
                LagLog.Load(tr);
            });

            bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
            {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        Markers.Add(new TasMovieMarker(line));
                    }
                }
            });

            if (GetClientSettingsOnLoad != null)
            {
                string clientSettings = "";
                bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            clientSettings = line;
                        }
                    }
                });

                if (!string.IsNullOrWhiteSpace(clientSettings))
                {
                    GetClientSettingsOnLoad(clientSettings);
                }
            }

            bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr)
            {
                VerificationLog.Clear();
                while (true)
                {
                    var line = tr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }

                    if (line.StartsWith("|"))
                    {
                        VerificationLog.Add(line);
                    }
                }
            });

            Branches.Load(bl, this);

            bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
            {
                var json = tr.ReadToEnd();
                try
                {
                    TasSession = JsonConvert.DeserializeObject <TasSession>(json);
                }
                catch
                {
                    // Do nothing, and use default settings instead
                }
            });

            ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings();

            bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
            {
                var json = tr.ReadToEnd();
                try
                {
                    settings = JsonConvert.DeserializeObject <ZwinderStateManagerSettings>(json);
                }
                catch
                {
                    // Do nothing, and use default settings instead
                }
            });

            bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
            {
                try
                {
                    TasStateManager?.Dispose();
                    TasStateManager = ZwinderStateManager.Create(br, settings, IsReserved);
                }
                catch
                {
                    // Continue with a fresh manager. If state history got corrupted, the file is still very much useable
                    // and we would want the user to be able to load, and regenerate their state history
                    // however, we still have an issue of how state history got corrupted
                    TasStateManager = new ZwinderStateManager(
                        Session.Settings.DefaultTasStateManagerSettings,
                        IsReserved);
                    Session.PopupMessage("State history was corrupted, clearing and working with a fresh history.");
                }
            });
        }