Example #1
0
    public void SendInput(PlayerInputData input, bool addDataToList)
    {
        // If we are currently synchronizing the game state by catching up to the highest frame, do not send off any inputs.
        if (Overseer.Instance.GameReady && !NetworkManager.Instance.IsSynchronizing)
        {
            PlayerInputPacket packetToSend = new PlayerInputPacket();

            packetToSend.FrameSent   = GameStateManager.Instance.FrameCount;
            packetToSend.PlayerIndex = PlayerController.PlayerIndex;
            if (addDataToList)
            {
                input.PacketId = PacketsSent;
                DataSent.Add(input);
                ++PacketsSent;
            }
            packetToSend.InputData = DataSent;

            float rand = Random.Range(0.0f, 1.0f);

            if (rand <= NetworkManager.Instance.SendPercentage)
            {
                NetworkManager.Instance.SendEventData(NetworkManager.PlayerInputUpdate, packetToSend, ReceiverGroup.Others, true);
            }
        }
    }
Example #2
0
    public void Update()
    {
        if (Overseer.Instance.GameReady)
        {
            if (Overseer.Instance.AllowInput)
            {
                PlayerInputData currentFrameInputData = new PlayerInputData();

                currentFrameInputData.RoundNumber  = GameStateManager.Instance.RoundCount;
                currentFrameInputData.FrameNumber  = GameStateManager.Instance.FrameCount;
                currentFrameInputData.PlayerIndex  = PlayerIndex;
                currentFrameInputData.InputPattern = DefaultInputPattern;

                // Properties cannot be passed by reference, so create a local variable
                ushort inputPattern = currentFrameInputData.InputPattern;

                UpdateButtonInput(ref inputPattern);
                UpdateJoystickInput(ref inputPattern);
                currentFrameInputData.InputPattern = inputPattern;

                bool addDataToInputHandlerList = currentFrameInputData.InputPattern != LastSavedInputPattern;
                CommandInterpreter.QueuePlayerInput(currentFrameInputData);
                LastSavedInputPattern = currentFrameInputData.InputPattern;

                if (InputHandler != null)
                {
                    InputHandler.SendInput(currentFrameInputData, addDataToInputHandlerList);
                }
            }
        }
        else if (Overseer.Instance.HasGameStarted && InputHandler != null)
        {
            InputHandler.SendHeartbeat();
        }
    }
Example #3
0
 public bool QueuePlayerInput(PlayerInputData dataToQueue)
 {
     if (dataToQueue.FrameNumber > HighestReceivedFrameNumber)
     {
         HighestReceivedFrameNumber = dataToQueue.FrameNumber;
         if (dataToQueue.InputPattern > 0)
         {
             if (GameStateManager.Instance.FrameCount >= dataToQueue.FrameNumber + FrameDelay)
             {
                 // Execute immediately if queue the frame to execute on the frame it was supposed to be executed.
                 // Ex. Frame 57 was sent with 7 frames of delay, but we receive it on frame 64.
                 if (Overseer.Instance.GameReady && GameStateManager.Instance.FrameCount == dataToQueue.FrameNumber + FrameDelay)
                 {
                     ExecuteInput(dataToQueue);
                     return(true);
                 }
             }
             InputBuffer.Enqueue(dataToQueue);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
    private void HandlePlayerInputAck(uint packetNumber)
    {
        PlayerInputData data = DataSent.Find(x => x.PacketId == packetNumber);

        if (data.IsValid())
        {
            DataSent.Remove(data);
        }
    }
Example #5
0
    private void ExecuteInput(PlayerInputData inputData)
    {
        if (lastInputPattern != inputData.InputPattern)
        {
            //Debug.LogWarning("Executing frame: " + inputData.FrameNumber + ", Executing on frame: " + GameStateManager.Instance.FrameCount + ", Anim State: " + clipName + ", Time = " + state.normalizedTime + ", RigidVelocity: " + characterStats.MovementMechanics.Velocity + ", X pos: " + gameObject.transform.position.x +  ", Y pos: " + gameObject.transform.position.y + ", ButtonTrigger: " + Anim.GetBool("ButtonAction"));
            if ((inputData.InputPattern & 1) == 1)
            {
                OnButtonEventTriggered(LP_ANIM_TRIGGER, LP_PRESSED_ANIM_TRIGGER);
                OnButtonPressedEvent?.Invoke(LP_ANIM_TRIGGER);
            }
            else
            {
                OnButtonReleased(LP_ANIM_TRIGGER, LP_RELEASED_ANIM_TRIGGER);
            }

            if (((inputData.InputPattern >> 1) & 1) == 1)
            {
                OnButtonEventTriggered(MP_ANIM_TRIGGER, MP_PRESSED_ANIM_TRIGGER);
                OnButtonPressedEvent?.Invoke(MP_ANIM_TRIGGER);
            }
            else
            {
                OnButtonReleased(MP_ANIM_TRIGGER, MP_RELEASED_ANIM_TRIGGER);
            }

            if (((inputData.InputPattern >> 2) & 1) == 1)
            {
                OnButtonEventTriggered(HP_ANIM_TRIGGER, HP_PRESSED_ANIM_TRIGGER);
                OnButtonPressedEvent?.Invoke(HP_ANIM_TRIGGER);
            }
            else
            {
                OnButtonReleased(HP_ANIM_TRIGGER, HP_RELEASED_ANIM_TRIGGER);
            }

            if (((inputData.InputPattern >> 3) & 1) == 1)
            {
                OnButtonEventTriggered(SPECIAL_ANIM_TRIGGER, SPECIAL_PRESSED_ANIM_TRIGGER);
                OnButtonPressedEvent?.Invoke(SPECIAL_ANIM_TRIGGER);
            }
            else
            {
                OnButtonReleased(SPECIAL_ANIM_TRIGGER, SPECIAL_RELEASED_ANIM_TRIGGER);
            }

            UpdateJoystickInput(GetJoystickInputFromData(inputData));

            lastInputPattern = inputData.InputPattern;

            CheckForMovementInputCommands();
        }
    }
Example #6
0
 private void Update()
 {
     if (InputBuffer.Count > 0 && Overseer.Instance.GameReady)
     {
         PlayerInputData dataToExecute  = InputBuffer.Peek();
         uint            currentFrame   = GameStateManager.Instance.FrameCount;
         uint            frameToExecute = dataToExecute.FrameNumber + (uint)FrameDelay;
         if (frameToExecute - currentFrame <= 0)
         {
             InputBuffer.Dequeue();
             ExecuteInput(dataToExecute);
         }
     }
 }