public void Enqueue(BlockCoordinates coordinates) { /* if (!Queue.Contains(coordinates)) * { * Queue.Enqueue(coordinates);*/ ChunkQueues.AddOrUpdate((ChunkCoordinates)coordinates, chunkCoordinates => { var newQueue = new ConcurrentQueue <BlockCoordinates>(); newQueue.Enqueue(coordinates); return(newQueue); }, (chunkCoordinates, queue) => { if (!queue.Contains(coordinates)) { queue.Enqueue(coordinates); } return(queue); }); // } }
public bool HasEnqueued(ChunkCoordinates coordinates) { if (ChunkQueues.TryGetValue(coordinates, out var queue)) { return(!queue.IsEmpty); } return(false); }
private void Test(World level, BlockCoordinates sourceBlock, BlockCoordinates target, ConcurrentQueue <BlockCoordinates> lightBfsQueue, int lightLevel) { var chunkCoord = new ChunkCoordinates(sourceBlock); //Interlocked.Add(ref touches, 1); bool isOtherChunk = false; var newChunkCoord = (ChunkCoordinates)target; if (chunkCoord.X != newChunkCoord.X || chunkCoord.Z != newChunkCoord.Z) { //chunk = GetChunk(level, newCoord); lightBfsQueue = ChunkQueues.GetOrAdd(newChunkCoord, coordinates => new ConcurrentQueue <BlockCoordinates>()); isOtherChunk = true; } if (isOtherChunk && !World.TryGetBlockLight(target, out _)) { lightBfsQueue.Enqueue(target); /*Queue.Enqueue((newCoord, () => * { * if (ChunkQueues.TryGetValue((ChunkCoordinates) newCoord, out var queue)) * { * if (!level.TryGetBlockLight(coord, out var ll)) * { * return false; * } * //var cc = GetChunk(level, newCoord); * //if (cc == null) * // return false; * //var ll = level.GetBlockLight(coord); * * DoPass(level, newCoord, queue, ll); * * Enqueue(coord); * Enqueue(newCoord); * return true; * } * return false; * }));*/ return; } DoPass(level, target, lightBfsQueue, lightLevel); }
public void Recalculate(ChunkColumn chunk) { ChunkQueues.TryRemove(new ChunkCoordinates(chunk.X, chunk.Z), out _); // var lightSources = chunk.GetLightSources().ToArray(); foreach (var section in chunk.Sections) { section?.ResetLight(true, false); section?.RemoveInvalidBlocks(); } var chunkpos = new BlockCoordinates(chunk.X << 4, 0, chunk.Z << 4); foreach (var lightsource in chunk.GetLightSources().OrderByDescending(x => x.Y)) { Enqueue(chunkpos + lightsource); } //chunk.GetLightSources() }
public bool Process(ChunkCoordinates coordinates) { int count = 0; if (ChunkQueues.TryGetValue(coordinates, out var queue)) { while (queue.TryDequeue(out var coords) && !CancellationToken.IsCancellationRequested) { ProcessNode(World, coords, queue); count++; } if (queue.IsEmpty) { ChunkQueues.TryRemove(coordinates, out _); } } return(count > 0); }
public void Clear() { ChunkQueues.Clear(); // Queue.Clear(); }
public void Remove(ChunkCoordinates coordinates) { ChunkQueues.TryRemove(coordinates, out _); }
/// <inheritdoc /> public void Dispose() { //Queue.Clear(); ChunkQueues.Clear(); }