public Entity AddEntity <T>(T data, bool updateFilters = true) where T : struct, IEntity { if (data.entity.id == 0) { data.entity = this.CreateNewEntity <T>(); } var code = WorldUtilities.GetKey(data); IList list; if (this.entitiesCache.TryGetValue(code, out list) == true) { ((List <T>)list).Add(data); } else { list = PoolList <T> .Spawn(this.GetCapacity <T>(code)); ((List <T>)list).Add(data); this.entitiesCache.Add(code, list); } if (updateFilters == true) { this.UpdateFilters <T>(code); } this.UpdateEntityCache(data); return(data.entity); }
void IPoolableRecycle.OnRecycle() { this.ReleaseState(ref this.resetState); this.ReleaseState(ref this.currentState); for (int i = 0; i < this.systems.Count; ++i) { this.systems[i].OnDeconstruct(); PoolSystems.Recycle(this.systems[i]); } PoolList <ISystem <TState> > .Recycle(ref this.systems); for (int i = 0; i < this.modules.Count; ++i) { this.modules[i].OnDeconstruct(); PoolModules.Recycle(this.modules[i]); } PoolList <IModule <TState> > .Recycle(ref this.modules); PoolDictionary <int, IList> .Recycle(ref this.entitiesCache); //PoolDictionary<EntityId, IEntity>.Recycle(ref this.entitiesDirectCache); PoolDictionary <int, IList> .Recycle(ref this.filtersCache); PoolDictionary <int, IComponents> .Recycle(ref this.componentsCache); PoolDictionary <int, int> .Recycle(ref this.capacityCache); }
public void CopyFrom(Filter <T> other) { if (this.list != null) { PoolList <T> .Recycle(ref this.list); } this.list = PoolList <T> .Spawn(other.list.Capacity); this.list.AddRange(other.list); }
public void SetData(List <T> data) { if (this.freeze == false && data != null && this.list != data) { if (this.list != null) { PoolList <T> .Recycle(ref this.list); } this.list = data; } }
void IPoolableRecycle.OnRecycle() { foreach (var item in this.dic) { PoolComponents.Recycle(item.Value); PoolList <IComponent <TState, TEntity> > .Recycle(item.Value); } PoolDictionary <EntityId, List <IComponent <TState, TEntity> > > .Recycle(ref this.dic); this.freeze = false; this.capacity = 0; }
public static void Recycle <T, TCopy>(ref ListCopyable <T> item, TCopy copy) where TCopy : IArrayElementCopy <T> { if (item != null) { for (int i = 0; i < item.Count; ++i) { copy.Recycle(item[i]); } PoolList <T> .Recycle(ref item); } }
public void CopyFrom(FiltersStorage other) { /*if (this.filters != null) { * * for (int i = 0, count = this.filters.Count; i < count; ++i) { * * this.filters[i].Recycle(); * * } * * PoolList<IFilterBase>.Recycle(ref this.filters); * * } * this.filters = PoolList<IFilterBase>.Spawn(other.filters.Count); * * for (int i = 0, count = other.filters.Count; i < count; ++i) { * * var copy = other.filters[i].Clone(); * this.filters.Add(copy); * UnityEngine.Debug.Log("Copy filter: " + i + " :: " + other.filters[i].id + " >> " + this.filters.Count + " (" + copy.id + ")"); * * }*/ if (this.freeze == true) { // Just copy if filters storage is in freeze mode if (this.filters == null) { this.filters = PoolList <IFilterBase> .Spawn(other.filters.Count); } for (int i = 0, count = other.filters.Count; i < count; ++i) { if (i >= this.filters.Count) { this.filters.Add(other.filters[i].Clone()); } else { this.filters[i].CopyFrom(other.filters[i]); } } } else { // Filters storage is not in a freeze mode, so it is an active state filters for (int i = 0, count = other.filters.Count; i < count; ++i) { this.filters[i].CopyFrom(other.filters[i]); } } }
void IPoolableRecycle.OnRecycle() { this.freeze = default; if (this.filters != null) { for (int i = 0, count = this.filters.Count; i < count; ++i) { this.filters[i].Recycle(); } PoolList <IFilterBase> .Recycle(ref this.filters); } }
void IPoolableSpawn.OnSpawn() { this.systems = PoolList <ISystem <TState> > .Spawn(100); this.modules = PoolList <IModule <TState> > .Spawn(100); this.entitiesCache = PoolDictionary <int, IList> .Spawn(100); //this.entitiesDirectCache = PoolDictionary<EntityId, IEntity>.Spawn(100); this.filtersCache = PoolDictionary <int, IList> .Spawn(100); this.componentsCache = PoolDictionary <int, IComponents> .Spawn(100); this.capacityCache = PoolDictionary <int, int> .Spawn(100); }
public void Register <TEntity>(ref Filter <TEntity> filterRef, bool freeze, bool restore) where TEntity : struct, IEntity { var code = WorldUtilities.GetKey <TEntity>(); var capacity = this.GetCapacity <TEntity>(code); if (filterRef == null) { filterRef = PoolClass <Filter <TEntity> > .Spawn(); filterRef.Initialize(capacity); filterRef.SetFreeze(freeze); } else { filterRef.SetFreeze(freeze); } if (freeze == false) { IList list; if (this.filtersCache.TryGetValue(code, out list) == true) { ((List <Filter <TEntity> >)list).Add(filterRef); } else { list = PoolList <Filter <TEntity> > .Spawn(capacity); ((List <Filter <TEntity> >)list).Add(filterRef); this.filtersCache.Add(code, list); } } if (restore == true) { // Update entities cache for (int i = 0; i < filterRef.Count; ++i) { var item = filterRef[i]; var list = PoolList <TEntity> .Spawn(capacity); list.Add(item); this.AddEntity(item, updateFilters: false); } this.UpdateFilters <TEntity>(code); } }
public void Add(Entity entity, IComponent <TState, TEntity> data) { List <IComponent <TState, TEntity> > list; if (this.dic.TryGetValue(entity.id, out list) == true) { list.Add(data); } else { list = PoolList <IComponent <TState, TEntity> > .Spawn(this.capacity); list.Add(data); this.dic.Add(entity.id, list); } }
public static void Copy <T, TCopy>(System.Collections.Generic.List <T> fromArr, ref System.Collections.Generic.List <T> arr, TCopy copy) where TCopy : IArrayElementCopy <T> { if (fromArr == null) { if (arr != null) { for (int i = 0; i < arr.Count; ++i) { copy.Recycle(arr[i]); } PoolList <T> .Recycle(ref arr); } arr = null; return; } if (arr == null || fromArr.Count != arr.Count) { if (arr != null) { ArrayUtils.Recycle(ref arr, copy); } arr = PoolList <T> .Spawn(fromArr.Count); } var cnt = arr.Count; for (int i = 0; i < fromArr.Count; ++i) { var isDefault = i >= cnt; T item = (isDefault ? default : arr[i]); copy.Copy(fromArr[i], ref item); if (isDefault == true) { arr.Add(item); } else { arr[i] = item; } } }
public static void Copy <T>(ListCopyable <T> fromArr, ref ListCopyable <T> arr) where T : struct { if (fromArr == null) { if (arr != null) { PoolList <T> .Recycle(ref arr); } arr = null; return; } if (arr == null) { arr = PoolList <T> .Spawn(fromArr.Count); } arr.CopyFrom(fromArr); }
public void CopyFrom(Components <TEntity, TState> other) { if (this.dic != null) { foreach (var item in this.dic) { //PoolComponents.Recycle(item.Value); PoolList <IComponent <TState, TEntity> > .Recycle(item.Value); } PoolDictionary <EntityId, List <IComponent <TState, TEntity> > > .Recycle(ref this.dic); } this.dic = PoolDictionary <EntityId, List <IComponent <TState, TEntity> > > .Spawn(this.capacity); foreach (var item in other.dic) { var newList = PoolList <IComponent <TState, TEntity> > .Spawn(item.Value.Capacity); newList.AddRange(item.Value); this.dic.Add(item.Key, newList); } }
public static void Copy <T>(System.Collections.Generic.List <T> fromArr, ref System.Collections.Generic.List <T> arr) where T : struct { if (fromArr == null) { if (arr != null) { PoolList <T> .Recycle(ref arr); } arr = null; return; } if (arr == null || fromArr.Count != arr.Count) { if (arr != null) { PoolList <T> .Recycle(ref arr); } arr = PoolList <T> .Spawn(fromArr.Count); } var cnt = arr.Count; for (int i = 0; i < fromArr.Count; ++i) { var isDefault = i >= cnt; var item = fromArr[i]; if (isDefault == true) { arr.Add(item); } else { arr[i] = item; } } }
public void Initialize(int capacity) { this.filters = PoolList <IFilterBase> .Spawn(capacity); }
public void Initialize(int capacity) { this.list = PoolList <T> .Spawn(capacity); }
void IPoolableRecycle.OnRecycle() { PoolList <T> .Recycle(ref this.list); this.freeze = false; }