JobHandle scheduleCollisionJob(EntityTypeData.EntityType entityTypeToCheck, EntityTypeData.EntityType entityTypeToCheckWith, JobHandle jobDependencies) { JobHandle collisionDetectJobHandle = new JobHandle(); if (entityTypeList.Contains(entityTypeToCheck) && entityTypeList.Contains(entityTypeToCheckWith)) { CollisionDetectJob collisionDetectJob = new CollisionDetectJob { entityArray = subsetEntityDictionary[entityTypeToCheck], entityBoundMinMaxData = subsetMinMaxDataDictionary[entityTypeToCheck], boundCells = cellEntityTypeDictionary[entityTypeToCheckWith], cellSizes = cellSizeEntityDictionary[entityTypeToCheckWith], collidedEntityQueue = destroyEntityDataGroup.destroyEntityData[0].entityCollisionQueueConcurrent, }; JobHandle jobDependenciesHandles = JobHandle.CombineDependencies(fillCellJobHandleDictionary[entityTypeToCheck], fillCellJobHandleDictionary[entityTypeToCheckWith], jobDependencies); collisionDetectJobHandle = collisionDetectJob.Schedule(collisionDetectJob.entityArray.Length, MonoBehaviourECSBridge.Instance.GetJobBatchCount(collisionDetectJob.entityArray.Length), jobDependenciesHandles); } return(JobHandle.CombineDependencies(collisionDetectJobHandle, jobDependencies)); }
void CreateCellHashMap(EntityTypeData.EntityType entityType) { if (cellEntityTypeDictionary.ContainsKey(entityType)) { return; } switch (entityType) { case EntityTypeData.EntityType.Asteroid: case EntityTypeData.EntityType.EnemyShip: case EntityTypeData.EntityType.AllyShip: case EntityTypeData.EntityType.PlayerShip: cellEntityTypeDictionary.Add(entityType, new NativeMultiHashMap <int, HashMapData>(50000, Allocator.Persistent)); if (!cellSizeEntityDictionary.ContainsKey(entityType)) { cellSizeEntityDictionary.Add(entityType, collisionHashMapSmallCellSizes); } break; case EntityTypeData.EntityType.EnemyBolt: case EntityTypeData.EntityType.AllyBolt: case EntityTypeData.EntityType.PlayerBolt: cellEntityTypeDictionary.Add(entityType, new NativeMultiHashMap <int, HashMapData>(600000, Allocator.Persistent)); if (!cellSizeEntityDictionary.ContainsKey(entityType)) { cellSizeEntityDictionary.Add(entityType, collisionHashMapBigCellSizes); } break; case EntityTypeData.EntityType.EntityTypeCount: break; default: { Debug.LogError("Unknown entity type"); cellEntityTypeDictionary.Add(entityType, new NativeMultiHashMap <int, HashMapData>(50000, Allocator.Persistent)); if (!cellSizeEntityDictionary.ContainsKey(entityType)) { cellSizeEntityDictionary.Add(entityType, collisionHashMapBigCellSizes); } } break; } }
protected override void OnDestroyManager() { base.OnDestroyManager(); for (int cellDictionaryIndex = 0; cellDictionaryIndex < cellEntityTypeDictionaryArray.Length; cellDictionaryIndex++) { currentCellDictionary = cellDictionaryIndex; allClearCellsJobHandle.Complete(); for (int i = 0; i < (int)EntityTypeData.EntityType.EntityTypeCount; i++) { EntityTypeData.EntityType entityTypeToRemove = (EntityTypeData.EntityType)i; if (cellEntityTypeDictionary.ContainsKey(entityTypeToRemove)) { cellEntityTypeDictionary[entityTypeToRemove].Dispose(); } } } }