コード例 #1
0
        /// <summary>
        ///     Flushes all the entities in the out queue from the matchmaker.
        /// </summary>
        /// <returns>The groups removed from the queue.</returns>
        private IEnumerable <QueueGroup> FlushOutQueue()
        {
            Queue <QueueGroup> toInform = new Queue <QueueGroup>();

            lock (outQueue)
            {
                while (outQueue.Count > 0)
                {
                    RankingMatchmakerQueueTask <T> task = outQueue.Dequeue();

                    //Get group and check it exists
                    QueueGroup queueGroup = queue.FirstOrDefault((g) => g.task == task);
                    if (queueGroup != null)
                    {
                        //Remove the group
                        queue.Remove(queueGroup);

                        //Remove all matches it had so we don't consider it in matchmaking
                        foreach (QueueGroup other in queue)
                        {
                            other.matches.Remove(new Match {
                                other = queueGroup
                            });
                        }

                        //If removed, inform it that it was cancelled
                        toInform.Enqueue(queueGroup);
                    }
                }
            }

            return(toInform);
        }
コード例 #2
0
        /// <inheritdoc/>
        public IMatchmakerQueueTask <T> EnqueueGroup(EntityGroup <T> entities, EventHandler <MatchmakingStateChangedEventArgs <T> > callback = null)
        {
            RankingMatchmakerQueueTask <T> task = new RankingMatchmakerQueueTask <T>(this, entities, callback);
            QueueGroup queueGroup = new QueueGroup {
                task = task
            };

            MatchRankingContext <T> context = new MatchRankingContext <T>(DiscardThreshold);

            //Look at all other entities in queue and rate them
            lock (queueSnapshot)
                AddMatchesToQueueGroup(queueGroup, queueSnapshot, context);

            lock (inQueue)
            {
                //Rate those to be added in future
                AddMatchesToQueueGroup(queueGroup, inQueue, context);

                //Add to in queue for next tick/flush
                inQueue.Enqueue(queueGroup);
            }

            return(task);
        }
コード例 #3
0
 /// <summary>
 ///     Cancels a given task
 /// </summary>
 /// <param name="task">The task to cancel.</param>
 internal void Cancel(RankingMatchmakerQueueTask <T> task)
 {
     //Add to out queue for next tick/flush
     lock (outQueue)
         outQueue.Enqueue(task);
 }