Beispiel #1
0
        public override GGPOErrorCode AdvanceFrame()
        {
            sync.IncrementFrame();
            currentInput.Erase();

            Log($"End of frame({sync.FrameCount})...");

            if (isRollingBack)
            {
                return(GGPOErrorCode.OK);
            }

            int frame = sync.FrameCount;
            // Hold onto the current frame in our queue of saved states.  We'll need
            // the checksum later to verify that our replay of the same frame got the
            // same results.
            var info = new SavedInfo
            {
                frame    = frame,
                input    = lastInput,
                buffer   = sync.GetLastSavedFrame().buffer,
                checksum = sync.GetLastSavedFrame().checksum,
            };

            savedFrames.Push(info);

            if (frame - lastVerified == checkDistance)
            {
                // We've gone far enough ahead and should now start replaying frames.
                // Load the last verified frame and set the rollback flag to true.
                sync.LoadFrame(lastVerified);

                isRollingBack = true;
                while (!savedFrames.IsEmpty)
                {
                    callbacks.AdvanceFrame();

                    // Verify that the checksumn of this frame is the same as the one in our
                    // list.
                    info = savedFrames.Front();
                    savedFrames.Pop();

                    if (info.frame != sync.FrameCount)
                    {
                        RaiseSyncError($"Frame number {info.frame} does not match saved frame number {frame}");
                    }
                    int checksum = sync.GetLastSavedFrame().checksum;
                    if (info.checksum != checksum)
                    {
                        LogSaveStates(info);
                        RaiseSyncError($"Checksum for frame {frame} does not match saved ({checksum} != {info.checksum})");
                    }
                    Log($"Checksum {checksum:D8} for frame {info.frame} matches.");
                }
                lastVerified  = frame;
                isRollingBack = false;
            }

            return(GGPOErrorCode.OK);
        }
        private RingBuffer <int> BuildBuffer()
        {
            var buffer = new RingBuffer <int>(BufferSize);

            for (var i = BufferSize / 2; i < BufferSize; i++)
            {
                buffer.Push(i);
            }

            for (var i = 0; i < BufferSize / 2; i++)
            {
                buffer.Push(i);
            }

            return(buffer);
        }
Beispiel #3
0
    private void ShowFpsHistogram(int framesRenderedInPastSecond, float currentFrameTime)
    {
        _pastFps.Push(currentFrameTime);
        _pastFps.ToArray(_fpsArray);

        fpsHistogramMaterial.SetFloatArray("_FpsArray", _fpsArray);
        fpsHistogramMaterial.SetFloat("_CurrentFPS", (float)framesRenderedInPastSecond);
    }
 public sealed override void SendMessage(IMessage pM)
 {
     if ((_messages.TryPeek(out IMessage m) && m.Type != pM.Type) || _messages.IsEmpty)
     {
         _messages.Push(pM);
         base.SendMessage(pM);
     }
 }
Beispiel #5
0
            public void PushSample(float sample)
            {
                sample = Math.Abs(sample);

                while (indices.Count > 0 && GetSample(indices.Head) <= sample)
                {
                    indices.Pop();
                }
                while (indices.Count > 0 && indices.Tail <= sampleCount - windowSize)
                {
                    indices.PopBack();
                }
                indices.Push(sampleCount++);
                buffer.Push(sample);
            }
Beispiel #6
0
            public void PushSample(float sample)
            {
                maxWindow.PushSample(sample);
                if (buffer.IsFull && buffer.PopBack())
                {
                    nonSilentSamples--;
                }

                bool nextNonSilent = maxWindow.GetLevel() >= levelThreshold;

                buffer.Push(nextNonSilent);
                if (nextNonSilent)
                {
                    nonSilentSamples++;
                }
            }
Beispiel #7
0
        public void SendInput(ref GameInput input)
        {
            if (currentState == State.Running)
            {
                // Check to see if this is a good time to adjust for the rift...
                timeSync.AdvanceFrame(ref input, localFrameAdvantage, remoteFrameAdvantage);

                // Save this input packet
                //
                // XXX: This queue may fill up for spectators who do not ack input packets in a timely
                // manner.When this happens, we can either resize the queue(ug) or disconnect them
                // (better, but still ug).  For the meantime, make this queue really big to decrease
                // the odds of this happening...
                pendingOutput.Push(input);
            }

            SendPendingOutput();
        }
Beispiel #8
0
        protected void SendMessage(NetworkMessage msg)
        {
            LogMsg("send", msg);

            packetsSent++;
            lastSendTime = Utility.GetCurrentTime();
            bytesSent   += Utility.GetMessageSize(msg);

            msg.Magic          = magicNumber;
            msg.SequenceNumber = nextSendSequence++;

            lock (queueLock)
            {
                sendQueue.Push(new QueueEntry
                {
                    queueTime   = Utility.GetCurrentTime(),
                    destAddress = udpEndpoint,
                    message     = msg,
                });
            }

            PumpSendQueue();
        }
        public void NormalFencePerfTest()
        {
            long numberOfItems = 10000000;

            ManualResetEvent evt = new ManualResetEvent(false);

            RingBuffer<long> buffer = new RingBuffer<long>(1000);

            Thread producer = new Thread(() =>
            {
                evt.WaitOne();

                long count = 0;

                while (count < numberOfItems)
                {
                    bool wasPushed = buffer.Push(1);

                    if (wasPushed)
                    {
                        count++;
                    }
                }
            });

            Thread consumer = new Thread(() =>
            {
                evt.WaitOne();

                long count = 0;

                while (count < numberOfItems)
                {
                    long popped = 0;
                    bool wasPopped = buffer.Pop(ref popped);

                    if (wasPopped)
                    {
                        count += popped;
                    }
                }

            });

            producer.Start();
            consumer.Start();

            Thread.Sleep(1000);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            evt.Set();

            producer.Join();
            consumer.Join();

            stopwatch.Stop();

            Console.WriteLine(string.Format("Total time taken: {0}ms", stopwatch.ElapsedMilliseconds));
        }
        public void NormalFencePerfTest()
        {
            long numberOfItems = 10000000;

            ManualResetEvent evt = new ManualResetEvent(false);

            RingBuffer <long> buffer = new RingBuffer <long>(1000);

            Thread producer = new Thread(() =>
            {
                evt.WaitOne();

                long count = 0;

                while (count < numberOfItems)
                {
                    bool wasPushed = buffer.Push(1);

                    if (wasPushed)
                    {
                        count++;
                    }
                }
            });

            Thread consumer = new Thread(() =>
            {
                evt.WaitOne();

                long count = 0;

                while (count < numberOfItems)
                {
                    long popped    = 0;
                    bool wasPopped = buffer.Pop(ref popped);

                    if (wasPopped)
                    {
                        count += popped;
                    }
                }
            });

            producer.Start();
            consumer.Start();

            Thread.Sleep(1000);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            evt.Set();

            producer.Join();
            consumer.Join();

            stopwatch.Stop();

            Console.WriteLine(string.Format("Total time taken: {0}ms", stopwatch.ElapsedMilliseconds));
        }
 public void Write(byte value)
 {
     windowBuffer.Push(value);
     ++OutputSize;
 }
        private void handleValue(Int16 amplitude)
        {
            amplitude = FirstPassFilter(amplitude);

            previousValues.Push(amplitude);

            // correct clipping at 255 or -256 using a parabola to synthesize the lost peak/vally
            if (previousValues[BUFFER - 16] == 255 || previousValues[BUFFER - 16] == -256)
            {
                int weightedPrevious = previousValues[BUFFER - 16 - 1];
                int divisor          = 0;
                int iterations       = 0;
                for (; iterations < 6; iterations++)
                {
                    divisor          += (iterations * 2);
                    weightedPrevious += previousValues[BUFFER - 16 - 1] + (previousValues[BUFFER - 16] - previousValues[BUFFER - 16 - 1]);

                    // break if we go out of range early
                    if (previousValues[BUFFER - 16] == 255 && previousValues[BUFFER - 16 + 1 + iterations] >= 255)
                    {
                        break;
                    }
                    if (previousValues[BUFFER - 16] == -256 && previousValues[BUFFER - 16 + 1 + iterations] <= -256)
                    {
                        break;
                    }
                }
                if (iterations > 2)
                {
                    float a = (float)(previousValues[BUFFER - 16 + 1 + iterations] - weightedPrevious) / (float)divisor;
                    float b = (float)(previousValues[BUFFER - 16] - previousValues[BUFFER - 16 - 1]) - a;
                    float c = (float)previousValues[BUFFER - 16 - 1];
                    for (int v13 = iterations, v9Index = 16 - 1, x = 2; v13 > 3; v13--, v9Index++, x++)
                    {
                        previousValues[v9Index] = (Int16)(float)Math.Round((a * x * x) + (b * x) + c);
                    }
                }
            }

            // get the max absolute amplitude of the last BUFFER frames
            previousAbsValues.Push((Int16)Math.Abs((previousValues[BUFFER - 16] == Int16.MinValue) ? Int16.MaxValue : previousValues[BUFFER - 16]));
            int maxAbsInWindow = 0;

            for (int i = 0; i < previousAbsValues.Size; i++)
            {
                Int16 newValue = previousAbsValues[i];
                if (newValue > maxAbsInWindow)
                {
                    maxAbsInWindow = newValue;
                }
            }


            // get the min and max for the 9 frames at the read index
            Int16 findMin = 0;
            Int16 findMax = 0;

            for (int i = 0; i < 9; i++)
            {
                Int16 newValue = previousValues[BUFFER - 16 + 2 + i];
                if (newValue > findMax)
                {
                    findMax = newValue;
                }
                if (newValue < findMin)
                {
                    findMin = newValue;
                }
            }

            int rangeTop    = Math.Max((int)findMax, 100);
            int rangeBottom = Math.Min((int)findMin, -100);
            int rangeMiddle = (rangeBottom + rangeTop) / 2;

            Int16 rangedValue = (Int16)Math.Min(Math.Max(previousValues[BUFFER - 16] - rangeMiddle, Int16.MinValue), Int16.MaxValue);

            if (maxAbsInWindow < 101)
            {
                if (countsBufferIndex > 0)
                {
                    // process counts data with various possible threshholds
                    rx_buffer_len   = 0;
                    currentBitIndex = 0;
                    currentByte     = 0;
                    self_checksumOK = false;
                    if (!processCountsWithThreshold(63))
                    {
                        for (int i = 1; i < 10; i++) // shouldn't this start at 1 as the above already tried?
                        {
                            rx_buffer_len   = 0;
                            currentBitIndex = 0;
                            currentByte     = 0;
                            if (processCountsWithThreshold(63 + i))
                            {
                                if (self_checksumOK)
                                {
                                    break;
                                }
                            }
                            rx_buffer_len   = 0;
                            currentBitIndex = 0;
                            currentByte     = 0;
                            if (processCountsWithThreshold(63 - i))
                            {
                                if (self_checksumOK)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (self_checksumOK)
                    {
                        ++self_checksumSuccessCount;
                    }
                    else if ((uint)countsBufferIndex > 20)
                    {
                        ++self_checksumErrorCount;
                    }
                    countsBufferIndex = 0;
                }
            }
            if (rangedValue > 1)
            {
                _MergedGlobals_currentValue = 1;
            }
            else if (rangedValue < -1)
            {
                _MergedGlobals_currentValue = 0;
            }
            {
                _MergedGlobals_countsSinceLastTransition += 10;
                if (_MergedGlobals_currentValue != _MergedGlobals_lastValue)
                {
                    int stepsAgoCrossedZero = 10 * Math.Abs((int)rangedValue) / Math.Abs((int)rangedValue - (int)_MergedGlobals_previousValue);
                    _MergedGlobals_countsSinceLastTransition -= stepsAgoCrossedZero;
                    if (rangedValue > 1 || countsBufferIndex != 0)
                    {
                        if (countsBufferIndex == 0)
                        {
                            _MergedGlobals_countsSinceLastTransition = stepsAgoCrossedZero;
                        }
                        countsBuffer[countsBufferIndex] = _MergedGlobals_countsSinceLastTransition;

                        // attempt to fix noise by merging overly-short inversion, another method might be detecting slope instead of time
                        if (countsBufferIndex > 4 && _MergedGlobals_countsSinceLastTransition < 35)
                        {
                            int total = countsBuffer[countsBufferIndex - 0] + countsBuffer[countsBufferIndex - 1] + countsBuffer[countsBufferIndex - 2];
                            if (total < 100)
                            {
                                countsBufferIndex -= 2;
                                countsBuffer[countsBufferIndex] = total;
                            }
                        }

                        if (countsBufferIndex < 4000)
                        {
                            countsBufferIndex++;
                        }
                    }
                    _MergedGlobals_countsSinceLastTransition = stepsAgoCrossedZero;
                }
                _MergedGlobals_lastValue     = _MergedGlobals_currentValue;
                _MergedGlobals_previousValue = rangedValue;
            }
        }
Beispiel #13
0
 protected void QueueEvent(UdpProtocolEvent evt)
 {
     LogEvent("Queuing event", evt);
     eventQueue.Push(evt);
 }
Beispiel #14
0
 private void PushUndolog()
 {
     undolog.Push(textBox.Text);
     autoUndologStage = 0;
 }