public void Modify(QueryMatchID id, int index, SetChildArgs args)
        {
            Assert.IsTrue(MatchIdToIndex.ContainsKey(id) &&
                          QueryMatchIds[index].Equals(id) &&
                          ValidIndices.Contains(index),
                          $"Invalid query match id {id} or invalid index {index}");

            Exclusivities[index]       = args.tryBestMatchArgs.exclusivity;
            Required[index]            = args.required;
            BestMatchDataIds[index]    = (int)ReservedDataIDs.Invalid;
            CachedTraits[index]        = new CachedTraitCollection(args.tryBestMatchArgs.conditions);
            Conditions[index]          = args.tryBestMatchArgs.conditions;
            TraitRequirements[index]   = args.TraitRequirements;
            RelationMemberships[index] = null;
            ConditionRatings[index].Recycle();
            ConditionRatings[index] = Pools.ConditionRatings.Get().Initialize(args.tryBestMatchArgs.conditions);
            ReducedConditionRatings[index].Clear();
            ConditionMatchSets[index].Clear();
            QueryResults[index] = new QueryResult {
                queryMatchId = id
            };

            AcquiringIndices.Add(index);
            UpdatingIndices.Remove(index);
        }
예제 #2
0
        public void Clear()
        {
            m_Count = 0;
            MatchIdToIndex.Clear();
            ValidIndices.Clear();
            FreedIndices.Clear();
            FilteredAcquiringIndices.Clear();
            AcquiringIndices.Clear();
            PotentialMatchAcquiringIndices.Clear();
            DefiniteMatchAcquireIndices.Clear();
            UpdatingIndices.Clear();

            Array.Clear(QueryMatchIds, 0, QueryMatchIds.Length);
            Array.Clear(QueryArgs, 0, QueryArgs.Length);
            Array.Clear(Exclusivities, 0, Exclusivities.Length);

            Array.Clear(UpdateMatchInterval, 0, UpdateMatchInterval.Length);
            Array.Clear(TimeOuts, 0, TimeOuts.Length);
            Array.Clear(ReAcquireOnLoss, 0, ReAcquireOnLoss.Length);

            Array.Clear(Conditions, 0, Conditions.Length);
            Array.Clear(TraitRequirements, 0, TraitRequirements.Length);
            Array.Clear(CachedTraits, 0, CachedTraits.Length);
            Array.Clear(ConditionRatings, 0, ConditionRatings.Length);
            Array.Clear(ConditionMatchSets, 0, ConditionMatchSets.Length);
            Array.Clear(ReducedConditionRatings, 0, ReducedConditionRatings.Length);
            Array.Clear(BestMatchDataIds, 0, BestMatchDataIds.Length);
            Array.Clear(QueryResults, 0, QueryResults.Length);

            Array.Clear(AcquireHandlers, 0, AcquireHandlers.Length);
            Array.Clear(UpdateHandlers, 0, UpdateHandlers.Length);
            Array.Clear(LossHandlers, 0, LossHandlers.Length);
            Array.Clear(TimeoutHandlers, 0, TimeoutHandlers.Length);
        }
        int Add(QueryMatchID matchId,
                IMRObject objectRef,
                Exclusivity exclusivity,
                int bestMatchDataId,
                bool isRequired,
                CachedTraitCollection traitCache,
                ProxyConditions condition,
                ProxyTraitRequirements requirements,
                ConditionRatingsData rating,
                HashSet <int> matchSet,
                Dictionary <int, float> flatRatings,
                QueryResult result)
        {
            var index = GetInsertionIndex();

            QueryMatchIds[index]           = matchId;
            ObjectReferences[index]        = objectRef;
            Exclusivities[index]           = exclusivity;
            Required[index]                = isRequired;
            BestMatchDataIds[index]        = bestMatchDataId;
            CachedTraits[index]            = traitCache;
            Conditions[index]              = condition;
            TraitRequirements[index]       = requirements;
            RelationMemberships[index]     = null;
            ConditionRatings[index]        = rating;
            ReducedConditionRatings[index] = flatRatings;
            ConditionMatchSets[index]      = matchSet;
            QueryResults[index]            = result;

            m_Count++;
            ValidIndices.Add(index);
            return(index);
        }
        public void Clear()
        {
            m_Count = 0;
            MatchIdToIndex.Clear();

            ValidIndices.Clear();
            FreedIndices.Clear();
            FilteredAcquiringIndices.Clear();
            AcquiringIndices.Clear();
            DefiniteMatchAcquireIndices.Clear();
            UpdatingIndices.Clear();

            Array.Clear(QueryMatchIds, 0, QueryMatchIds.Length);
            Array.Clear(Exclusivities, 0, Exclusivities.Length);
            Array.Clear(Required, 0, Required.Length);
            Array.Clear(Conditions, 0, Conditions.Length);
            Array.Clear(TraitRequirements, 0, TraitRequirements.Length);
            Array.Clear(CachedTraits, 0, CachedTraits.Length);
            Array.Clear(ConditionRatings, 0, ConditionRatings.Length);
            Array.Clear(ConditionMatchSets, 0, ConditionMatchSets.Length);
            Array.Clear(ReducedConditionRatings, 0, ReducedConditionRatings.Length);
            Array.Clear(BestMatchDataIds, 0, BestMatchDataIds.Length);
            Array.Clear(QueryResults, 0, QueryResults.Length);
            Array.Clear(ObjectReferences, 0, ObjectReferences.Length);
            Array.Clear(RelationMemberships, 0, RelationMemberships.Length);
        }
        public int Register(QueryMatchID id, int[] members, RelationDataPair[] pairs, SetQueryArgs args)
        {
            var index = GetInsertionIndex();

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

            UsedByMatch[index]  = Pools.DataIdHashSets.Get();
            SetMatchData[index] = new SetMatchData()
            {
                dataAssignments = new Dictionary <IMRObject, int>(),
                exclusivities   = new Dictionary <IMRObject, Exclusivity>()
            };

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

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

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

            QueryResults[index]        = new SetQueryResult(id);
            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;
            // SearchData will be initialized after the initial add

            m_Count++;
            MatchIdToIndex.Add(id, index);
            ValidIndices.Add(index);
            AcquiringIndices.Add(index);
            return(index);
        }
        public void Clear()
        {
            m_Count = 0;
            MatchIdToIndex.Clear();
            ValidIndices.Clear();
            FreedIndices.Clear();
            FilteredAcquiringIndices.Clear();
            AcquiringIndices.Clear();
            DefiniteMatchAcquireIndices.Clear();
            UpdatingIndices.Clear();

            Array.Clear(QueryMatchIds, 0, QueryMatchIds.Length);
            Array.Clear(SetQueryArgs, 0, SetQueryArgs.Length);
            Array.Clear(QueryResults, 0, QueryResults.Length);

            foreach (var hashSet in UsedByMatch)
            {
                if (hashSet != null)
                {
                    Pools.DataIdHashSets.Recycle(hashSet);
                }
            }
            Array.Clear(UsedByMatch, 0, UsedByMatch.Length);

            Array.Clear(CachedTraits, 0, CachedTraits.Length);
            Array.Clear(Relations, 0, Relations.Length);
            Array.Clear(RelationRatings, 0, RelationRatings.Length);
            Array.Clear(SearchData, 0, SearchData.Length);
            Array.Clear(SetMatchData, 0, SetMatchData.Length);
            Array.Clear(RatingConfigurations, 0, RatingConfigurations.Length);
            Array.Clear(RelationIndexPairs, 0, RelationIndexPairs.Length);
            Array.Clear(LocalRelationIndexPairs, 0, LocalRelationIndexPairs.Length);
            Array.Clear(ReAcquireOnLoss, 0, ReAcquireOnLoss.Length);
            Array.Clear(Priorities, 0, Priorities.Length);
            Array.Clear(UpdateMatchInterval, 0, UpdateMatchInterval.Length);
            Array.Clear(LastUpdateCheckTime, 0, LastUpdateCheckTime.Length);
            Array.Clear(OrderWeights, 0, OrderWeights.Length);
            Array.Clear(TimeOuts, 0, UpdateMatchInterval.Length);
            Array.Clear(AcquireHandlers, 0, AcquireHandlers.Length);
            Array.Clear(UpdateHandlers, 0, UpdateHandlers.Length);
            Array.Clear(LossHandlers, 0, LossHandlers.Length);
            Array.Clear(TimeoutHandlers, 0, TimeoutHandlers.Length);
        }
예제 #7
0
        public void Register(QueryMatchID id, QueryArgs args)
        {
            if (MatchIdToIndex.ContainsKey(id))
            {
                return; // query is already registered
            }

            var index = GetInsertionIndex();

            QueryMatchIds[index]    = 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;

            m_Count++;
            ValidIndices.Add(index);
            MatchIdToIndex.Add(id, index);
            AcquiringIndices.Add(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);
            }
        }