/// Use pool.CreateEntity() to create a new entity and pool.DestroyEntity() to destroy it. public Entity(Dictionary <Type, Stack <T> > componentsPool, PoolMeta meta) { _poolMeta = meta; _componentsPool = componentsPool; _totalComponents = meta.TotalComponents; _components = new Dictionary <Type, T>(_totalComponents); foreach (var kv in _componentsPool) { _components.Add(kv.Key, null); } }
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); }
public PoolMetaDataException(Pool <T> pool, PoolMeta poolMetaData) : base("Invalid PoolMetaData for '" + pool + "'!\nExpected " + pool?.TotalComponents + " componentName(s) but got " + poolMetaData?.TotalComponents, null) { }