예제 #1
0
        private IEnumerator DelayedPlayCoroutine()
        {
            yield return(new WaitForSeconds(1.0f));

            // sorted list with 0 having highest ping
            pingTupples = new List <SPingTupple>();

            // Sort
            while (pingMap.Count != 0)
            {
                SPingTupple maxPing = new SPingTupple();
                foreach (var tuppleJ in pingMap)
                {
                    if (tuppleJ.Value > maxPing.HalfPing)
                    {
                        maxPing.HalfPing  = tuppleJ.Value / 2.0f;
                        maxPing.NetworkID = tuppleJ.Key;
                    }
                }

                pingTupples.Add(maxPing);
                pingMap.Remove(maxPing.NetworkID);
            }

            isPlayAlgoRunning = true;
        }
예제 #2
0
        protected override void Update()
        {
            base.Update();

            if (isPlayAlgoRunning == true)
            {
                // Delayed play event
                if (pingTupples.Count > 1 &&
                    Time.time - lastTime >= timeDifference)
                {
                    SPingTupple maxPing  = pingTupples[0];
                    SPingTupple nextPing = pingTupples[1];

                    timeDifference = (maxPing.HalfPing - nextPing.HalfPing) / 1000.0f;
                    lastTime       = Time.time;

                    LogConsole("Play on " + maxPing.NetworkID + " with delay : " + timeDifference);

                    BEventsCollection.BI_PlayVideo.Invoke(new BEHandle(), BEventReplicationType.TO_TARGET, true, maxPing.NetworkID);

                    pingTupples.RemoveAt(0);
                }
                else if (pingTupples.Count > 0 &&
                         Time.time - lastTime >= timeDifference)
                {
                    SPingTupple lastPing = pingTupples[0];
                    BEventsCollection.BI_PlayVideo.Invoke(new BEHandle(), BEventReplicationType.TO_TARGET, true, lastPing.NetworkID);


                    timeDifference = lastPing.HalfPing / 1000.0f;
                    lastTime       = Time.time;

                    LogConsole("Play on " + lastPing.NetworkID + " with delay : " + timeDifference);

                    pingTupples.RemoveAt(0);
                }
                else if (Time.time - lastTime >= timeDifference)
                {
                    PlayVideo();
                    if (automaticSync == true)
                    {
                        StartNewCoroutine(ref syncVideoEnumerator, SyncVideoCoroutine());
                    }
                    isPlayAlgoRunning = false;
                }
            }


            if (videoPlayer)
            {
                LogCanvas("VideoPlayer", "Frame : " + videoPlayer.frame);

                if (videoPlayer.isPlaying)
                {
                    float elapsedFrames = videoPlayer.frame - lastFrame;
                    float elapsedTime   = Time.time - lastFrameTime;

                    //LogConsole("Frames : " + elapsedFrames + " - " + elapsedTime);

                    currentFrameTime = elapsedTime /* / elapsedFrames*/;
                    //LogConsole("Frame Time : " + currentFrameTime);
                    CalculateAvgFrameTime(currentFrameTime);

                    lastFrame     = videoPlayer.frame;
                    lastFrameTime = Time.time;
                }

                LogCanvas("FrameTime", "Frame Time : " + currentFrameTime);
            }
        }