protected override RollbackInputBaseActions GetCurrentActionsValue(int controllerId)
        {
            //Gather local inputs and execute them
            RollbackInputBaseActions actionsValue = new RollbackInputBaseActions((int)ActionsCode.LENGTH);

            SetBitFromKeycode((int)ActionsCode.UP, KeyCode.W, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.RIGHT, KeyCode.D, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.DOWN, KeyCode.S, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.LEFT, KeyCode.A, ref actionsValue);
            actionsValue.SetOrClearBit((int)ActionsCode.SHOOT, Input.GetMouseButton(1));

            actionsValue.SetHorizontalAxis(Input.GetAxisRaw("Horizontal"));
            actionsValue.SetVerticalAxis(Input.GetAxisRaw("Vertical"));

            return(actionsValue);
        }
    protected override RollbackInputBaseActions GetCurrentActionsValue(int controllerId)
    {
        if (controllerId == localPlayerId)
        {
            //Gather local inputs and execute them
            RollbackInputBaseActions actionsValue = new RollbackInputBaseActions((int)ActionsCode.LENGTH);

            SetBitFromKeycode((int)ActionsCode.UP, KeyCode.W, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.RIGHT, KeyCode.D, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.DOWN, KeyCode.S, ref actionsValue);
            SetBitFromKeycode((int)ActionsCode.LEFT, KeyCode.A, ref actionsValue);
            actionsValue.SetOrClearBit((int)ActionsCode.SHOOT, Input.GetMouseButton(1));

            actionsValue.SetHorizontalAxis(Input.GetAxisRaw("Horizontal"));
            actionsValue.SetVerticalAxis(Input.GetAxisRaw("Vertical"));

            return(actionsValue);
        }
        else
        {
            //Predict the next input by copying the last input
            return(_playerInputList[controllerId].value);
        }
    }
 void SetBitFromKeycode(int inputIndex, KeyCode keyCode, ref RollbackInputBaseActions actionsValue)
 {
     actionsValue.SetOrClearBit(inputIndex, Input.GetKey(keyCode));
 }
Beispiel #4
0
 void SetBitFromAction(InputActionManager.InputType inputType, ref RollbackInputBaseActions actionsValue, InputDevice inputDevice)
 {
     actionsValue.SetOrClearBit((int)inputType, InputActionManager.GetInput(inputType, inputDevice));
 }
Beispiel #5
0
        private void DisplayInputSimulation()
        {
            GUILayout.Label("Input simulations options", EditorStyles.boldLabel);

            EditorGUILayout.IntField("ControllerId : ", _controllerId);

            //Vertical axis input
            float verticalValue = _rbBaseInput.GetVerticalAxis();

            verticalValue = EditorGUILayout.Slider("Vertical axis", verticalValue, -1f, 1f);
            _rbBaseInput.SetVerticalAxis(verticalValue);

            //Vertical axis input
            float horizontalValue = _rbBaseInput.GetHorizontalAxis();

            horizontalValue = EditorGUILayout.Slider("Horizontal axis", horizontalValue, -1f, 1f);
            _rbBaseInput.SetHorizontalAxis(horizontalValue);

            //Button inputs
            GUILayout.Label("Buttons press options : ", EditorStyles.boldLabel);
            int oldNumOfInputs = _numOfInputs;

            _numOfInputs = EditorGUILayout.IntField("NumOfInputs : ", _numOfInputs);

            if (_numOfInputs != oldNumOfInputs)
            {
                _rbBaseInput = new RollbackInputBaseActions(1 + _numOfInputs / 8);
            }

            for (int i = 0; i < _numOfInputs; i++)
            {
                EditorGUILayout.BeginHorizontal();
                bool initValue = _rbBaseInput.GetValueBit(i);
                initValue = EditorGUILayout.Toggle(_rollbackManager.GetRBInputManager().GetActionName(i), initValue);
                _rbBaseInput.SetOrClearBit(i, initValue);
                EditorGUILayout.EndHorizontal();
            }

            //Correction of inputs
            if (GUILayout.Button("Correct Inputs"))
            {
                if (_rollbackManager != null)
                {
                    RollbackInputBaseActions[] rbInputs = new RollbackInputBaseActions[_numFramesToSimulate];
                    for (int i = 0; i < _numFramesToSimulate; i++)
                    {
                        rbInputs[i] = _rbBaseInput;
                    }

                    DateTime currentTime = System.DateTime.Now;
                    _rollbackManager.GetRBInputManager().CorrectInputs(_controllerId, _numFramesToSimulate, rbInputs);
                    _rollbackManager.ReSimulate(_numFramesToSimulate);
                    _spentTimeToResimulate = System.DateTime.Now - currentTime;
                }
            }

            if (_spentTimeToResimulate != null)
            {
                GUILayout.Label("Time to resimulate " + _numFramesToSimulate + " frames : " + _spentTimeToResimulate.TotalMilliseconds + "ms.");
            }
        }