private void createJob() { if (_waitingQueue.Count == 0 || _processingList.Count >= 16) { return; } Chunk chunk = _waitingQueue.Dequeue(); ChunkData data = new ChunkData { chunk = chunk, chunkPos = new int2(chunk.chunkPos.x, chunk.chunkPos.y), blocks = new NativeArray <byte>(65536, Allocator.Persistent), vertices = new NativeList <float3>(Allocator.Persistent), uvs = new NativeList <float2>(Allocator.Persistent), triangles = new NativeList <int>(Allocator.Persistent) }; ChunkJob job = new ChunkJob { chunkPos = data.chunkPos, blocks = data.blocks, vertices = data.vertices, uvs = data.uvs, triangles = data.triangles }; data.handle = job.Schedule(); _processingList.Add(data); }
/// <summary> /// Attempt to queue a job for this chunk /// </summary> public bool QueueJob(ChunkJob Job, byte Priority) { WorldManager manager = WorldManager.Main; if (manager == null) { return(false); } // Check for any duplicates already in active jobs if (Job.bPreventDuplicates) { lock (mActiveJobs) { // Only allow to add, if no other job of type exists, or if that job has already started if (mActiveJobs.Exists(j => j != null && !j.bHasStarted && Job.Equals(j))) { return(false); } } } mActiveJobs.Add(Job); manager.mWorker.Enqueue(Job, Priority); return(true); }
/// <summary> /// Schedules a single loading job based on the chunks to load. /// </summary> private void queueLoadingJobs() { // No need to try and process chunks if there are none. if (chunksToLoad.Count == 0) { return; } // Create and set load info. var noiseSize = noiseSettings.size + 1; var size = noiseSize * noiseSize * noiseSize; for (int index = 0; index < chunksToLoad.Count; index++) { // Create ChunkJob. var chunkJob = new ChunkJob { location = chunksToLoad[index], chunkInfo = new ChunkInfo { meshData = new NativeList <float3>(Allocator.TempJob), volumeData = new NativeArray <float>(size, Allocator.TempJob, NativeArrayOptions.UninitializedMemory) }, noiseSettings = noiseSettings }; // Add to waiting jobs. mWaitingJobs.Add(chunkJob); } }
private async Task DownloadChunkAsync(ChunkJob chunkJob, CancellationToken cancellationToken) { var server = await _serverPool.GetServerAsync(cancellationToken).ConfigureAwait(false); var token = await _serverPool.AuthenticateWithServerAsync(DepotId, server).ConfigureAwait(false); CDNClient.DepotChunk chunkData = default; try { chunkData = await _serverPool.CdnClient.DownloadDepotChunkAsync( DepotId, chunkJob.InternalChunk, server, token, _depotKey, proxyServer : _serverPool.DesignatedProxyServer).ConfigureAwait(false); if (chunkData.Data.Length != chunkJob.Chunk.CompressedLength && chunkData.Data.Length != chunkJob.Chunk.UncompressedLength) { throw new InvalidDataException("Chunk data was not the expected length."); } _serverPool.ReturnServer(server, isFaulty: false); } catch { _serverPool.ReturnServer(server, isFaulty: true); throw; } await chunkJob.FileWriter.WriteAsync(chunkData.ChunkInfo.Offset, chunkData.Data); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { _queue.Clear(); var ha = new ChunkJob { cq = _queue.ToConcurrent() }.Schedule(query, inputDeps); _waitHandle = ha; return(_waitHandle); }
/// <summary> /// Attempt to queue up a job with a given priority /// </summary> public void Enqueue(ChunkJob Job, byte Priority) { if (Priority > MAX_PRIORITY) { Priority = MAX_PRIORITY; } lock (PendingJobs) PendingJobs.Enqueue(new JobInfo(Job, Priority)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { _map.Clear(); var ha = new ChunkJob { indexMod = 0, cmap = _map.ToConcurrent() }.Schedule(query_A, inputDeps); var hb = new ChunkJob { indexMod = 1000, cmap = _map.ToConcurrent() }.Schedule(query_B, ha); _waitHandle = hb; return(_waitHandle); }
/// <summary> /// Execute job and add to completed jobs, if successful /// </summary> private void AttemptJob(ChunkJob Job) { // Has already aborted if (Job.bIsAborted) { return; } Job.bHasStarted = true; Job.Execute(); // Was aborted during execution if (Job.bIsAborted) { return; } // Was successful, so add to completed job list lock (CompletedJobs) CompletedJobs.Enqueue(Job); }
public JobInfo(ChunkJob Job, byte Priority) { this.Job = Job; this.PriorityIndex = Priority; }
/// <summary> /// Are these 2 jobs the same (Used when preventing duplicates) /// </summary> public virtual bool Equals(ChunkJob Other) { return(GetType() == Other.GetType()); }
/// <summary> /// Called when a job is finished /// </summary> public void OnFinishJob(ChunkJob Job) { lock (mActiveJobs) mActiveJobs.Remove(Job); }
/// <summary> /// Sets the next job to run. /// </summary> private void runNextJob() { mRunningChunkJob = mWaitingJobs[0]; mChunkJobHandle = mRunningChunkJob.Schedule(); mWaitingJobs.RemoveAt(0); }