public void OnTextData(PopMessageText Message)
    {
        //	need to keep this in sync with packet numbers
        var NewMeta = JsonUtility.FromJson <PacketMeta>(Message.Data);

        LastPacketMeta = NewMeta;
    }
    void UpdateMaterial(Material Material, PacketMeta Meta, Texture Texture)
    {
        Material.mainTexture = Texture;

        var Aspect = Meta.HorizontalFov / Meta.VerticalFov;

        //	setup camera for visualisation
        if (ProjectionCamera)
        {
            //	gr: fov is vertical
            //		aspect is width / height
            //	https://docs.unity3d.com/ScriptReference/Matrix4x4.Perspective.html
            ProjectionCamera.fieldOfView   = Meta.VerticalFov;
            ProjectionCamera.aspect        = Aspect;
            ProjectionCamera.nearClipPlane = WorldNear;
            ProjectionCamera.farClipPlane  = WorldFar;
        }

        //var ProjectionMatrix = ProjectionCamera ? c: Matrix4x4.identity;
        var ProjectionMatrix = Matrix4x4.Perspective(Meta.VerticalFov, Aspect, WorldNear, WorldFar);

        if (UseCameraProjection)
        {
            ProjectionMatrix = ProjectionCamera.projectionMatrix;
        }
        Material.SetMatrix("DepthProjectionMatrix", ProjectionMatrix);
        Material.SetFloat("TextureDepthMin", Meta.DepthMin);
        Material.SetFloat("TextureDepthMax", Meta.DepthMax);
        Material.SetFloat("CameraDepthMin", Meta.MinReliableDistance);
        Material.SetFloat("CameraDepthMax", Meta.MaxReliableDistance);
        Material.SetFloat("WorldDepthMin", WorldNear);
        Material.SetFloat("WorldDepthMax", WorldFar);
    }
示例#3
0
        /// <summary>
        ///     Try to send a dframe or a keep alive if no user data is waiting to be sent.
        /// </summary>
        /// <returns>Return true if a dframe was sent</returns>
        public bool SendDFrame()
        {
            if (UserData.Count <= 0)
            {
                return(false);
            }

            // If the window is full, don't send any thing
            if (IsAckWindowFull())
            {
                return(false);
            }

            // If we have sent a user data message that had to be carried in multiple
            // dframes then stop sending. We can't have more than one of these on the
            // wire at one time (if I've intepreted the specs correctly).
            if (MultipleDframePacket)
            {
                return(false);
            }

            // The retry time should start at 100 + rtt * 2.5 according to the specs but we use
            // 2 as this is a round number.
            uint retryTime = 100 + (_rtTime * 2);

            while (UserData.Count > 0)
            {
                byte[] ud = UserData.First();
                UserData.RemoveFirst();

                // Break the user data block into sizes smaller than the ethernet mtu. We
                // assume an MTU of 1450 as some infrastructure steals some bytes.
                int  offset      = 0;
                bool firstPacket = true;
                bool lastPacket  = false;
                while (offset < ud.Length)
                {
                    int length;
                    if ((ud.Length - offset) > 1450)
                    {
                        length = 1450;
                        MultipleDframePacket = true;
                    }
                    else
                    {
                        length     = ud.Length - offset;
                        lastPacket = true;
                    }

                    byte[] pkt = { 0x07, 0x00, NextTxSeq, NextRxSeq };

                    // If this is the first packet, set the flag to indicate this.
                    if (firstPacket)
                    {
                        pkt[0] |= 0x10;
                    }

                    // If this is the last packet, set the flag to indicate this
                    if (lastPacket)
                    {
                        pkt[0] |= 0x20;
                    }

                    // If the session isn't fully connected then this must be a session establishment
                    // message

                    var sessionState = Context.ActorSelection("../dplay-session").
                                       Ask <FLServer.Player.Session.State>("GetSessState");
                    if (sessionState.Result == FLServer.Player.Session.State.CONNECTING_SESSINFO)
                    {
                        pkt[0] |= 0x40;
                    }

                    FLMsgType.AddArray(ref pkt, ud, offset, length);

                    var spkt = new PacketMeta
                    {
                        Data      = pkt,
                        RetryTime = DateTime.UtcNow.AddMilliseconds(retryTime),
                        SendTime  = DateTime.UtcNow
                    };

                    _userDataPendingAck[NextTxSeq] = spkt;
                    //sess.BytesTx += pkt.Length;
                    Context.ActorSelection("../socket").Tell(pkt);
                    //TxStart(pkt, sess.Client);

                    // Increase the retry times if multiple packets are sent so that
                    // we're less likely to send a massive burst of packets to retry.
                    retryTime += 5;

                    NextTxSeq++;

                    firstPacket = false;
                    offset     += length;

                    // fixme: it's possible for a multi-dframe user data message to overrun
                    // the valid seq window size. this is bad and the connection will fail.
                }

                // If we have sent a user data message that had to be carried in multiple
                // dframes then stop sending. We can't have more than one of these on the
                // wire at one time (if I've intepreted the specs correctly).
                if (MultipleDframePacket)
                {
                    break;
                }

                // If the window is full, don't send any more
                if (IsAckWindowFull())
                {
                    break;
                }
            }

            return(true);
        }