Beispiel #1
0
        public Result BuildQuery(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(Result.ValidBecauseEmpty);
            }

            var matches = k_Regex.Matches(input);

            if (matches.Count == 0)
            {
                return(Result.Valid(null, input));
            }

            using (var componentTypes = PooledHashSet <ComponentType> .Make())
            {
                m_UnmatchedInputBuilder.Clear();
                var pos = 0;
                for (var i = 0; i < matches.Count; i++)
                {
                    var match      = matches[i];
                    var matchGroup = match.Groups["componentType"];

                    var length = match.Index - pos;
                    if (length > 0)
                    {
                        m_UnmatchedInputBuilder.Append(input.Substring(pos, length));
                    }

                    pos = match.Index + match.Length;

                    if (matchGroup.Value.Length == 0)
                    {
                        continue;
                    }

                    var results     = ComponentTypeCache.GetExactMatchingTypes(matchGroup.Value);
                    var resultFound = false;
                    foreach (var result in results)
                    {
                        resultFound = true;
                        componentTypes.Set.Add(result);
                    }

                    if (!resultFound)
                    {
                        return(Result.Invalid(matchGroup.Value));
                    }
                }

                if (input.Length - pos > 0)
                {
                    m_UnmatchedInputBuilder.Append(input.Substring(pos));
                }

                return(Result.Valid(new EntityQueryDesc {
                    Any = componentTypes.Set.ToArray(), Options = EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludeDisabled
                }, m_UnmatchedInputBuilder.ToString()));
            }
        }
Beispiel #2
0
        public static unsafe IEnumerable <string> CollectComponentTypesFromSystemQuery(SystemHandle systemHandle)
        {
            if (systemHandle == null || !systemHandle.Valid)
            {
                return(Enumerable.Empty <string>());
            }
            ;

            using (var hashPool = PooledHashSet <string> .Make())
            {
                var hashset = hashPool.Set;

                var ptr = systemHandle.StatePointer;
                if (ptr != null && ptr->EntityQueries.length > 0)
                {
                    var queries = ptr->EntityQueries;
                    for (var i = 0; i < queries.length; i++)
                    {
                        using (var queryTypeList = queries[i].GetQueryTypes().ToPooledList())
                        {
                            foreach (var name in queryTypeList.List.Select(queryType => SpecifiedTypeName(queryType.GetManagedType())))
                            {
                                hashset.Add(name);
                            }
                        }
                    }
                }

                return(hashset.ToArray());
            }
        }
Beispiel #3
0
        IEnumerable <Type> GetSystemTypesFromNamesInSearchFilter(PlayerLoopSystemGraph graph)
        {
            if (string.IsNullOrEmpty(SearchFilter))
            {
                yield break;
            }

            var systemNameList = SearchUtility.GetStringFollowedByGivenToken(SearchFilter, Constants.SystemSchedule.k_SystemDependencyToken).ToList();

            if (!systemNameList.Any())
            {
                yield break;
            }

            using (var pooled = PooledHashSet <Type> .Make())
            {
                foreach (var system in graph.AllSystems)
                {
                    foreach (var singleSystemName in systemNameList)
                    {
                        if (string.Compare(system.GetType().Name, singleSystemName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            var type = system.GetType();
                            if (pooled.Set.Add(type))
                            {
                                yield return(type);
                            }
                        }
                    }
                }
            }
        }
        public static IEnumerable <Type> GetFuzzyMatchingTypes(string str)
        {
            var strLower = str.ToLowerInvariant();

            using (var hashPool = PooledHashSet <Type> .Make())
            {
                foreach (var nameType in m_ComponentNameTypes)
                {
                    if (nameType.Name.IndexOf(strLower) >= 0)
                    {
                        if (hashPool.Set.Add(nameType.Type))
                        {
                            yield return(nameType.Type);
                        }
                    }
                }
            }
        }
        void BuildFilterResults()
        {
            m_SearchResultsFlatSystemList.Clear();
            if (m_CurrentSearchQuery == null || string.IsNullOrWhiteSpace(m_CurrentSearchQuery.SearchString) || m_CurrentSearchQuery.Tokens.Count == 0 && string.IsNullOrEmpty(SearchFilter.ErrorComponentType))
            {
                m_SearchResultsFlatSystemList.AddRange(m_AllSystemsForSearch);
            }
            else
            {
                foreach (var systemForSearch in m_AllSystemsForSearch)
                {
                    systemForSearch.SystemDependencyCache = (from kvp in m_SystemDependencyMap where kvp.Value.Contains(systemForSearch.SystemName) select kvp.Key).ToArray();
                }

#if QUICKSEARCH_AVAILABLE
                m_SearchResultsFlatSystemList.AddRange(m_CurrentSearchQuery.Apply(m_AllSystemsForSearch));
#else
                using (var candidates = PooledHashSet <SystemForSearch> .Make())
                {
                    foreach (var system in m_AllSystemsForSearch)
                    {
                        if (SearchFilter.Names.All(n => system.SystemName.IndexOf(n, StringComparison.OrdinalIgnoreCase) >= 0))
                        {
                            candidates.Set.Add(system);
                        }

                        if (candidates.Set.Contains(system) && !SearchFilter.ComponentNames.All(component => system.ComponentNamesInQuery.Any(c => c.IndexOf(component, StringComparison.OrdinalIgnoreCase) >= 0)))
                        {
                            candidates.Set.Remove(system);
                        }

                        if (candidates.Set.Contains(system) && SearchFilter.DependencySystemNames.All(dependency => system.SystemDependency.Any(c => c.IndexOf(dependency, StringComparison.OrdinalIgnoreCase) >= 0)))
                        {
                            m_SearchResultsFlatSystemList.Add(system);
                        }
                    }
                }
#endif
            }
        }
Beispiel #6
0
        /// <summary>
        /// Get list of <see cref="Type"/> for update before/after system list for given system types.
        /// <param name="systemType">The given system <see cref="Type"/>.</param>
        /// </summary>
        public static void GetSystemDepListFromSystemTypes(IEnumerable <Type> systemType, List <Type> resultList)
        {
            var index = 0;

            using (var hashPool = PooledHashSet <Type> .Make())
            {
                var hashset = hashPool.Set;

                foreach (var singleSystemType in systemType)
                {
                    var updateBeforeList = GetSystemAttributes <UpdateBeforeAttribute>(singleSystemType);
                    var updateAfterList  = GetSystemAttributes <UpdateAfterAttribute>(singleSystemType);

                    if (index == 0)
                    {
                        hashset.UnionWith(updateBeforeList);
                        hashset.UnionWith(updateAfterList);
                    }
                    else
                    {
                        hashset.IntersectWith(updateBeforeList);
                        hashset.IntersectWith(updateAfterList);
                    }

                    index++;
                }

                resultList.Clear();
                resultList.AddRange(hashset);

                if (systemType.Count() == 1)
                {
                    resultList.Add(systemType.First());
                }
            }
        }
Beispiel #7
0
 public static PooledHashSet <T> GetHashSet <T>()
 {
     return(PooledHashSet <T> .Make());
 }