Example #1
0
 /// <summary>
 /// Updates the screen by writing to the standard output.
 /// </summary>
 /// <param name="screen">The frame to draw</param>
 private void update(TFrame screen)
 {
     if (!f.IsInvalid)
     {
         int y, x;
         //generate the buffer
         for (int i = 0; i < buf.Length; ++i)
         {
             y = (int)i / Width;
             x = i % Width;
             buf[i].Attributes       = (short)((int)screen.forground[y][x] | (((int)screen.background[y][x]) << 4));
             buf[i].Char.UnicodeChar = screen.image[y][x];
         }
         //push it.
         bool b = WriteConsoleOutput(this.f, buf,
                                     new Coord()
         {
             X = (short)Width, Y = (short)Height
         },
                                     new Coord()
         {
             X = 0, Y = 0
         },
                                     ref rect);
         frame_Counter++;
     }
     else
     {
         Console.SetCursorPosition(0, 0);
         Console.WriteLine("Console output handel is invalid");
     }
 }
Example #2
0
        /// <summary>
        /// Initilises the Virtual screen.
        /// </summary>
        /// <param name="w">width of the screen</param>
        /// <param name="h">height of the screen</param>
        public Graphics(int w, int h)
        {
            // Initilisation=================================
            Console.SetWindowSize(w, h);
            Console.CursorVisible = false;
            currentFrame          = new TFrame(w, h);
            frameQueue            = new Queue <TFrame>();
            buf  = new CharInfo[w * h];
            rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = (short)w, Bottom = (short)h
            };
            this.f = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            Height         = h;
            Width          = w;
            maxQueueLength = 3;
            //thread creation================================
            ThreadStart fpsth = new ThreadStart(updateFps);

            updateFpsThread = new Thread(fpsth);
            updateFpsThread.IsBackground = true;
            updateFpsThread.Start();

            ThreadStart thref = new ThreadStart(FrameUpdater);

            updateThread = new Thread(thref);
            updateThread.IsBackground = true;
            updateThread.Start();
        }
Example #3
0
 /// <summary>
 /// Queues up the current frame.
 /// </summary>
 public void pushFrame()
 {
     if (frameQueue.Count < maxQueueLength)
     {
         frameQueue.Enqueue(currentFrame);
         currentFrame = new TFrame(Width, Height);
     }
     Thread.Sleep(FrameTime);
 }
Example #4
0
 internal void Draw(TFrame frame, int x, int y, ConsoleColor alphaKey = ConsoleColor.Black)
 {
     for (int i = 0; i < frame.image[0].Length; i++)
     {
         for (int j = 0; j < frame.image.Length; j++)
         {
             if (frame.image[j][i] != '\0')
             {
                 Draw(frame.image[j][i], frame.forground[j][i], x + i, y + j);
             }
             if (frame.background[j][i] != alphaKey)
             {
                 DrawBackground(frame.background[j][i], x + i, y + j);
             }
         }
     }
 }