private static Type[] DistinctTypes(IEnumerable <Type> types) { var typesSet = RentitasCache.GetTypeHashSet(); foreach (var index in types) { typesSet.Add(index); } var uniqueTypes = new Type[typesSet.Count]; typesSet.CopyTo(uniqueTypes); //Array.Sort(uniqueTypes); RentitasCache.PushTypeHashSet(typesSet); return(uniqueTypes); }
public Type[] GetComponentsTypes() { if (_componentTypesCache == null) { var types = RentitasCache.GetTypeHashSet(); foreach (var componentType in _poolMeta.ComponentTypes) { if (Has(componentType)) { types.Add(componentType); } } _componentTypesCache = types.ToArray(); RentitasCache.PushTypeHashSet(types); } return(_componentTypesCache); }
public Pool(string name, int creationIndex, params T[] components) : this(components.Length, creationIndex) { PoolName = name; var types = RentitasCache.GetTypeHashSet(); for (int i = 0; i < components.Length; i++) { var component = components[i]; var type = component.GetType(); if (!types.Add(type)) { throw new PoolMetaDataException <T>(this, null); } var stack = new Stack <T>(); stack.Push(component); _componentPools.Add(type, stack); _groupsForTypes.Add(type, new List <Group <T> >()); var isSingleton = component is ISingleton; if (isSingleton) { // TODO: Create auto single group var group = GetGroup(Matcher.AllOf(type)); _singletons.Add(type, group); } } _metaData = new PoolMeta( types.Count, types.ToArray(), components.ToDictionary( c => c.GetType(), c => c.ToString().Split('.').Last())); RentitasCache.PushTypeHashSet(types); }