Example #1
0
    void ServerMove(SavedMove savedMove)
    {
        if (botColor == BotColor.Red && photonView.IsMine)
        {
            Vector3 serverStartPos = transform.position;
            float   startRotation  = transform.rotation.eulerAngles.y;
            if (serverStartPos != savedMove.getStartPostion())
            {
                if (serverStartPos == Vector3.zero)
                {
                    serverStartPos     = savedMove.getStartPostion();
                    transform.position = savedMove.getStartPostion();
                }
            }

            PerformeMovment(savedMove, Time.deltaTime);


            float distance = Mathf.Abs(Vector3.Distance(transform.position, savedMove.getPostion()));
            SaveCurrentStateToFile();
            ServerLastMove = new SavedMove(savedMove.timestamp, savedMove.forwardmove, savedMove.sidemove, transform.rotation.eulerAngles.y, startRotation, transform.position, serverStartPos, CurrentSpeed, savedMove.shooting, savedMove.stand);

            if (distance > maxPosDiff)
            {
                if ((CorrectionTime + CorrectionBound) < PhotonNetwork.Time)
                {
                    ClientAdjustment adjustment = new ClientAdjustment(false, serverStartPos, transform.position, transform.rotation.y, savedMove.timestamp);

                    photonView.RPC("ClientAdjustPosition", RpcTarget.All, adjustment);
                    byte evCode = 2;
                    RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
                        Receivers = ReceiverGroup.Others
                    };
                    SendOptions sendOptions = new SendOptions {
                        Reliability = true
                    };
                    PhotonNetwork.RaiseEvent(evCode, adjustment, raiseEventOptions, sendOptions);
                    CorrectionTime = PhotonNetwork.Time;
                }
            }
            else
            {
                Debug.Log(" MOVE CORRECT ");
                RecreateShoot(savedMove);
                ClientAdjustment adjustment = new ClientAdjustment();
                adjustment.AckGoodMove = true;
                adjustment.TimeStamp   = savedMove.timestamp;
                byte evCode = 2;
                RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
                    Receivers = ReceiverGroup.Others
                };
                SendOptions sendOptions = new SendOptions {
                    Reliability = true
                };
                PhotonNetwork.RaiseEvent(evCode, adjustment, raiseEventOptions, sendOptions);
            }
        }
    }
Example #2
0
    public void OnEvent(EventData photonEvent)
    {
        if (photonEvent.Code == 1)
        {
            if (botColor == BotColor.Red && photonView.IsMine)
            {
                SavedMove recivedMove = (SavedMove)photonEvent.CustomData;
                ServerMove(recivedMove);
            }
        }

        if (photonEvent.Code == 2)
        {
            if (botColor == BotColor.Green && photonView.IsMine)
            {
                ClientAdjustment clientAdjustment = (ClientAdjustment)photonEvent.CustomData;
                ClientAdjustPosition(clientAdjustment);
            }
        }
    }
Example #3
0
    void ClientAdjustPosition(ClientAdjustment adjustment)
    {
        if (botColor == BotColor.Green && photonView.IsMine)
        {
            if (adjustment.AckGoodMove)
            {
                if (PendingMoveList != null)
                {
                    PendingMoveList.RemoveAll(a => a.timestamp <= adjustment.TimeStamp);
                }
            }
            else
            {
                bUpdatePosition = true;

                latestAdjustment = adjustment;
                Debug.Log(" WRONMG move " + adjustment.getStartLoc() + " resulted in postion " + adjustment.getNewLoc() + " actual postion   " + transform.position + "  on " + adjustment.TimeStamp);
            }
        }
    }
Example #4
0
    // Start is called before the first frame update
    void Start()
    {
        PhotonPeer.RegisterType(typeof(SavedMove), 2, SavedMove.Serialize, SavedMove.Deserialize);
        PhotonPeer.RegisterType(typeof(ClientAdjustment), 3, ClientAdjustment.Serialize, ClientAdjustment.Deserialize);

        controller = GetComponent <CharacterController>();
        animat     = GetComponent <Animator>();
        photonView = GetComponent <PhotonView>();
        Destroy(playerCamera);
        Destroy(playerAudio);

        LaserObject = Instantiate(LaserEffect, rayOrgin);
        LaserObject.SetActive(false);

        controller.detectCollisions = false;

        StartTime = PhotonNetwork.Time;
        CurrentStartPhotonTime = 0; // PhotonNetwork.Time-0.5f;
        MyLocalTime            = Time.time;
        //savedMoves = new Queue<SavedMove>();
        PendingMoveList     = new List <SavedMove>();
        InterpolationBuffer = new Queue <SavedMove>();
        ServerLastMove      = new SavedMove();
        ReplicatedMovement  = new SavedMove();
        latestAdjustment    = new ClientAdjustment();

        logfile = new StringBuilder();
        var newLine = string.Format("{0}:{1}:{2}:{3}:{4}", "Index", "PostionX", "PostionZ", "RotationAngle", "PhotonTime");

        logfile.AppendLine(newLine);

        PhotonNetwork.SendRate          = 80;
        PhotonNetwork.SerializationRate = 80;

        if (botColor == BotColor.Target)
        {
            RecreatePostionListner        += recreatePostion;
            ReturnToOrginalPostionListner += returnToOrginalPosition;
        }
    }