void FixedUpdate()
    {
        if (!isServer || (isServer && isClient))
        {
            return;
        }
        NetKeyState keyState;

        while (m_pendingInputs.Count > 0)
        {
            //TODO: cheat detection
            keyState = m_pendingInputs.Dequeue();
            //apply movement
            m_input.Process(keyState.inputData);
            m_messageId = keyState.messageId;
            ProcessActions(m_input.GetInputData());
            m_movement.ProcessInputs(m_input.GetInputData(), Time.fixedDeltaTime);
            PlayerProperties properties = m_movement.GetProperties();

            //add new state to send buffer, respect limit
            while (m_sendBuffer.Count >= c_sendBufferLength)
            {
                m_sendBuffer.RemoveAt(0);
            }
            //pushing the player is not predicted - disable server reconciliation as long as pushing is active
            //if (properties.isPushed) Debug.Log("INHPUSH");
            m_sendBuffer.Add(new ServerState(m_messageId, properties, keyState.inputData, properties.isPushed));

            LagCompensator.Register(gameObject);
        }
    }
 void Awake()
 {
     if (singleton == null)
     {
         singleton = this;
         m_history = new Dictionary <GameObject, List <Vector3> >();
     }
     else
     {
         Debug.LogWarning("LagCompensator: Multiple instance detected. Destroying...");
         Destroy(this);
     }
 }
예제 #3
0
    void FixedUpdate()
    {
        //update server side only in fixed steps for lag compensation
        if (isClient || !isServer)
        {
            return;
        }

        //Lag compensation only works with connection info of player object
        if (m_launcher != null && LagCompensator.IsActive)
        {
            NetworkIdentity identity = m_launcher.GetComponent <NetworkIdentity>();
            if (identity != null)
            {
                LagCompensator.Rewind(gameObject, m_launcher);                //identity.connectionToClient);
            }
        }
        Move(Time.fixedDeltaTime);
        LagCompensator.Register(gameObject);
        LagCompensator.Restore(gameObject);
    }
    private void ProcessActions(InputData inputData)
    {
        //add client check to avoid activation lag compensation in local multiplayer regardless of its setting
        if ((inputData.attack > 0.0f) && m_attackReleased && !isClient)
        {
            m_attackReleased = false;
            Debug.Log("attack");
            LagCompensator.Rewind(gameObject, gameObject);            //, connectionToClient);
            m_movement.ProcessActions(m_input.GetInputData(), Time.fixedDeltaTime);
            LagCompensator.Restore(gameObject);

            m_movement.ProcessEvents();
        }
        else
        {
            m_movement.ProcessActions(m_input.GetInputData(), Time.fixedDeltaTime);
            m_movement.ProcessEvents();
        }

        if (inputData.attack <= 0.0f)
        {
            m_attackReleased = true;
        }
    }
 void OnDestroy()
 {
     LagCompensator.Unregister(gameObject);
 }
예제 #6
0
 void OnDestroy()
 {
     //at this stage isServer is not reliable anymore - just Unregister, LagCompensator will catch it.
     LagCompensator.Unregister(gameObject);
 }