Esempio n. 1
0
 // Enumerate all gap states in reverse order
 private IEnumerable <StateInfo> GapStates()
 {
     for (var i = _gapFiller.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_gapFiller.GetState(i)));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Enumerate high priority states in reverse order
 /// </summary>
 /// <returns></returns>
 private IEnumerable <StateInfo> HighPriorityStates()
 {
     for (var i = _highPriority.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_highPriority.GetState(i)));
     }
 }
 // Enumerate all current and recent states in reverse order
 private IEnumerable <StateInfo> CurrentAndRecentStates()
 {
     for (var i = _current.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_current.GetState(i)));
     }
     for (var i = _recent.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_recent.GetState(i)));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Enumerate all states, excepting high priority, in reverse order
 /// </summary>
 /// <returns></returns>
 private IEnumerable <StateInfo> NormalStates()
 {
     for (var i = _current.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_current.GetState(i)));
     }
     for (var i = _recent.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_recent.GetState(i)));
     }
     for (var i = _ancient.Count - 1; i >= 0; i--)
     {
         yield return(new StateInfo(_ancient[i]));
     }
     yield return(new StateInfo(0, _originalState));
 }
Esempio n. 5
0
        public bool Rewind(int frameToAvoid)
        {
            Sync();
            if (!_active || _count == 0)
            {
                return(false);
            }

            if (_masterFrame == frameToAvoid)
            {
                if (_count > 1)
                {
                    var index = _buffer.Count - 1;
                    RefillMaster(_buffer.GetState(index));
                    _buffer.InvalidateEnd(index);
                    _stateSource.LoadStateBinary(new BinaryReader(new MemoryStream(_master, 0, _masterLength, false)));
                }
                else
                {
                    _stateSource.LoadStateBinary(new BinaryReader(new MemoryStream(_master, 0, _masterLength, false)));
                    _masterFrame = -1;
                }
                _count--;
            }
            else
            {
                // The emulator will frame advance without giving us a chance to
                // re-capture this frame, so we shouldn't invalidate this state just yet.
                _stateSource.LoadStateBinary(new BinaryReader(new MemoryStream(_master, 0, _masterLength, false)));
            }
            return(true);
        }
Esempio n. 6
0
        public bool Rewind(int frameToAvoid)
        {
            if (!Active || Count == 0)
            {
                return(false);
            }
            var index = Count - 1;
            var state = _buffer.GetState(index);

            if (state.Frame == frameToAvoid && Count > 1)
            {
                // Do not decrement index again.  We will "head" this state and not pop it since it will be advanced past
                // without an opportunity to capture.  This is a bit hackish.
                state = _buffer.GetState(index - 1);
            }
            _stateSource.LoadStateBinary(new BinaryReader(state.GetReadStream()));
            _buffer.InvalidateEnd(index);
            return(true);
        }
Esempio n. 7
0
        public bool Rewind()
        {
            if (!Active || Count == 0)
            {
                return(false);
            }
            var index = Count - 1;
            var state = _buffer.GetState(index);

            _stateSource.LoadStateBinary(new BinaryReader(state.GetReadStream()));
            _buffer.InvalidateEnd(index);
            return(true);
        }
Esempio n. 8
0
        public bool Rewind(int frameToAvoid)
        {
            Sync();
            if (!_active || _count == 0)
            {
                return(false);
            }

            if (_masterFrame == frameToAvoid && _count > 1)
            {
                var index = _buffer.Count - 1;
                RefillMaster(_buffer.GetState(index));
                _buffer.InvalidateEnd(index);
                _stateSource.LoadStateBinary(new BinaryReader(new MemoryStream(_master, 0, _masterLength, false)));
                _count--;
            }
            else
            {
                _stateSource.LoadStateBinary(new BinaryReader(new MemoryStream(_master, 0, _masterLength, false)));
                Work(() =>
                {
                    var index = _buffer.Count - 1;
                    if (index >= 0)
                    {
                        RefillMaster(_buffer.GetState(index));
                        _buffer.InvalidateEnd(index);
                    }
                    else
                    {
                        _masterFrame = -1;
                    }
                    _count--;
                });
            }
            return(true);
        }
 private ZwinderBuffer UpdateBuffer(ZwinderBuffer buffer, RewindConfig newConfig, bool keepOldStates)
 {
     if (buffer == null)             // just make a new one, plain and simple
     {
         buffer = new ZwinderBuffer(newConfig);
     }
     else if (!buffer.MatchesSettings(newConfig))             // no need to do anything if these settings are already in use
     {
         if (keepOldStates)
         {
             // force capture all the old states, let the buffer handle decay if they don't all fit
             ZwinderBuffer old = buffer;
             buffer = new ZwinderBuffer(newConfig);
             for (int i = 0; i < old.Count; i++)
             {
                 ZwinderBuffer.StateInformation si = old.GetState(i);
                 // don't allow states that should be reserved to decay here, where we don't attempt re-capture
                 if (_reserveCallback(si.Frame))
                 {
                     AddToReserved(si);
                 }
                 else
                 {
                     buffer.Capture(si.Frame, s => si.GetReadStream().CopyTo(s), null, true);
                 }
             }
             old.Dispose();
         }
         else
         {
             buffer.Dispose();
             buffer = new ZwinderBuffer(newConfig);
         }
     }
     return(buffer);
 }