Exemplo n.º 1
0
        //should include startFrame, include endframe
        public void HandleInputFramesInBackground(SWBytes initialInputFramesData, int startFrameNumber, int endFrameNumber)
        {
            lock (FRAME_SYNC_LOCK)
            {
                if (_game.gameState == FrameSyncGameState.Stopped)
                {
                    return;
                }
                SWConsole.Info($"HandleInputFramesInBackground startFrameNumber={startFrameNumber} endFrameNumber={endFrameNumber}");
                _startFrameNumber = startFrameNumber;
                _endFrameNumber   = endFrameNumber;
                _initialInputFrameDeltas.Clear();
                _initialInputFramesData = initialInputFramesData;
                for (int i = startFrameNumber; i < endFrameNumber; i++)
                {
                    InputFrameDelta delta  = new InputFrameDelta();
                    byte            length = initialInputFramesData.PopByte();
                    initialInputFramesData.PopByteBuffer(delta.bytes, 0, length);
                    _initialInputFrameDeltas.Add(delta);
                }

                int expected = endFrameNumber - startFrameNumber;
                int got      = _initialInputFrameDeltas.Count;
                //reset read index, we will save the data to disk later
                _initialInputFramesData.SetReadIndex(0);
                if (expected != got)
                {
                    SWConsole.Error($"HandleInputFramesInBackground got={got} expected={expected}");
                }
            }
        }
Exemplo n.º 2
0
        public void SendInputFrameDeltas(SWBytes inputFrameDeltas, int count, byte inputSize)
        {
            for (int i = 0; i < count; i++)
            {
                int playerFrameNumber    = inputFrameDeltas.PopInt();
                int predictedFrameNumber = inputFrameDeltas.PopInt();

                byte length = inputFrameDeltas.PopByte();

                if (playerFrameNumber == _lastReceivedPlayerFrameNumber + 1)
                {
                    int correctPredictedFrameNumber = 0;

                    if (predictedFrameNumber != 0)
                    {
                        correctPredictedFrameNumber = _lastPredictedFrameNumber + 1;
                        _predictedFrameNumber       = predictedFrameNumber;
                        _correctFrameNumber         = correctPredictedFrameNumber;
                        SWConsole.Info($"MOCK: SendInputFrameDeltas playerFrameNumber={playerFrameNumber} correctPredictedFrameNumber={correctPredictedFrameNumber} _predictedFrameNumber={_predictedFrameNumber}");
                    }

                    InputFrameDelta delta = new InputFrameDelta();
                    delta.frameNumber = playerFrameNumber;
                    inputFrameDeltas.PopByteBuffer(delta.bytes, 0, length);
                    _receivedInputFrameDeltas.Enqueue(delta);
                    _lastReceivedPlayerFrameNumber = playerFrameNumber;
                    _lastPredictedFrameNumber      = correctPredictedFrameNumber;
                }
                else
                {
                    SWConsole.Info($"MOCK: SendInputFrameDeltas SKIP playerFrameNumber={playerFrameNumber}");
                    inputFrameDeltas.SkipRead(length);
                }
            }
        }
Exemplo n.º 3
0
        internal void ImportData(SWBytes buffer)
        {
            _byteBuffer.Reset();

            if (largeDataContainer)
            {
                UInt16 size = _byteBuffer.PopUInt16();
                buffer.PopByteBuffer(_byteBuffer, 0, size);
            }
            else
            {
                byte size = buffer.PopByte();
                buffer.PopByteBuffer(_byteBuffer, 0, size);
            }

            foreach (IFrameSyncData frameSyncData in _frameSyncDatas)
            {
                frameSyncData.Import(_byteBuffer);
            }
        }
Exemplo n.º 4
0
        public void Import(SWBytes buffer)
        {
            UInt16 dataLength = buffer.PopUInt16();

            buffer.PopByteBuffer(bytes, 0, (int)dataLength);
        }
Exemplo n.º 5
0
        public void Import(SWBytes buffer)
        {
            byte dataLength = buffer.PopByte();

            buffer.PopByteBuffer(bytes, 0, (int)dataLength);
        }