public static bool TryMatchAllInternal(Relations relations, RelationTraitCache traits, RelationRatingsData ratings, Dictionary <int, float>[] memberRatings, RelationDataPair[] relationPairs) { if (relations.GetTypeCount(out IRelation <System.Int32>[] intRelations) > 0) { if (!traits.TryGetType(out List <RelationTraitCache.ChildTraits <System.Int32> > intTraits) || !RateMatches(intRelations, intTraits, relationPairs, memberRatings, ratings)) { return(false); } } if (relations.GetTypeCount(out IRelation <UnityEngine.Pose>[] poseRelations) > 0) { if (!traits.TryGetType(out List <RelationTraitCache.ChildTraits <UnityEngine.Pose> > poseTraits) || !RateMatches(poseRelations, poseTraits, relationPairs, memberRatings, ratings)) { return(false); } } if (relations.GetTypeCount(out IRelation <UnityEngine.Vector2>[] vector2Relations) > 0) { if (!traits.TryGetType(out List <RelationTraitCache.ChildTraits <UnityEngine.Vector2> > vector2Traits) || !RateMatches(vector2Relations, vector2Traits, relationPairs, memberRatings, ratings)) { return(false); } } return(true); }
/// <summary> /// Try to find matches for all Relations in a Set. /// </summary> /// <param name="relations">All relations in the set</param> /// <param name="traits">References to the trait values used by all relations</param> /// <param name="ratingData">Output list of dictionaries</param> /// <param name="memberRatings">The collection of all member ratings</param> /// <param name="relationPairs">The relation index pairs for this Set</param> /// <returns>True if all relations found at least 1 match, false otherwise</returns> public static bool TryMatchAll(Relations relations, RelationTraitCache traits, RelationRatingsData ratingData, Dictionary <int, float>[] memberRatings, RelationDataPair[] relationPairs) { CurrentRelationPairIndex = 0; foreach (var dictionary in ratingData) { dictionary.Clear(); } return(TryMatchAllInternal(relations, traits, ratingData, memberRatings, relationPairs)); }
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 TryMatchAll() { var dataSet = new RelationRatingTestData.SingleMatchUsingSameTrait(); var testObject = m_SetQueryTestObject; var relations = TestUtils.GetRelations(testObject); var traitCache = new RelationTraitCache(relations); Assert.True(traitCache.TryGetType(out List <RelationTraitCache.ChildTraits <float> > floatTraits)); traitCache.TryGetType(out List <RelationTraitCache.ChildTraits <Pose> > poseTraits); floatTraits[0] = new RelationTraitCache.ChildTraits <float>(dataSet.FloatTraitValues); // start with one of our trait values being empty of data, so we can test a failure case poseTraits[0] = new RelationTraitCache.ChildTraits <Pose>(new Dictionary <int, Pose>()); var relationRatings = new RelationRatingsData(relations); var memberRatingsArray = RandomRatingsArray(relations.children.Count); var relationIndexPairs = new RelationDataPair[relations.Count]; for (var i = 0; i < relations.Count; i++) { // for the purposes of this test, we just want to see that the lower-level // abstraction that works on a per-type basis works for all types, // so it doesn't matter if the index pair data is accurate relationIndexPairs[i] = new RelationDataPair(i, i == relations.Count - 1 ? 0 : i + 1); } // because our pose relation has no trait data, it should fail and cause the whole result to be false Assert.False(RelationRatingTransform.TryMatchAll(relations, traitCache, relationRatings, memberRatingsArray, relationIndexPairs)); // assign usable data to the trait that had no values before, and then re-try - now it should succeed poseTraits[0] = new RelationTraitCache.ChildTraits <Pose>(dataSet.PoseTraitValues); Assert.True(RelationRatingTransform.TryMatchAll(relations, traitCache, relationRatings, memberRatingsArray, relationIndexPairs)); // The default set test prefab has a float and pose relation on it, so we expect 2 Assert.AreEqual(2, relationRatings.Count); VerifyRelationRatings(relationRatings[0], floatTraits[0]); VerifyRelationRatings(relationRatings[1], poseTraits[0]); }
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); } }