private void OnServerTick100ms(float dt) { accum += dt; if (updateSnowLayerQueue.Count > 5 || (accum > 1 && updateSnowLayerQueue.Count > 0)) { accum = 0; int cnt = 0; int max = 10; UpdateSnowLayerChunk[] q = new UpdateSnowLayerChunk[max]; lock (updateSnowLayerQueueLock) { while (updateSnowLayerQueue.Count > 0) { q[cnt] = updateSnowLayerQueue.Dequeue(); cnt++; if (cnt >= max) { break; } } } for (int i = 0; i < cnt; i++) { processBlockUpdates(q[i].Coords, q[i], ba); } ba.Commit(); } }
private bool TryImmediateSnowUpdate(WeatherSimulationRegion simregion, IServerMapChunk mc, Vec2i chunkCoord, IWorldChunk[] chunksCol) { UpdateSnowLayerChunk dummy = new UpdateSnowLayerChunk() { Coords = chunkCoord }; lock (updateSnowLayerQueue) { if (updateSnowLayerQueue.Contains(dummy)) { return(false); } } double nowTotalHours = ws.api.World.Calendar.TotalHours; if (nowTotalHours - simregion.LastUpdateTotalHours > 1) // Lets wait until WeatherSimulationRegion is done updating { return(false); } UpdateSnowLayerChunk ch = GetSnowUpdate(simregion, mc, chunkCoord, chunksCol); if (ch == null) { return(true); // The only path returning null, if we provided a full set of chunksCol, will be where newCount == 0 } if (ch.SetBlocks.Count == 0) { return(true); } cuba.SetChunks(chunkCoord, chunksCol); processBlockUpdates(mc, ch, cuba); cuba.Commit(); lock (updateSnowLayerQueue) { updateSnowLayerQueue.Enqueue(dummy); } return(true); }
private void OnServerTick100ms(float dt) { accum += dt; if (updateSnowLayerQueue.Count > 5 || (accum > 1 && updateSnowLayerQueue.Count > 0)) { accum = 0; int cnt = 0; int max = 10; UpdateSnowLayerChunk[] q = new UpdateSnowLayerChunk[max]; lock (updateSnowLayerQueue) { while (updateSnowLayerQueue.Count > 0) { q[cnt] = updateSnowLayerQueue.Dequeue(); cnt++; if (cnt >= max) { break; } } } for (int i = 0; i < cnt; i++) { IMapChunk mc = sapi.WorldManager.GetMapChunk(q[i].Coords.X, q[i].Coords.Y); if (mc == null) { continue; // No longer loaded, we can just ditch it and re-do the thing again next time it gets loaded again } processBlockUpdates(mc, q[i], ba); } ba.Commit(); } }