public ref EntityFilterCollection GetOrCreatePersistentFilter <T>(CombinedFilterID filterID, NativeRefWrapperType typeRef) where T : unmanaged, IEntityComponent { long combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(filterID); if (_persistentEntityFilters.TryFindIndex(combineFilterIDs, out var index) == true) { return(ref _persistentEntityFilters.GetDirectValueByRef(index)); } _persistentEntityFilters.Add(combineFilterIDs, new EntityFilterCollection(filterID)); var lastIndex = _persistentEntityFilters.count - 1; if (_indicesOfPersistentFiltersUsedByThisComponent.TryFindIndex(typeRef, out var getIndex) == false) { var newArray = new NativeDynamicArrayCast <int>(1, Allocator.Persistent); newArray.Add(lastIndex); _indicesOfPersistentFiltersUsedByThisComponent.Add(typeRef, newArray); } else { ref var array = ref _indicesOfPersistentFiltersUsedByThisComponent.GetDirectValueByRef(getIndex); array.Add(lastIndex); }
public ref EntityFilterCollection GetPersistentFilter <T>(CombinedFilterID filterID) where T : unmanaged, IEntityComponent { long combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(filterID); if (_persistentEntityFilters.TryFindIndex(combineFilterIDs, out var index) == true) { return(ref _persistentEntityFilters.GetDirectValueByRef(index)); } throw new Exception("filter not found"); }
public bool TryGetTransientFilter <T>(CombinedFilterID filterID, out EntityFilterCollection entityCollection) where T : unmanaged, IEntityComponent { var combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(filterID); if (_transientEntityFilters.TryFindIndex(combineFilterIDs, out var index)) { entityCollection = _transientEntityFilters.GetDirectValueByRef(index); return(true); } entityCollection = default; return(false); }
public bool TryGetPersistentFilter <T>(CombinedFilterID combinedFilterID, out EntityFilterCollection entityCollection) where T : unmanaged, IBaseEntityComponent { long combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(combinedFilterID); if (_persistentEntityFilters.TryFindIndex(combineFilterIDs, out var index) == true) { entityCollection = _persistentEntityFilters.GetDirectValueByRef(index); return(true); } entityCollection = default; return(false); }
/// <summary> /// Creates a transient filter. Transient filters are deleted after each submission /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public ref EntityFilterCollection GetOrCreateTransientFilter <T>(CombinedFilterID filterID) where T : unmanaged, IEntityComponent { var combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(filterID); if (_transientEntityFilters.TryFindIndex(combineFilterIDs, out var index)) { return(ref _transientEntityFilters.GetDirectValueByRef(index)); } var filterCollection = new EntityFilterCollection(filterID); _transientEntityFilters.Add(combineFilterIDs, filterCollection); return(ref _transientEntityFilters.GetDirectValueByRef((uint)(_transientEntityFilters.count - 1))); }
public ref EntityFilterCollection GetOrCreatePersistentFilter <T>(CombinedFilterID filterID) where T : unmanaged, IEntityComponent { long combineFilterIDs = Internal_FilterHelper.CombineFilterIDs <T>(filterID); if (_persistentEntityFilters.TryFindIndex(combineFilterIDs, out var index) == true) { return(ref _persistentEntityFilters.GetDirectValueByRef(index)); } var typeRef = TypeRefWrapper <T> .wrapper; var filterCollection = new EntityFilterCollection(filterID); _persistentEntityFilters.Add(combineFilterIDs, filterCollection); var lastIndex = _persistentEntityFilters.count - 1; _indicesOfPersistentFiltersUsedByThisComponent.GetOrAdd(new NativeRefWrapperType(typeRef), () => new NativeDynamicArrayCast <int>(1, Svelto.Common.Allocator.Persistent)).Add(lastIndex); return(ref _persistentEntityFilters.GetDirectValueByRef((uint)lastIndex)); }