Ejemplo n.º 1
0
 /// <summary>
 /// Use this overload to get arguments for the next instance of a replicated Proxy
 /// </summary>
 /// <param name="original">The original / previous spawn's arguments</param>
 public TryBestMatchArguments(TryBestMatchArguments original)
 {
     conditions  = original.conditions;
     exclusivity = original.exclusivity;
     // we can re-use the internal ratings structure for all instances of a spawn
     ratings = original.ratings;
 }
        public static ProxyConditions FromGenericIMRObject <TComponentRootType>(TComponentRootType target) where TComponentRootType : Component, IMRObject
        {
            var conditions = new ProxyConditions();

            conditions.FilterConditions(target);
            return(conditions);
        }
Ejemplo n.º 3
0
        public static bool RateConditionMatchesInternal(ProxyConditions conditions,
                                                        CachedTraitCollection traits, ConditionRatingsData ratings)
        {
            conditions.TryGetType(out ICondition <System.Int32>[] intConditions);
            if (!RateConditionType(intConditions, traits, ratings[typeof(System.Int32)]))
            {
                return(false);
            }

            conditions.TryGetType(out ICondition <System.Single>[] floatConditions);
            if (!RateConditionType(floatConditions, traits, ratings[typeof(System.Single)]))
            {
                return(false);
            }

            conditions.TryGetType(out ICondition <System.String>[] stringConditions);
            if (!RateConditionType(stringConditions, traits, ratings[typeof(System.String)]))
            {
                return(false);
            }

            conditions.TryGetType(out ICondition <UnityEngine.Pose>[] poseConditions);
            if (!RateConditionType(poseConditions, traits, ratings[typeof(UnityEngine.Pose)]))
            {
                return(false);
            }

            conditions.TryGetType(out ICondition <UnityEngine.Vector2>[] vector2Conditions);
            if (!RateConditionType(vector2Conditions, traits, ratings[typeof(UnityEngine.Vector2)]))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 public SetChildArgs(ProxyConditions conditions, Exclusivity exclusivity, bool required,
                     ProxyTraitRequirements requirements = null)
 {
     this.required     = required;
     tryBestMatchArgs  = new TryBestMatchArguments(conditions, exclusivity);
     TraitRequirements = requirements;
 }
Ejemplo n.º 5
0
        static int CountInternal(ProxyConditions self)
        {
            var count = 0;

            count += self.SemanticTagConditions.Length;
            count += self.IntConditions.Length;
            count += self.FloatConditions.Length;
            count += self.StringConditions.Length;
            count += self.PoseConditions.Length;
            count += self.Vector2Conditions.Length;
            return(count);
        }
Ejemplo n.º 6
0
        internal static bool RateConditionMatches(ProxyConditions conditions, CachedTraitCollection traitCache,
                                                  ConditionRatingsData resultData)
        {
            if (conditions.Count <= 0)
            {
                return(false);
            }

            conditions.TryGetType(out ISemanticTagCondition[] semanticTagConditions);
            traitCache.TryGetType(out List <Dictionary <int, bool> > semanticTagTraits);

            var semanticTagsMatched = RateSemanticTagConditionMatches(semanticTagConditions,
                                                                      semanticTagTraits, resultData[typeof(bool)], resultData.MatchRuleIndexes);

            return(semanticTagsMatched && RateConditionMatchesInternal(conditions, traitCache, resultData));
        }
Ejemplo n.º 7
0
        internal bool DataIdPassesAll(ProxyConditions conditions, CachedTraitCollection traitCache, int dataId)
        {
            conditions.TryGetType(out ISemanticTagCondition[] semanticTagConditions);
            traitCache.TryGetType(out List <Dictionary <int, bool> > semanticTagTraits);

            for (var i = 0; i < semanticTagConditions.Length; i++)
            {
                var tagCondition       = semanticTagConditions[i];
                var tagTraitCollection = semanticTagTraits[i];

                if (!tagTraitCollection.TryGetValue(dataId, out var traitValue))
                {
                    switch (tagCondition.matchRule)
                    {
                    case SemanticTagMatchRule.Exclude:
                        continue;

                    case SemanticTagMatchRule.Match:
                        return(false);
                    }
                }

                var rating = tagCondition.RateDataMatch(ref traitValue);

                switch (tagCondition.matchRule)
                {
                case SemanticTagMatchRule.Exclude:
                    if (rating > 0f)
                    {
                        return(false);
                    }

                    break;

                case SemanticTagMatchRule.Match:
                    if (rating <= 0f)
                    {
                        return(false);
                    }

                    break;
                }
            }

            return(DataPassesAllConditionsInternal(traitCache, dataId));
        }
        internal void FillQueryResult(int dataId, ProxyConditions conditions, CachedTraitCollection traits,
                                      ProxyTraitRequirements requirements, QueryMatchID matchId, QueryResult result)
        {
            result.queryMatchId = matchId;
            result.SetDataId(dataId);

            FillRequiredTraitsAction(dataId, requirements, result);

            FillQueryResultInternal(dataId, conditions, traits, matchId, result);

            conditions.TryGetType(out ICondition <Pose>[] poseConditions);
            traits.TryGetType(out List <Dictionary <int, Pose> > poseCollections);

            for (var i = 0; i < poseConditions.Length; i++)
            {
                var poseCollection = poseCollections[i];
                var nonOffsetValue = poseCollection[dataId];
                var poseValue      = applyOffsetToPose(nonOffsetValue);
                var refiner        = poseConditions[i] as IPoseRefiner;
                if (refiner != null)
                {
                    poseValue = refiner.RefinePose(poseValue, true);
                }
                result.SetTrait(poseConditions[i].traitName, poseValue);
            }

            if (!conditions.TryGetType(out ISemanticTagCondition[] semanticTagConditions))
            {
                return;
            }

            // tags can take a shortcut with query filling - they're really just a test for presence or absence,
            // so if that test has already been passed, we can just assign a bool representing the result
            foreach (var condition in semanticTagConditions)
            {
                var isExcluding = condition.matchRule == SemanticTagMatchRule.Exclude;
                result.SetTrait(condition.traitName, !isExcluding);
            }
        }
        internal static void FillQueryResultInternal(int dataId, ProxyConditions conditions, CachedTraitCollection traits,
                                                     QueryMatchID matchId, QueryResult result)
        {
            traits.TryGetType(out List <Dictionary <int, System.Int32> > intCollections);
            conditions.TryGetType(out ICondition <System.Int32>[] intConditions);
            FillQueryResult <System.Int32>(dataId, intConditions, intCollections, result);

            traits.TryGetType(out List <Dictionary <int, System.Single> > floatCollections);
            conditions.TryGetType(out ICondition <System.Single>[] floatConditions);
            FillQueryResult <System.Single>(dataId, floatConditions, floatCollections, result);

            traits.TryGetType(out List <Dictionary <int, System.String> > stringCollections);
            conditions.TryGetType(out ICondition <System.String>[] stringConditions);
            FillQueryResult <System.String>(dataId, stringConditions, stringCollections, result);

            traits.TryGetType(out List <Dictionary <int, UnityEngine.Pose> > poseCollections);
            conditions.TryGetType(out ICondition <UnityEngine.Pose>[] poseConditions);
            FillQueryResult <UnityEngine.Pose>(dataId, poseConditions, poseCollections, result);

            traits.TryGetType(out List <Dictionary <int, UnityEngine.Vector2> > vector2Collections);
            conditions.TryGetType(out ICondition <UnityEngine.Vector2>[] vector2Conditions);
            FillQueryResult <UnityEngine.Vector2>(dataId, vector2Conditions, vector2Collections, result);
        }
Ejemplo n.º 10
0
 public TryBestMatchArguments(ProxyConditions conditions, Exclusivity exclusivity)
 {
     this.conditions  = conditions;
     this.exclusivity = exclusivity;
     ratings          = new ConditionRatingsData(conditions);
 }
Ejemplo n.º 11
0
 public SetChildArgs(ProxyConditions conditions, ProxyTraitRequirements requirements = null) :
     this(conditions, Exclusivity.ReadOnly, true, requirements)
 {
 }