Beispiel #1
0
        private unsafe void RefillMaster(ZwinderBuffer.StateInformation state)
        {
            var lengthHolder     = 0;
            var lengthHolderSpan = new Span <byte>(&lengthHolder, 4);
            var zeldas           = SpanStream.GetOrBuild(state.GetReadStream());

            zeldas.Read(lengthHolderSpan);
            _masterLength = lengthHolder;
            fixed(byte *buffer_ = _master)
            {
                int *buffer = (int *)buffer_;

                while (zeldas.Read(lengthHolderSpan) == 4)
                {
                    if ((lengthHolder & IS_GAP) != 0)
                    {
                        buffer += lengthHolder & ~IS_GAP;
                    }
                    else
                    {
                        zeldas.Read(new Span <byte>(buffer, lengthHolder * 4));
                        buffer += lengthHolder;
                    }
                }
            }

            _masterFrame = state.Frame;
        }
        private void AddToReserved(ZwinderBuffer.StateInformation state)
        {
            if (_reserved.ContainsKey(state.Frame))
            {
                return;
            }

            var bb = new byte[state.Size];
            var ms = new MemoryStream(bb);

            state.GetReadStream().CopyTo(ms);
            _reserved.Add(state.Frame, bb);
            AddStateCache(state.Frame);
        }
 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);
 }
 public StateInfo(ZwinderBuffer.StateInformation si)
 {
     Frame = si.Frame;
     Read  = si.GetReadStream;
 }