void StubRegistration(QueryMatchID id, SetQueryArgs args,
                              Dictionary <IMRObject, ChildMatchInfo> expectedMatches = null)
        {
            var module = ModuleLoaderCore.instance.GetModule <QueryPipelinesModule>();

            module.GroupPipeline = m_GroupPipeline;
            m_GroupPipeline.Register(id, args);

            if (expectedMatches == null)
            {
                return;
            }

            var memberCount   = 0;
            var setIndex      = m_GroupPipeline.Data.MatchIdToIndex[id];
            var memberIndices = m_GroupPipeline.Data.MemberIndices[setIndex];

            // fake like we already acquired the match
            foreach (var child in expectedMatches)
            {
                var memberIndex = memberIndices[memberCount];
                var matchInfo   = child.Value;
                m_GroupPipeline.MemberData.BestMatchDataIds[memberIndex] = matchInfo.dataID;
                memberCount++;
            }
        }
Exemple #2
0
        public void Register(SetQueryArgs args)
        {
            var countBefore  = m_Data.Count;
            var queryMatchId = RegisterFromSetArgs(args);

            Assert.AreEqual(countBefore + 1, m_Data.Count);

            int index;

            Assert.True(m_Data.MatchIdToIndex.TryGetValue(queryMatchId, out index));
            Assert.True(m_Data.ValidIndices.Contains(index));

            Assert.AreEqual(m_Data.SetQueryArgs[index], args);
            Assert.AreEqual(m_Data.UpdateMatchInterval[index], args.commonQueryData.updateMatchInterval);
            Assert.AreEqual(m_Data.TimeOuts[index], args.commonQueryData.timeOut);
            Assert.AreEqual(m_Data.ReAcquireOnLoss[index], args.commonQueryData.reacquireOnLoss);
            Assert.AreEqual(m_Data.Relations[index], args.relations);
            Assert.AreEqual(m_Data.AcquireHandlers[index], args.onAcquire);
            Assert.AreEqual(m_Data.UpdateHandlers[index], args.onMatchUpdate);
            Assert.AreEqual(m_Data.LossHandlers[index], args.onLoss);
            Assert.AreEqual(m_Data.TimeoutHandlers[index], args.onTimeout);
            // make sure we got all necessary intermediate / result containers from the pools when we registered
            Assert.NotNull(m_Data.CachedTraits[index]);
            Assert.NotNull(m_Data.RelationIndexPairs[index]);
            Assert.NotNull(m_Data.LocalRelationIndexPairs[index]);
            Assert.NotNull(m_Data.RelationRatings[index]);
            Assert.NotNull(m_Data.QueryResults[index]);
        }
        static Relations MakeBaseSet(out SetQueryResult result, Dictionary <IMRObject, ChildMatchInfo> childrenExpectedMatchInfo)
        {
            var gameObject = new GameObject("Set");

            gameObject.AddComponent <ProxyGroup>();
            k_ToDestroy.Add(gameObject);

            // Make child MR objects and give them ordinary relations
            var children = new Dictionary <IMRObject, SetChildArgs>();

            for (var i = 0; i < k_RelationCount + 1; ++i)
            {
                var childGameObject = new GameObject("Child" + i);
                k_ToDestroy.Add(childGameObject);
                childGameObject.transform.SetParent(gameObject.transform);
                var conditionsRoot    = childGameObject.AddComponent <TestMRObject>();
                var expectedMatchInfo = new ChildMatchInfo();
                childrenExpectedMatchInfo[conditionsRoot] = expectedMatchInfo;

                var hasTraitCondition = childGameObject.AddComponent <SemanticTagCondition>();
                hasTraitCondition.SetTraitName(k_CommonTrait);
                expectedMatchInfo.semanticTagTraits.Add(k_CommonTrait, true);

                var conditions = ProxyConditions.FromGenericIMRObject(conditionsRoot);
                var childArgs  = new SetChildArgs(conditions);
                children[conditionsRoot] = childArgs;
            }

            // Make relations and store the expected trait values that will match them
            var childrenList = new List <IMRObject>(children.Keys);

            for (var i = 0; i < k_RelationCount; ++i)
            {
                var child1 = childrenList[i];
                var child2 = childrenList[i + 1];

                var floatRelation = gameObject.AddComponent <FloatRelation>();
                floatRelation.Initialize(child1, child2, k_FloatTrait1, k_FloatTrait2);
                childrenExpectedMatchInfo[child1].floatTraits[floatRelation.child1TraitName] = i;
                childrenExpectedMatchInfo[child2].floatTraits[floatRelation.child2TraitName] = i + 1f;

                var vector2Relation = gameObject.AddComponent <Vector2Relation>();
                vector2Relation.Initialize(child1, child2, k_Vector2Trait1, k_Vector2Trait2);
                childrenExpectedMatchInfo[child1].vector2Traits[vector2Relation.child1TraitName] = new Vector2(i, 0f);
                childrenExpectedMatchInfo[child2].vector2Traits[vector2Relation.child2TraitName] = new Vector2(i + 1f, 0f);
            }

            result = new SetQueryResult(QueryMatchID.Generate(), childrenList);

            var relations = new Relations(gameObject, children);

            s_SetArgs = new SetQueryArgs {
                relations = relations
            };
            return(relations);
        }
Exemple #4
0
        QueryMatchID RegisterFromSetArgs(SetQueryArgs args)
        {
            var matchId = QueryMatchID.Generate();
            // for these low-level tests, we don't need member indices / relation data pairs filled in.
            var memberIndices     = new int[args.relations.children.Count];
            var relationDataPairs = new RelationDataPair[args.relations.Count];

            m_Data.Register(matchId, memberIndices, relationDataPairs, args);
            return(matchId);
        }
        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);
        }
Exemple #6
0
        public void Remove(SetQueryArgs args)
        {
            var queryMatchId = RegisterFromSetArgs(args);

            int index;

            Assert.True(m_Data.MatchIdToIndex.TryGetValue(queryMatchId, out index));

            var countBefore             = m_Data.Count;
            var freedIndicesCountBefore = m_Data.FreedIndices.Count;

            Assert.True(m_Data.Remove(queryMatchId));

            // make sure we decrement the global counter
            Assert.AreEqual(countBefore - 1, m_Data.Count);
            // make sure we added the index we free to the queue
            Assert.AreEqual(freedIndicesCountBefore + 1, m_Data.FreedIndices.Count);

            Assert.True(m_Data.FreedIndices.Contains(index));
            Assert.False(m_Data.ValidIndices.Contains(index));
            Assert.False(m_Data.MatchIdToIndex.ContainsKey(queryMatchId));

            Assert.AreEqual(m_Data.SetQueryArgs[index], default(SetQueryArgs));
            Assert.AreEqual(m_Data.UpdateMatchInterval[index], default(float));
            Assert.AreEqual(m_Data.LastUpdateCheckTime[index], default(float));
            Assert.AreEqual(m_Data.TimeOuts[index], default(float));
            Assert.AreEqual(m_Data.ReAcquireOnLoss[index], default(bool));
            Assert.AreEqual(m_Data.OrderWeights[index], default(float));
            Assert.Null(m_Data.Relations[index]);
            Assert.Null(m_Data.AcquireHandlers[index]);
            Assert.Null(m_Data.UpdateHandlers[index]);
            Assert.Null(m_Data.LossHandlers[index]);
            Assert.Null(m_Data.TimeoutHandlers[index]);
            Assert.Null(m_Data.CachedTraits[index]);
            Assert.Null(m_Data.RelationRatings[index]);
            Assert.Null(m_Data.UsedByMatch[index]);
            Assert.Null(m_Data.QueryResults[index]);
            Assert.Null(m_Data.RelationIndexPairs[index]);
            Assert.Null(m_Data.LocalRelationIndexPairs[index]);
            Assert.Null(m_Data.SearchData[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);
            }
        }
 /// <summary>
 /// Notifies the MARS backend that a particular set query's arguments have been modified.
 /// </summary>
 /// <param name="caller">The object making the set query.</param>
 /// <param name="queryMatchID">The identifier of the query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 internal static void ModifySetQuery(this IUsesSetQueryResults caller, QueryMatchID queryMatchID,
                                     SetQueryArgs queryArgs)
 {
     ISetQueryResultsMethods.ModifySetQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Called to get set event(s) from the MARS backend
 /// Allows a user to specify a custom query ID to use - make sure it is unique!
 /// </summary>
 /// <param name="caller">The object making the query</param>
 /// <param name="queryMatchID">The identifier to use for this query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 public static void RegisterSetQuery(this IUsesSetQueryResults caller, QueryMatchID queryMatchID, SetQueryArgs queryArgs)
 {
     ISetQueryResultsMethods.RegisterSetOverrideQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Called to get set event(s) from the MARS backend
 /// </summary>
 /// <param name="caller">The object making the query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 /// <returns>A ID that identifies this series of queries</returns>
 public static QueryMatchID RegisterSetQuery(this IUsesSetQueryResults caller, SetQueryArgs queryArgs)
 {
     return(ISetQueryResultsMethods.RegisterSetQuery(queryArgs));
 }