Example #1
0
        private void Update(List <Rect> updateAreas)
        {
            if (updateAreas.Count == 0 || _initializing)
            {
                return;
            }

            DateTime speedTest = DateTime.Now;

            _bitmap.Lock();

            foreach (var updateArea in updateAreas.Select(r => new Int32Rect((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height)))
            {
                Int32Rect safeRect = new Int32Rect(Math.Max(0, updateArea.X), Math.Max(0, updateArea.Y), updateArea.Width, updateArea.Height);

                if (safeRect.X + safeRect.Width > WorldRenderer.BITMAP_WIDTH)
                {
                    safeRect.Width -= WorldRenderer.BITMAP_WIDTH - (safeRect.X + safeRect.Width);
                }

                if (safeRect.Y + safeRect.Height > WorldRenderer.BITMAP_HEIGHT)
                {
                    safeRect.Height -= WorldRenderer.BITMAP_HEIGHT - (safeRect.Y + safeRect.Height);
                }

                Int32Rect sourceArea = new Int32Rect(0, 0, Math.Max(0, Math.Min(safeRect.Width, WorldRenderer.BITMAP_WIDTH)), Math.Max(0, Math.Min(safeRect.Height, WorldRenderer.BITMAP_HEIGHT)));

                _worldRenderer.Update(safeRect, withInteractionOverlay: ShowInteraction.IsChecked.Value);
                _bitmap.WritePixels(sourceArea, _worldRenderer.GetRectangle(safeRect), safeRect.Width * 4, safeRect.X, safeRect.Y);
                _bitmap.AddDirtyRect(safeRect);
            }

            _bitmap.Unlock();

            Console.WriteLine("Draw time " + (DateTime.Now - speedTest).TotalMilliseconds + " milliseconds.");
        }