private JobHandle ScheduleAutophagyJob(JobHandle dependency, CustomRuleSymbols customSymbols) { // autophagy is only dependent on the source string. don't need to register as dependent on native data/source symbols if (customSymbols.hasAutophagy) { var helperStack = new TmpNativeStack <AutophagyPostProcess.BranchIdentity>(10, Allocator.TempJob); var autophagicJob = new AutophagyPostProcess { symbols = target, lastIdentityStack = helperStack, customSymbols = customSymbols }; dependency = autophagicJob.Schedule(dependency); dependency = helperStack.Dispose(dependency); } return(dependency); }
public TurtleStringReadingCompletable( Mesh targetMesh, int totalSubmeshes, DependencyTracker <SymbolString <float> > symbols, DependencyTracker <NativeTurtleData> nativeData, int branchStartChar, int branchEndChar, TurtleState defaultState, CustomRuleSymbols customSymbols, TurtleVolumeWorldReferences volumetrics, Matrix4x4 localToWorldTransform) { this.targetMesh = targetMesh; this.nativeData = nativeData; UnityEngine.Profiling.Profiler.BeginSample("turtling job"); JobHandleWrapper volumetricJobHandle = currentJobHandle; var volumetricHandles = new TurtleVolumetricHandles { durabilityWriter = volumetrics.durabilityWriter.GetNextNativeWritableHandle(localToWorldTransform, ref volumetricJobHandle), universalWriter = volumetrics.universalLayerWriter.GetNextNativeWritableHandle(localToWorldTransform), volumetricData = volumetrics.world.NativeVolumeData.openReadData.AsReadOnly() }; currentJobHandle = volumetricJobHandle; UnityEngine.Profiling.Profiler.BeginSample("allocating"); var tmpHelperStack = new TmpNativeStack <TurtleState>(50, Allocator.TempJob); organInstances = new NativeList <TurtleOrganInstance>(100, Allocator.TempJob); newMeshSizeBySubmesh = new NativeArray <TurtleMeshAllocationCounter>(totalSubmeshes, Allocator.TempJob); UnityEngine.Profiling.Profiler.EndSample(); NativeArray <float> destructionCommandTimestamps; if (volumetrics.damageFlags != null) { destructionCommandTimestamps = volumetrics.damageFlags.GetDestructionCommandTimestampsReadOnly(); } else { destructionCommandTimestamps = new NativeArray <float>(0, Allocator.TempJob); } var entitySpawningSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); var entitySpawnBuffer = entitySpawningSystem.CreateCommandBuffer(); var turtleCompileJob = new TurtleCompilationJob { symbols = symbols.Data, operationsByKey = nativeData.Data.operationsByKey, organData = nativeData.Data.allOrganData, organInstances = organInstances, newMeshSizeBySubmesh = newMeshSizeBySubmesh, spawnEntityBuffer = entitySpawnBuffer, nativeTurtleStack = tmpHelperStack, branchStartChar = branchStartChar, branchEndChar = branchEndChar, currentState = defaultState, customRules = customSymbols, volumetricHandles = volumetricHandles, hasVolumetricDestruction = volumetrics.damageFlags != null, volumetricDestructionTimestamps = destructionCommandTimestamps, earliestValidDestructionCommand = volumetrics.damageFlags != null ? Time.time - volumetrics.damageFlags.timeCommandStaysActive : -1 }; currentJobHandle = turtleCompileJob.Schedule(currentJobHandle); volumetrics.world.NativeVolumeData.RegisterReadingDependency(currentJobHandle); entitySpawningSystem.AddJobHandleForProducer(currentJobHandle); volumetrics.damageFlags?.RegisterReaderOfDestructionFlags(currentJobHandle); volumetrics.durabilityWriter.RegisterWriteDependency(currentJobHandle); volumetrics.universalLayerWriter.RegisterWriteDependency(currentJobHandle); nativeData.RegisterDependencyOnData(currentJobHandle); symbols.RegisterDependencyOnData(currentJobHandle); currentJobHandle = tmpHelperStack.Dispose(currentJobHandle); if (volumetrics.damageFlags == null) { currentJobHandle = destructionCommandTimestamps.Dispose(currentJobHandle); } UnityEngine.Profiling.Profiler.EndSample(); }