示例#1
0
        private void UpdateInput(uint bufferIndex)
        {
            if (!Initialized && !ConnectedToServer)
            {
                return;
            }

            if (m_lastInput != null)
            {
                m_inputBuffer[bufferIndex].Movement.Value  = m_lastInput.Movement.Value;
                m_inputBuffer[bufferIndex].Sprinting.Value = m_lastInput.Sprinting.Value;
            }
            else
            {
                m_inputBuffer[bufferIndex].SetToNeutral();
            }

            m_inputBuffer[bufferIndex].Tick.Value = m_localTick;

            m_lastInput = null;

            List <common.data.InputFrame> frames = new List <common.data.InputFrame>();

            for (uint tick = (uint)Mathf.Max((int)m_remoteTick, (int)m_localTick - (m_simulationBuffer * 2)); tick <= m_localTick; tick++)
            {
                frames.Add(m_inputBuffer[tick % CLIENT_STATE_BUFFER_SIZE]);
            }

            InputMessage inputMessage = new InputMessage();

            inputMessage.PlayerID.Value    = PlayerID.Value;
            inputMessage.StartTick.Value   = m_remoteTick;
            inputMessage.InputFrames.Value = frames;

#if NETWORK_SIMULATE
            if (Random.Range(0f, 1f) > m_packetLossChance)
            {
                m_UDPClient.Send(inputMessage.GetBytes(), PlayerID.Value);
            }
            else
            {
                Debug.Log("SIMULATING PACKET LOSS");
            }
#else
            m_udpClient.Send(inputMessage.ToBytes());
#endif //NETWORK_SIMULATE
        }
示例#2
0
        private void SendInputMessages(byte inputFrame)
        {
            if (localPlayer == null)
            {
                return;
            }

            if (inputProvider.InputReceived)
            {
                InputMessage inputMessage = new InputMessage(localPlayer.UnitId, inputProvider.GetSimulationXTranslation(),
                                                             inputProvider.GetSimulationYTranslation(), localPlayer.MovementState.Value.Rotation, inputFrame);
                udpClient.SendMessage(inputMessage.GetBytes());
            }

            if (inputProvider.AbilityInputReceived)
            {
                AbilityInputMessage AbilityInputMessage = new AbilityInputMessage(localPlayer.UnitId, 0, localPlayer.MovementState.Value.Rotation, inputFrame);
                udpClient.SendMessage(AbilityInputMessage.GetBytes());
            }

            inputProvider.Reset();
        }