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); }
/// <summary> /// Translate the global relation member indices into "local" indices. /// A global index refers to the member's index in the parallel collections that hold all data. /// A local index refers to the index when all group members are represented /// in a collection that has length equal to count of group members. /// </summary> /// <param name="groupMemberIndices">All member indices in the group</param> /// <param name="globalPairs">The relation index pairs for the global collections</param> /// <param name="localPairs">The output local relation pairs</param> internal static void MapGlobalToLocalRelationPairs(int[] groupMemberIndices, RelationDataPair[] globalPairs, RelationDataPair[] localPairs) { k_IndexTranslations.Clear(); for (var i = 0; i < groupMemberIndices.Length; i++) { k_IndexTranslations.Add(groupMemberIndices[i], i); } for (var i = 0; i < globalPairs.Length; i++) { var inputPair = globalPairs[i]; var translated1 = k_IndexTranslations[inputPair.Child1]; var translated2 = k_IndexTranslations[inputPair.Child2]; localPairs[i] = new RelationDataPair(translated1, translated2); } }
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); } }
public void MapGlobalToLocalMemberIndices() { var globalIndices = new [] { 2, 3, 4 }; var globalRelationPairs = new [] { new RelationDataPair(2, 3), new RelationDataPair(4, 2), new RelationDataPair(3, 4), }; var expectedLocalPairs = new [] { new RelationDataPair(0, 1), new RelationDataPair(2, 0), new RelationDataPair(1, 2), }; const int pairCount = 3; var actualLocalPairs = new RelationDataPair[pairCount]; ParallelGroupData.MapGlobalToLocalRelationPairs(globalIndices, globalRelationPairs, actualLocalPairs); for (var i = 0; i < pairCount; i++) { Assert.AreEqual(expectedLocalPairs[i], actualLocalPairs[i]); } }