fCraft.Map.ProcessDrawOps C# (CSharp) Method

ProcessDrawOps() private method

private ProcessDrawOps ( int maxTotalUpdates ) : int
maxTotalUpdates int
return int
        private int ProcessDrawOps( int maxTotalUpdates )
        {
            if ( World == null )
                throw new InvalidOperationException( "No world assigned" );
            int blocksDrawnTotal = 0;
            for ( int i = 0; i < drawOps.Count; i++ ) {
                DrawOperation op = drawOps[i];

                // remove a cancelled drawOp from the list
                if ( op.IsCancelled ) {
                    op.End();
                    drawOps.RemoveAt( i );
                    i--;
                    continue;
                }

                // draw a batch of blocks
                int blocksToDraw = maxTotalUpdates / ( drawOps.Count - i );
                op.StartBatch();
            #if DEBUG
                int blocksDrawn = op.DrawBatch( blocksToDraw );
            #else
                int blocksDrawn;
                try {
                    blocksDrawn = op.DrawBatch( blocksToDraw );
                } catch ( Exception ex ) {
                    Logger.LogAndReportCrash( "DrawOp error", "fCraft", ex, false );
                    op.Player.Message( "&WError occured in your draw command: {0}: {1}",
                                       ex.GetType().Name, ex.Message );
                    drawOps.RemoveAt( i );
                    op.End();
                    return blocksDrawnTotal;
                }
            #endif
                blocksDrawnTotal += blocksDrawn;
                if ( blocksDrawn > 0 ) {
                    HasChangedSinceSave = true;
                }
                maxTotalUpdates -= blocksDrawn;

                // remove a completed drawOp from the list
                if ( op.IsDone ) {
                    op.End();
                    drawOps.RemoveAt( i );
                    i--;
                }
            }
            return blocksDrawnTotal;
        }