Exemplo n.º 1
0
        //public void PutChar(int _Col, int _Row, byte _Char)
        //{
        //    var charIdx = _Row * cRowSize + _Col;
        //    _videoRam[charIdx] = _Char;

        //    if (_allInvalid) return;

        //    lock (_invalidCharPositions)
        //    {
        //        if (!_allInvalid)
        //        {
        //            if (_invalidCharPositions.Count >= cInvalidLimit)
        //            {
        //                _allInvalid = true;
        //                _invalidCharPositions.Clear();
        //            }
        //            else
        //                _invalidCharPositions.Add(hCharIdx);
        //        }
        //    }
        //}

        public void UpdateScreen()
        {
            WritePixelsInfo[] writePixelsInfos;

            Monitor.Enter(_invalidCharPositions);
            if (_allInvalid)
            {
                _allInvalid = false;
                _invalidCharPositions.Clear();
                Monitor.Exit(_invalidCharPositions);

                writePixelsInfos = new WritePixelsInfo[RowCount * ColCount];
                Parallel.For(
                    0,
                    RowCount,
                    row =>
                {
                    for (var col = 0; col < ColCount; col++)
                    {
                        var info = PrepareDrawChar(col, row);
                        if (info != null)
                        {
                            writePixelsInfos[row * ColCount + col] = info;
                        }
                    }
                });
            }
            else
            {
                var charIndices = _invalidCharPositions.ToArray();
                _invalidCharPositions.Clear();
                Monitor.Exit(_invalidCharPositions);

                writePixelsInfos = new WritePixelsInfo[charIndices.Length];

                Parallel.For(
                    0,
                    charIndices.Length,
                    idx =>
                {
                    var charIdx = charIndices[idx];
                    var info    = PrepareDrawChar(charIdx % RowSize, charIdx / RowSize);
                    if (info != null)
                    {
                        writePixelsInfos[idx] = info;
                    }
                });
            }

            foreach (var info in writePixelsInfos.Where(pixelInfo => pixelInfo != null))
            {
                _screen.WritePixels(info.Rect, info.Pixels, info.Stride, 0);
            }
        }
Exemplo n.º 2
0
        //public void PutChar(int _Col, int _Row, byte _Char)
        //{
        //    var hCharIdx = _Row * cRowSize + _Col;
        //    _videoRam[hCharIdx] = _Char;
        //    if (FAllInvalid) return;
        //    lock (FInvalidCharPositions)
        //    {
        //        if (!FAllInvalid)
        //        {
        //            if (FInvalidCharPositions.Count >= cInvalidLimit)
        //            {
        //                FAllInvalid = true;
        //                FInvalidCharPositions.Clear();
        //            }
        //            else
        //                FInvalidCharPositions.Add(hCharIdx);
        //        }
        //    }
        //}
        public void UpdateScreen()
        {
            WritePixelsInfo[] hWritePixelsInfos;

            Monitor.Enter(_invalidCharPositions);
            if (_allInvalid)
            {
                _allInvalid = false;
                _invalidCharPositions.Clear();
                Monitor.Exit(_invalidCharPositions);

                hWritePixelsInfos = new WritePixelsInfo[RowCount * ColCount];
                Parallel.For(
                    0,
                    RowCount,
                    row =>
                    {
                        for (var hCol = 0; hCol < ColCount; hCol++)
                        {
                            var hWritePixelsInfo = PrepareDrawChar(hCol, row);
                            if (hWritePixelsInfo != null)
                                hWritePixelsInfos[row * ColCount + hCol] = hWritePixelsInfo;
                        }
                    });
            }
            else
            {
                var hCharIndices = _invalidCharPositions.ToArray();
                _invalidCharPositions.Clear();
                Monitor.Exit(_invalidCharPositions);

                hWritePixelsInfos = new WritePixelsInfo[hCharIndices.Length];

                Parallel.For(
                    0,
                    hCharIndices.Length,
                    idx =>
                    {
                        var hCharIdx = hCharIndices[idx];
                        var hWritePixelsInfo = PrepareDrawChar(hCharIdx % RowSize, hCharIdx / RowSize);
                        if (hWritePixelsInfo != null)
                            hWritePixelsInfos[idx] = hWritePixelsInfo;
                    });

            }

            foreach (var hWritePixelsInfo in hWritePixelsInfos.Where(pixelInfo => pixelInfo != null))
                _screen.WritePixels(hWritePixelsInfo.Rect, hWritePixelsInfo.Pixels, hWritePixelsInfo.Stride, 0);
        }