示例#1
0
        public uint GenerateHash()
        {
            _byteBuffer.Reset();

            foreach (IFrameSyncData frameSyncData in _frameSyncDatas)
            {
                frameSyncData.Export(_byteBuffer);
            }

            return(_byteBuffer.Crc32());
        }
示例#2
0
 internal void Reset()
 {
     bytes.Reset();
     if (_userRestorable != null)
     {
         _userRestorable.Clear();
         _userRestorable = null;
     }
 }
示例#3
0
    public void SendData(string jsonData, byte playerID)
    {
        //length UInt16

        //senderID byte
        //command byte
        //jsonData 2 + jsonData length
        UInt16 length = (UInt16)(1 + 1 + 2 + jsonData.Length);

        _outBuffer.Reset();
        _outBuffer.Push(length);
        _outBuffer.Push(playerID);
        _outBuffer.Push(FrameSyncConstant.DEBUG_SERVER_PLAYER_FRAME);
        _outBuffer.PushUTF8LongString(jsonData);
        _tcpConnection.Send(_outBuffer);
    }
        void SendLocalInputs()
        {
            if (_localInputFrameDeltaNumberToSend == 0)
            {
                _localInputFrameDeltaNumberToSend = _currentLocalInputFrameDeltaNumber;
            }

            _sendLocalInputDeltaBuffer.Reset();

            int end = _localInputFrameDeltaNumberToSend + FrameSyncConstant.LOCAL_INPUT_FRAME_RESEND_COUNT;

            if (end > _currentLocalInputFrameDeltaNumber)
            {
                end = _currentLocalInputFrameDeltaNumber;
            }

            int count = 0;

            for (int i = _localInputFrameDeltaNumberToSend; i <= end; i++)
            {
                InputFrameDelta inputFrameDelta = localInputFrameDeltas[i];
                _sendLocalInputDeltaBuffer.Push(inputFrameDelta.frameNumber);

                byte length = (byte)inputFrameDelta.bytes.DataLength;
                _sendLocalInputDeltaBuffer.Push(length);
                _sendLocalInputDeltaBuffer.PushAll(inputFrameDelta.bytes);

                count++;
                inputFrameDelta.resend = inputFrameDelta.resend - 1;
                if (inputFrameDelta.resend == 0)
                {
                    _localInputFrameDeltaNumberToSend++;
                }
            }

            if (count > 0)
            {
                _io.SendInputFrameDeltas(_sendLocalInputDeltaBuffer, count, _input.Size);
            }
        }
        public void RequestInputFrames(int startFrameNumber, int endFrameNumber)
        {
            if (startFrameNumber <= endFrameNumber)
            {
                if (startFrameNumber > 0 && endFrameNumber <= _frameNumber)
                {
                    _largeData.Reset();

                    for (int i = startFrameNumber; i < endFrameNumber; i++)
                    {
                        InputFrameDelta delta = _inputFrameDeltas[i];
                        if (delta == null)
                        {
                            delta             = new InputFrameDelta();
                            delta.frameNumber = 0; //playerFrameNumber
                        }

                        delta.Export(_largeData);
                    }

                    _handler.HandleInputFramesInBackground(_largeData, startFrameNumber, endFrameNumber);
                }
            }
        }
示例#6
0
 internal void ResetBytes()
 {
     bytes.Reset();
 }
        void DoTick()
        {
            _frameNumber++;
            _sealedFrameNumber = _frameNumber - 10;
            if (_sealedFrameNumber < 1)
            {
                _sealedFrameNumber = 1;
            }

            if (_receivedInputFrameDeltas.Count > 0)
            {
                SWConsole.Crit($"MockIO: DoTick playerFrameCount={_receivedInputFrameDeltas.Count}");
                InputFrameDelta delta = _receivedInputFrameDeltas.Peek();

                if (true)
                {
                    delta = _receivedInputFrameDeltas.Dequeue();
                    //SWConsole.Crit($"MockIO: DoTick playerFrameCount 1 ={_receivedInputFrameDeltas.Count}");
                    _inputFrameDeltas[_frameNumber] = delta;

                    _data.Reset();

                    byte length = (byte)delta.bytes.DataLength;
                    _data.Push(length);
                    _data.PushAll(delta.bytes);

                    SWConsole.Crit($"MockIO: DoTick send PLAYER={delta.frameNumber} roomStep={_frameNumber}");

                    MockHandleInputFrameOperaion operation = new MockHandleInputFrameOperaion(_handler, _pingMilliseconds);
                    operation.inputFrameData = SWBytes.Clone(_data);
                    operation.playerLastInputFrameOnServer = _receivedInputFrameDeltas.Count;
                    operation.predictionFrameNumber        = _predictedFrameNumber;
                    operation.correctFrameNumber           = _correctFrameNumber;
                    operation.roomStep          = _frameNumber;
                    operation.sealedFrameNumber = _sealedFrameNumber;
                    _operationQueue.AddOperation(operation);
                    return;
                }
                //else if(delta.predictedServerFrameNumber < _frameNumber)
                //{
                //    delta = _receivedInputFrameDeltas.Dequeue();
                //    delta.version = 1;
                //    _inputFrameDeltas[delta.predictedServerFrameNumber] = delta;

                //    _data.Reset();

                //    byte length = (byte)delta.bytes.DataLength;
                //    _data.Push(length);
                //    _data.Push(delta.bytes, 0);

                //    SWConsole.Crit($"MockIO: DoTick send PLAYER={delta.frameNumber} roomStep={_frameNumber} prediction={delta.predictedServerFrameNumber}");
                //    _frameNumber--;
                //    _sealedFrameNumber = _frameNumber - 10;
                //    if (_sealedFrameNumber < 1)
                //    {
                //        _sealedFrameNumber = 1;
                //    }
                //    MockHandleInputFrameOperaion operation = new MockHandleInputFrameOperaion(_handler, _pingMilliseconds);
                //    operation.inputFrameData = SWBytes.Clone(_data);
                //    operation.playerLastInputFrameOnServer = _receivedInputFrameDeltas.Count;
                //    operation.predictionError = _predictionError;
                //    operation.roomStep = delta.predictedServerFrameNumber;
                //    operation.version = delta.version;
                //    operation.sealedFrameNumber = _sealedFrameNumber;
                //    _operationQueue.AddOperation(operation);
                //    return;
                //}
            }

            {
                _lastPredictedFrameNumber = _frameNumber;
                InputFrameDelta delta = new InputFrameDelta();
                delta.frameNumber = 0; //playerFrameNumber
                _inputFrameDeltas[_frameNumber] = delta;

                _data.Reset();
                _data.Push((byte)0); //length
                SWConsole.Crit($"MockIO: DoTick send EMPTY={delta.frameNumber} roomStep={_frameNumber}");

                MockHandleInputFrameOperaion operation = new MockHandleInputFrameOperaion(_handler, _pingMilliseconds);
                operation.inputFrameData = SWBytes.Clone(_data);
                operation.playerLastInputFrameOnServer = _receivedInputFrameDeltas.Count;
                operation.predictionFrameNumber        = _predictedFrameNumber;
                operation.correctFrameNumber           = _correctFrameNumber;
                operation.roomStep          = _frameNumber;
                operation.sealedFrameNumber = _sealedFrameNumber;
                _operationQueue.AddOperation(operation);
            }
        }