Beispiel #1
0
    /// <summary>Reads the "custom content" Hashtable that is sent as position update.</summary>
    /// <returns>Hashtable for event "move" to update others</returns>
    public void ReadEvInput(Hashtable evContent)
    {
        int numFramesReceived = 0;

        if (evContent.ContainsKey((int)0))
        {
            numFramesReceived = (int)evContent[0];
        }

        if (numFramesReceived <= 0)
        {
            return;
        }

        int sentAtFrameNumber = 0;
        int currentFrame      = RollbackManager.Instance.GetIndexFrameNumFromStart();

        if (evContent.ContainsKey((int)1))
        {
            sentAtFrameNumber = (int)evContent[1];
        }

        int numDiffFramesWithPresent = currentFrame - sentAtFrameNumber;
        int applicableFrame          = RollbackManager.Instance.GetMaxFramesNum() - numDiffFramesWithPresent;

        RollbackElementRollbackInputBaseActions playerInputHistory = RollbackManager.rbInputManager.GetPlayerInputHistory(ActorNumber - 1);

        //Correct inputs
        int backtrackNumFrames = -1;

        for (int i = 0; i < numFramesReceived; i++)
        {
            if (LastConfirmedFrame >= sentAtFrameNumber - i)
            {
                break;
            }

            RollbackInputBaseActions baseActions = new RollbackInputBaseActions();
            baseActions.UnpackBits((byte[])evContent[2 + i]);

            //If return true, that means the correction was done
            if (playerInputHistory.CorrectValue(baseActions, applicableFrame - i))
            {
                backtrackNumFrames = i + 1;
            }
        }

        // If at least a frame changed, we make a simulate
        if (backtrackNumFrames > -1)
        {
            //Predict new inputs from difference of receiving
            RollbackInputBaseActions lastInput = new RollbackInputBaseActions();
            lastInput.UnpackBits((byte[])evContent[2]); // The latest frame is always on 2
            for (int i = 0; i < numDiffFramesWithPresent; i++)
            {
                playerInputHistory.CorrectValue(lastInput, applicableFrame + i);
            }

            //Resimulate actions depending
            RollbackManager.Instance.ReSimulate(backtrackNumFrames + numDiffFramesWithPresent + 5);
        }

        this.LastConfirmedFrame = sentAtFrameNumber;
        this.LastUpdateFrame    = GameLogic.Timestamp;
    }