public void ResumeSync(bool forceresumePlay)
        {
            HookEvents();
            Timer.Start();

            if (forceresumePlay)
            {
                UnpauseAll();
            }
            else
            {
                HeuristicManager.StartMonitoring();
            }
        }
Exemple #2
0
    private Node MakeTree()
    {
        GameGrid realGrid    = GameBoard.gameGrid;
        GameGrid virtualGrid = new GameGrid();

        virtualGrid.Grid = GameGrid.CloneGrid(realGrid.Grid);

        Vector3Int opponentPos = opponent.CurrentTilePos;
        PlayerNum  nextMovesBelongsTo;

        Queue <Node> list = new Queue <Node>();

        Node root = new Node(virtualGrid, new List <Node>(), HeuristicManager.Heuristic(availableMoves.Count, opponent.availableMoves.Count), 0, availableMoves, CurrentTilePos, opponentPos, PlayerNum.Player2);

        list.Enqueue(root);

        while (list.Count > 0)
        {
            Node node = list.Dequeue();
            if (node.depth % 2 == 0)
            {
                nextMovesBelongsTo = PlayerNum.Player1;
            }
            else
            {
                nextMovesBelongsTo = PlayerNum.Player2;
            }

            if (node.depth <= GameManager.Instance.treeDepth && node.moves.Count > 0)
            {
                foreach (Vector3Int item in node.moves)
                {
                    GameGrid newGameGrid = new GameGrid();
                    newGameGrid.Grid = GameGrid.CloneGrid(node.gameGrid.Grid);

                    Vector3Int activePlayerPos = item;
                    newGameGrid.Grid[item.x, item.y].isExplored = true;

                    List <Vector3Int> nextMoves = GetAvailableMoves(newGameGrid, node.opponentPos);
                    List <Vector3Int> thisMoves = GetAvailableMoves(newGameGrid, activePlayerPos);
                    Node child = new Node(newGameGrid, new List <Node>(), HeuristicManager.Heuristic(thisMoves.Count, nextMoves.Count), node.depth + 1, nextMoves, node.opponentPos, activePlayerPos, nextMovesBelongsTo);
                    node.children.Add(child);
                    list.Enqueue(child);
                }
            }
        }
        return(root);
    }
        private void masterMedia_MediaOpened(object sender, RoutedEventArgs e)
        {
            HeuristicManager.StartMonitoring();

            // the live video intermittently starts at the beginning of the live video
            // instead of the end, it has been difficult to reproduce and resolve, calling
            // StartSeekToLive is a workaround to solve the problem, it can be removed if
            // find the root problem of the issue
            //
            // only want to run the workaround for live streams and when the initial
            // video is loaded, not when the stream is restored by the auto retry
            //if (MainMedia.IsLive && MainMedia.RetryState == RetryState.None)
            if (MainMedia.IsLive)
            {
                MainMedia.StartSeekToLive();
            }

            MainMedia.Play();
        }
        private void PauseAll()
        {
            HeuristicManager.StopMonitoring();

            foreach (SlaveMediaElement slave in SubMediaElements)
            {
                if (slave.MediaElement != MainMedia)
                {
                    if (slave.MediaElement.CurrentState != SmoothStreamingMediaElementState.Paused &&
                        slave.MediaElement.CurrentState != SmoothStreamingMediaElementState.Closed)
                    {
                        try
                        {
                            slave.MediaElement.Pause();
                        }
                        catch (InvalidOperationException) { }
                    }
                }
            }
        }
        public void RegisterMaster(SmoothStreamingMediaElement media, TimeSpan position)
        {
            UnhookEvents();

            //MainMedia is for syncing
            //HeuristicsMasterMedia is used for Heuristics
            MainMedia = media;
            //MainMedia.Position = position;

            HookEvents();

            //UpdateSlaves();

            if (media == HeuristicMasterMedia)
            {
                HeuristicManager.StartMonitoring();
            }
            else
            {
                HeuristicManager.StopMonitoring();
            }
        }
        //Assuming Master is ready
        //Assuming Slaves are in a heuristic loadable state
        public void ResetHeuristics()
        {
            if (ResettingHeuristics != null)
            {
                ResettingHeuristics(this, null);
            }

            HeuristicManager.StopMonitoring();
            HeuristicManager.Clear();

            if (HeuristicMasterMedia != null)
            {
                HeuristicManager.AddSmoothStreamingMediaElement(HeuristicMasterMedia, HeuristicSettings.PrimaryMinBitRate,
                                                                HeuristicSettings.PrimaryMinFrameRate);
                // TODO:  determin min values depending on size of master

                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    if (slave.MediaElement != HeuristicMasterMedia)
                    {
                        // reset current heuristic enabled flag
                        slave.IsPhysicalSyncEnabled = false;

                        //if (slave.IsLogicalSyncEnabled) // does it logically needed to be playing, if so, add it to HM
                        //{
                        if (slave.MediaElement != null)
                        {
                            HeuristicManager.AddSmoothStreamingMediaElement(slave.MediaElement,
                                                                            HeuristicSettings.SecondaryMinBitRate,
                                                                            HeuristicSettings.SecondaryMinFrameRate);
                        }
                    }
                }

                HeuristicManager.StartMonitoring();
            }
        }
        //private void RetrySlaves()
        //{
        //    foreach (SlaveMediaElement slave in SubMediaElements)
        //    {
        //        if (slave.MediaElement.CurrentState == SmoothStreamingMediaElementState.Closed)
        //        {
        //            slave.MediaElement.Retry();
        //        }
        //    }
        //}

        private void UnpauseAll()
        {
            HeuristicManager.StartMonitoring();

            MainMedia.Play();
        }