private void StateAccessed(int frame)
        {
            if (frame == 0 && _movie.StartsFromSavestate)
            {
                return;
            }

            StateManagerState state = States[frame];
            bool removed            = accessed.Remove(state);

            accessed.Add(state);

            if (States[frame].IsOnDisk)
            {
                if (!States[accessed[0].Frame].IsOnDisk)
                {
                    MoveStateToDisk(accessed[0].Frame);
                }
                MoveStateToMemory(frame);
            }

            if (!removed && accessed.Count > maxStates)
            {
                accessed.RemoveAt(0);
            }
        }
Beispiel #2
0
        public void LoadBranchStates(BinaryReader br)
        {
            try
            {
                int c = br.ReadInt32();
                _branchStates = new SortedList <int, SortedList <int, StateManagerState> >(c);
                while (c > 0)
                {
                    int key  = br.ReadInt32();
                    int c2   = br.ReadInt32();
                    var list = new SortedList <int, StateManagerState>(c2);
                    while (c2 > 0)
                    {
                        int key2  = br.ReadInt32();
                        var state = StateManagerState.Read(br, this);
                        list.Add(key2, state);
                        c2--;
                    }

                    _branchStates.Add(key, list);
                    c--;
                }
            }
            catch (EndOfStreamException)
            {
                // Bad!
            }
        }
Beispiel #3
0
        private int FindState(StateManagerState s)
        {
            if (!_states.ContainsValue(s))
            {
                return(-1);
            }

            return(s.Frame);
        }
Beispiel #4
0
 public void ClearStateHistory()
 {
     if (_states.Any())
     {
         StateManagerState power = _states.Values.First(s => s.Frame == 0);
         _states.Clear();
         SetState(0, power.State);
         Used = (ulong)power.State.Length;
         NdbDatabase?.Clear();
     }
 }
        public void ClearStateHistory()
        {
            if (States.Any())
            {
                StateManagerState power = States.Values.FirstOrDefault(s => s.Frame == 0);
                StateAccessed(power.Frame);

                States.Clear();
                accessed.Clear();

                SetState(0, power.State);
                Used = (ulong)power.State.Length;

                clearDiskStates();
            }
        }
        private Point findState(StateManagerState s)
        {
            Point ret = new Point(0, -1);

            ret.X = s.Frame;
            if (!States.ContainsValue(s))
            {
                if (BranchStates.ContainsKey(s.Frame))
                {
                    int index = BranchStates[s.Frame].Values.IndexOf(s);
                    ret.Y = BranchStates[s.Frame].Keys.ElementAt(index);
                }
                if (ret.Y == -1)
                {
                    return(new Point(-1, -2));
                }
            }

            return(ret);
        }
Beispiel #7
0
        public void ClearStateHistory()
        {
            if (_states.Any())
            {
                var temp_state          = _states.Values;
                StateManagerState power = null;
                if (temp_state[0].Frame == 0)
                {
                    power = _states.Values.First(s => s.Frame == 0);
                }
                else
                {
                    power = _states.Values[0];
                }

                _states.Clear();
                SetState(0, power.State);
                Used = (ulong)power.State.Length;
                NdbDatabase?.Clear();
            }
        }
Beispiel #8
0
        private void RemoveState(int frame)
        {
            int index = _states.IndexOfKey(frame);

            if (frame < 1 || index < 1)
            {
                return;
            }

            StateManagerState state = _states.ElementAt(index).Value;

            if (state.IsOnDisk)
            {
                state.Dispose();
            }
            else
            {
                Used -= (ulong)state.Length;
            }

            _states.RemoveAt(index);
        }
Beispiel #9
0
        public bool RemoveState(int frame)
        {
            int index = _states.IndexOfKey(frame);

            if (frame < 1 || index < 1)
            {
                return(false);
            }

            StateManagerState state = _states.Values[index];

            if (state.IsOnDisk)
            {
                state.Dispose();
            }
            else
            {
                Used -= (ulong)state.Length;
            }

            _states.RemoveAt(index);

            return(true);
        }
		private Point findState(StateManagerState s)
		{
			Point ret = new Point(0, -1);
			ret.X = s.Frame;
			if (!States.ContainsValue(s))
			{
				if (BranchStates.ContainsKey(s.Frame))
				{
					int index = BranchStates[s.Frame].Values.IndexOf(s);
					ret.Y = BranchStates[s.Frame].Keys.ElementAt(index);
				}
				if (ret.Y == -1)
					return new Point(-1, -2);
			}

			return ret;
		}
        /// <summary>
        /// X is the frame of the state, Y is the branch (-1 for current).
        /// </summary>
        private Point StateToRemove()
        {
            // X is frame, Y is branch
            Point shouldRemove = new Point(-1, -1);

            if (BranchStates.Any() && Settings.EraseBranchStatesFirst)
            {
                var kvp = BranchStates.Count() > 1 ? BranchStates.ElementAt(1) : BranchStates.ElementAt(0);
                shouldRemove.X = kvp.Key;
                shouldRemove.Y = kvp.Value.Keys[0];

                return(shouldRemove);
            }

            int i           = 0;
            int markerSkips = maxStates / 2;

            // lowPrioritySates (e.g. states with only lag frames between them)
            do
            {
                if (lowPriorityStates.Count > i)
                {
                    shouldRemove = findState(lowPriorityStates[i]);
                }
                else
                {
                    break;
                }

                // Keep marker states
                markerSkips--;
                if (markerSkips < 0)
                {
                    shouldRemove.X = -1;
                }
                i++;
            } while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);

            // by last accessed
            markerSkips = maxStates / 2;
            if (shouldRemove.X < 1)
            {
                i = 0;
                do
                {
                    if (accessed.Count > i)
                    {
                        shouldRemove = findState(accessed[i]);
                    }
                    else
                    {
                        break;
                    }

                    // Keep marker states
                    markerSkips--;
                    if (markerSkips < 0)
                    {
                        shouldRemove.X = -1;
                    }
                    i++;
                } while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);
            }

            if (shouldRemove.X < 1)             // only found marker states above
            {
                if (BranchStates.Any() && !Settings.EraseBranchStatesFirst)
                {
                    var kvp = BranchStates.Count() > 1 ? BranchStates.ElementAt(1) : BranchStates.ElementAt(0);
                    shouldRemove.X = kvp.Key;
                    shouldRemove.Y = kvp.Value.Keys[0];
                }
                else
                {
                    StateManagerState s = States.Values[1];
                    shouldRemove.X = s.Frame;
                    shouldRemove.Y = -1;
                }
            }

            return(shouldRemove);
        }