public ExclusiveGroup(ushort range) { _group = new ExclusiveGroupStruct(range); #if DEBUG _range = range; #endif }
/// <summary> /// Preallocate memory to avoid the impact to resize arrays when many entities are submitted at once /// </summary> void Preallocate(ExclusiveGroupStruct groupID, uint numberOfEntities, IComponentBuilder[] entityComponentsToBuild) { void PreallocateEntitiesToAdd() { _groupedEntityToAdd.Preallocate(groupID, numberOfEntities, entityComponentsToBuild); } void PreallocateDBGroup() { var numberOfEntityComponents = entityComponentsToBuild.Length; FasterDictionary <RefWrapperType, ITypeSafeDictionary> group = GetOrCreateDBGroup(groupID); for (var index = 0; index < numberOfEntityComponents; index++) { var entityComponentBuilder = entityComponentsToBuild[index]; var entityComponentType = entityComponentBuilder.GetEntityComponentType(); var refWrapper = new RefWrapperType(entityComponentType); var dbList = group.GetOrCreate(refWrapper, () => entityComponentBuilder.CreateDictionary(numberOfEntities)); entityComponentBuilder.Preallocate(dbList, numberOfEntities); if (_groupsPerEntity.TryGetValue(refWrapper, out var groupedGroup) == false) { groupedGroup = _groupsPerEntity[refWrapper] = new FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary>(); } groupedGroup[groupID] = dbList; } } PreallocateDBGroup(); PreallocateEntitiesToAdd(); _entityLocator.PreallocateReferenceMaps(groupID, numberOfEntities); }
static void SwapGroup(ExclusiveGroupStruct fromGroupID, ExclusiveGroupStruct toGroupID, EnginesRoot enginesRoot) { using (var sampler = new PlatformProfiler("swap whole group")) { enginesRoot.SwapEntitiesBetweenGroups(fromGroupID, toGroupID, sampler); } }
public void SwapEntity(EGID from, ExclusiveGroupStruct to, int threadIndex) { var simpleNativeBag = _swapQueue.GetBuffer(threadIndex); simpleNativeBag.Enqueue(_indexSwap); simpleNativeBag.Enqueue(new DoubleEGID(from, new EGID(from.entityID, to))); }
///-------------------------------------------- void Preallocate <T>(ExclusiveGroupStruct groupID, uint size) where T : IEntityDescriptor, new() { using (var profiler = new PlatformProfiler("Preallocate")) { var entityComponentsToBuild = EntityDescriptorTemplate <T> .descriptor.componentsToBuild; var numberOfEntityComponents = entityComponentsToBuild.Length; FasterDictionary <RefWrapper <Type>, ITypeSafeDictionary> group = GetOrCreateGroup(groupID, profiler); for (var index = 0; index < numberOfEntityComponents; index++) { var entityComponentBuilder = entityComponentsToBuild[index]; var entityComponentType = entityComponentBuilder.GetEntityComponentType(); var refWrapper = new RefWrapper <Type>(entityComponentType); if (group.TryGetValue(refWrapper, out var dbList) == false) { group[refWrapper] = entityComponentBuilder.Preallocate(ref dbList, size); } else { dbList.SetCapacity(size); } if (_groupsPerEntity.TryGetValue(refWrapper, out var groupedGroup) == false) { groupedGroup = _groupsPerEntity[refWrapper] = new FasterDictionary <uint, ITypeSafeDictionary>(); } groupedGroup[groupID] = dbList; } } }
public void DisposeFilterForGroup <T>(int resetFilterID, ExclusiveGroupStruct @group) { if (_filters.TryGetValue(TypeRefWrapper <T> .wrapper, out var fasterDictionary) == true) { fasterDictionary[group].DisposeFilter(resetFilterID); } }
static void RemoveGroup(ExclusiveGroupStruct groupID, EnginesRoot enginesRoot) { using (var sampler = new PlatformProfiler("remove whole group")) { enginesRoot.RemoveEntitiesFromGroup(groupID, sampler); } }
public void SwapEntitiesInGroup <T>(ExclusiveGroupStruct fromGroupID, ExclusiveGroupStruct toGroupID) where T : IEntityDescriptor, new() { #if DEBUG && !PROFILE_SVELTO IComponentBuilder[] components = EntityDescriptorTemplate <T> .descriptor.componentsToBuild; if (_enginesRoot.Target._groupEntityComponentsDB.TryGetValue(fromGroupID, out var entitiesInGroupPerType) == false) { throw new Exception("Entity Serialization failed"); } foreach (var component in components) { var dictionary = entitiesInGroupPerType[new RefWrapper <Type>(component.GetEntityComponentType())]; dictionary.KeysEvaluator((key) => { _enginesRoot.Target.CheckRemoveEntityID(new EGID(key, fromGroupID), component.GetType()); _enginesRoot.Target.CheckAddEntityID(new EGID(key, fromGroupID), component.GetType()); }); } #endif _enginesRoot.Target.QueueEntitySubmitOperation( new EntitySubmitOperation(EntitySubmitOperationType.SwapGroup, new EGID(0, fromGroupID), new EGID(0, toGroupID))); }
internal void Preallocate (ExclusiveGroupStruct groupID, uint numberOfEntities, IComponentBuilder[] entityComponentsToBuild) { void PreallocateDictionaries (FasterDictionary <ExclusiveGroupStruct, FasterDictionary <RefWrapperType, ITypeSafeDictionary> > dic) { var group = dic.GetOrCreate(groupID, () => new FasterDictionary <RefWrapperType, ITypeSafeDictionary>()); foreach (var componentBuilder in entityComponentsToBuild) { var entityComponentType = componentBuilder.GetEntityComponentType(); var safeDictionary = group.GetOrCreate(new RefWrapperType(entityComponentType) , () => componentBuilder .CreateDictionary(numberOfEntities)); componentBuilder.Preallocate(safeDictionary, numberOfEntities); } } PreallocateDictionaries(current); PreallocateDictionaries(other); _currentEntitiesCreatedPerGroup.GetOrCreate(groupID); _otherEntitiesCreatedPerGroup.GetOrCreate(groupID); }
public EntityStructInitializer BuildEntity <T>(uint entityID, ExclusiveGroupStruct groupStructId, IEnumerable <object> implementors = null) where T : IEntityDescriptor, new() { return(_enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId), EntityDescriptorTemplate <T> .descriptor.entitiesToBuild, implementors)); }
public NativeEGIDMapper (ExclusiveGroupStruct groupStructId , SveltoDictionary <uint, T, NativeStrategy <FasterDictionaryNode <uint> >, NativeStrategy <T> > toNative) : this() { groupID = groupStructId; map = toNative; }
public ExclusiveGroup(ushort range) { _group = ExclusiveGroupStruct.GenerateWithRange(range); #if DEBUG _range = range; #endif }
public void RemoveGroupAndEntities(ExclusiveGroupStruct groupID) { _enginesRoot.Target.RemoveGroupID(groupID); _enginesRoot.Target.QueueEntitySubmitOperation( new EntitySubmitOperation(EntitySubmitOperationType.RemoveGroup, new EGID(0, groupID), new EGID())); }
public EntityComponentInitializer BuildEntity <T> (uint entityID, ExclusiveGroupStruct groupStructId, T descriptorEntity, IEnumerable <object> implementors) where T : IEntityDescriptor { return(_enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId) , descriptorEntity.componentsToBuild, implementors)); }
public GroupFilters(SharedSveltoDictionaryNative <int, FilterGroup> filters, ExclusiveGroupStruct group) { this.filters = filters; #if DEBUG && !PROFILE_SVELTO _group = @group; #endif }
public ref FilterGroup CreateOrGetFilterForGroup <T>(int filterID, ExclusiveGroupStruct groupID) where T : struct, IEntityComponent { var refWrapper = TypeRefWrapper <T> .wrapper; return(ref CreateOrGetFilterForGroup(filterID, groupID, refWrapper)); }
internal static NativeEGIDMapper <T> ToNativeEGIDMapper <T>(this TypeSafeDictionary <T> dic, ExclusiveGroupStruct groupStructId) where T : unmanaged, IEntityComponent { var mapper = new NativeEGIDMapper <T>(groupStructId, dic.implUnmgd); return(mapper); }
public void DisposeFilters <T>(ExclusiveGroupStruct exclusiveGroupStruct) { if (_filters.TryGetValue(TypeRefWrapper <T> .wrapper, out var fasterDictionary) == true) { fasterDictionary[exclusiveGroupStruct].DisposeFilters(); fasterDictionary.Remove(exclusiveGroupStruct); } }
public bool HasFiltersForGroup <T>(ExclusiveGroupStruct groupID) where T : struct, IEntityComponent { if (_filters.ContainsKey(TypeRefWrapper <T> .wrapper) == false) { return(false); } return(_filters[TypeRefWrapper <T> .wrapper].ContainsKey(groupID)); }
public void RemoveEntitiesFromGroup(ExclusiveGroupStruct groupID) { _enginesRoot.Target.RemoveGroupID(groupID); DBC.ECS.Check.Require(groupID != 0, "invalid group detected"); _enginesRoot.Target.QueueEntitySubmitOperation( new EntitySubmitOperation(EntitySubmitOperationType.RemoveGroup, new EGID(0, groupID), new EGID())); }
internal Consumer <T> GenerateConsumer(ExclusiveGroupStruct group, string name, uint capacity) { var consumer = new Consumer <T>(group, name, capacity); _consumers.Add(consumer); return(consumer); }
internal FilterGroup(ExclusiveGroupStruct exclusiveGroupStruct) { _denseListOfIndicesToEntityComponentArray = new NativeDynamicArrayCast <uint>(NativeDynamicArray.Alloc <uint>(Allocator.Persistent)); _reverseEGIDs = new NativeDynamicArrayCast <uint>(NativeDynamicArray.Alloc <uint>(Allocator.Persistent)); _EIDs = new SharedSveltoDictionaryNative <uint, uint>(0, Allocator.Persistent); _exclusiveGroupStruct = exclusiveGroupStruct; }
public bool HasFiltersForGroup <T>(ExclusiveGroupStruct groupID) where T : struct, IEntityComponent { if (_filters.TryGetValue(TypeRefWrapper <T> .wrapper, out var fasterDictionary) == false) { return(false); } return(fasterDictionary.ContainsKey(groupID)); }
public void ClearFilter <T>(int filterID, ExclusiveGroupStruct exclusiveGroupStruct) { if (_filters.TryGetValue(TypeRefWrapper <T> .wrapper, out var fasterDictionary) == true) { DBC.ECS.Check.Require(fasterDictionary.ContainsKey(exclusiveGroupStruct), $"trying to clear filter not present in group {exclusiveGroupStruct}"); fasterDictionary[exclusiveGroupStruct].ClearFilter(filterID); } }
public ref LegacyGroupFilters CreateOrGetFiltersForGroup <T>(ExclusiveGroupStruct groupID) where T : struct, IBaseEntityComponent { var fasterDictionary = _filtersLegacy.GetOrAdd(TypeRefWrapper <T> .wrapper, () => new FasterDictionary <ExclusiveGroupStruct, LegacyGroupFilters>()); return(ref fasterDictionary.GetOrAdd(groupID, () => new LegacyGroupFilters(new SharedSveltoDictionaryNative <int, LegacyFilterGroup>(0), groupID))); }
public GroupFilters GetGroupFilter(ExclusiveGroupStruct group) { if (_filtersPerGroup.TryGetValue(group, out var groupFilter) == true) { return(groupFilter); } throw new Exception($"no filter linked to group {group}"); }
FasterDictionary <RefWrapperType, ITypeSafeDictionary> GetDBGroup(ExclusiveGroupStruct fromIdGroupId) { if (_groupEntityComponentsDB.TryGetValue(fromIdGroupId, out FasterDictionary <RefWrapperType, ITypeSafeDictionary> fromGroup) == false) { throw new ECSException("Group doesn't exist: ".FastConcat(fromIdGroupId.ToName())); } return(fromGroup); }
public void ClearFilters <T>(int filterID, ExclusiveGroupStruct exclusiveGroupStruct) { if (_filters.ContainsKey(TypeRefWrapper <T> .wrapper) == true) { FasterDictionary <ExclusiveGroupStruct, GroupFilters> fasterDictionary = _filters[TypeRefWrapper <T> .wrapper]; fasterDictionary[exclusiveGroupStruct].ClearFilter(filterID); } }
public void SwapEntitiesInGroup <T>(ExclusiveGroupStruct fromGroupID, ExclusiveGroupStruct toGroupID) { throw new NotImplementedException("can't run this until I add the checks!"); #pragma warning disable 162 _enginesRoot.Target.QueueEntitySubmitOperation( new EntitySubmitOperation(EntitySubmitOperationType.SwapGroup, new EGID(0, fromGroupID), new EGID(0, toGroupID))); #pragma warning restore 162 }
public GroupFilters GetOrCreateGroupFilter(ExclusiveGroupStruct group) { if (_filtersPerGroup.TryGetValue(group, out var groupFilter) == false) { groupFilter = new GroupFilters(group); _filtersPerGroup.Add(group, groupFilter); } return(groupFilter); }