public bool Remove(QueryMatchID id)
        {
            int index;

            if (!MatchIdToIndex.TryGetValue(id, out index))
            {
                return(false);
            }

            MatchIdToIndex.Remove(id);

            QueryMatchIds[index] = QueryMatchID.NullQuery;
            // the query result can still be in use (by the onLoss event), so we don't pool/recycle it
            QueryResults[index] = null;

            Pools.DataIdHashSets.Recycle(UsedByMatch[index]);
            UsedByMatch[index] = null;

            Pools.RelationTraitCaches.Recycle(CachedTraits[index]);
            CachedTraits[index] = null;
            Pools.RelationRatings.Recycle(RelationRatings[index]);
            RelationRatings[index] = null;

            RelationIndexPairs[index]      = null;
            LocalRelationIndexPairs[index] = null;
            RatingConfigurations[index]    = default(GroupRatingConfiguration);
            SetQueryArgs[index]            = null;

            SearchData[index]?.Dispose();
            SearchData[index]   = null;
            SetMatchData[index] = default;

            TimeOuts[index]            = 0f;
            OrderWeights[index]        = 0f;
            Relations[index]           = null;
            ReAcquireOnLoss[index]     = false;
            Priorities[index]          = default;
            UpdateMatchInterval[index] = 0f;
            LastUpdateCheckTime[index] = 0f;

            AcquireHandlers[index] = null;
            UpdateHandlers[index]  = null;
            LossHandlers[index]    = null;
            TimeoutHandlers[index] = null;

            FreeIndex(index);
            if (UpdatingIndices.Contains(index))
            {
                UpdatingIndices.Remove(index);
            }

            if (AcquiringIndices.Contains(index))
            {
                AcquiringIndices.Remove(index);
            }

            m_Count--;
            return(true);
        }
Esempio n. 2
0
        public void Modify(QueryMatchID id, QueryArgs args)
        {
            if (!MatchIdToIndex.TryGetValue(id, out var index))
            {
                return;
            }

            Assert.IsTrue(QueryMatchIds[index].Equals(id),
                          $"{index} mismatch with {id}!");

            QueryArgs[index]        = args;
            Exclusivities[index]    = args.exclusivity;
            BestMatchDataIds[index] = (int)ReservedDataIDs.Invalid;

            TimeOuts[index]            = args.commonQueryData.timeOut;
            ReAcquireOnLoss[index]     = args.commonQueryData.reacquireOnLoss;
            Priority[index]            = args.commonQueryData.priority;
            UpdateMatchInterval[index] = args.commonQueryData.updateMatchInterval;

            CachedTraits[index]            = new CachedTraitCollection(args.conditions);
            TraitRequirements[index]       = args.traitRequirements;
            Conditions[index]              = args.conditions;
            ConditionRatings[index]        = Pools.ConditionRatings.Get().Initialize(args.conditions);
            ConditionMatchSets[index]      = Pools.DataIdHashSets.Get();
            ReducedConditionRatings[index] = Pools.Ratings.Get();
            QueryResults[index]            = new QueryResult {
                queryMatchId = id
            };

            AcquireHandlers[index] = args.onAcquire;
            UpdateHandlers[index]  = args.onMatchUpdate;
            LossHandlers[index]    = args.onLoss;
            TimeoutHandlers[index] = args.onTimeout;

            if (!AcquiringIndices.Contains(index))
            {
                AcquiringIndices.Add(index);
            }

            UpdatingIndices.Remove(index);
        }
        public void Modify(int index, int[] members, RelationDataPair[] pairs, SetQueryArgs args)
        {
            Assert.IsTrue(ValidIndices.Contains(index),
                          $"{index} is not valid to modify!");

            SetQueryArgs[index]  = args;
            MemberIndices[index] = members;

            CachedTraits[index] = new RelationTraitCache(args.relations);
            Relations[index]    = args.relations;
            RelationRatings[index].Clear();
            RelationRatings[index].Initialize(args.relations);

            RelationIndexPairs[index] = pairs;
            var localPairs = new RelationDataPair[pairs.Length];

            MapGlobalToLocalRelationPairs(members, pairs, localPairs);
            LocalRelationIndexPairs[index] = localPairs;

            TimeOuts[index]            = args.commonQueryData.timeOut;
            ReAcquireOnLoss[index]     = args.commonQueryData.reacquireOnLoss;
            Priorities[index]          = args.commonQueryData.priority;
            UpdateMatchInterval[index] = args.commonQueryData.updateMatchInterval;
            LastUpdateCheckTime[index] = 0f;
            AcquireHandlers[index]     = args.onAcquire;
            UpdateHandlers[index]      = args.onMatchUpdate;
            LossHandlers[index]        = args.onLoss;
            TimeoutHandlers[index]     = args.onTimeout;

            if (UpdatingIndices.Contains(index))
            {
                UpdatingIndices.Remove(index);
            }

            if (!AcquiringIndices.Contains(index))
            {
                AcquiringIndices.Add(index);
            }
        }