QUINTIX

fake_vsync

Nov 16th, 2017
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2.  
  3. //make vertical white bar(s) across an 80x50 console
  4. void vbar(CHAR_INFO buff[4000], int pos){
  5.     if (pos < 0 || pos > 79) {return;}
  6.     const CHAR_INFO white = { ' ', BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY };
  7.     const CHAR_INFO black = { ' ', 0 };
  8.    
  9.     for (int i = 0; i < 80; i++)    {   buff[i] = black;}
  10.     buff[pos] = white;
  11.     buff[(pos + 1) % 80] = white;
  12.     buff[(pos + 3) % 80] = white;
  13.     buff[(pos + 5) % 80] = white;
  14.  
  15.     CHAR_INFO* firstLine = buff;
  16.     for (CHAR_INFO* curLine = &buff[80]; curLine < &buff[80 * 49 + 1]; curLine += 80)
  17.     {   memcpy_s((void*)curLine, sizeof(CHAR_INFO) * 80, (void*)firstLine, sizeof(CHAR_INFO)*80);}
  18. }
  19.  
  20. int _tmain(int argc, _TCHAR* argv[]){
  21.     HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE);
  22.     CHAR_INFO buff[80 * 50];
  23.  
  24.     SetConsoleScreenBufferSize(hdl, { 80, 50 });
  25.     SMALL_RECT recv = { 0, 0, 80, 50 };
  26.  
  27.     DWORD oldTime = GetTickCount();
  28.     int pos = 0;
  29.     SHORT yPos = 0;
  30.     bool done = false;
  31.  
  32.     while (!done){
  33.         CONST DWORD newTime = GetTickCount();
  34.  
  35.         if (newTime != oldTime)
  36.         {   vbar(buff, pos);
  37.             DWORD diffTime = newTime - oldTime;
  38.             oldTime = newTime;
  39.             pos = (pos + 1) % 80;
  40.             WriteConsoleOutput(hdl, buff, { 80, 50 }, { 5, 0 }, &recv);
  41.            
  42.             yPos = (yPos + 1) % 50;
  43.             printf_s("%04d", diffTime);
  44.             SetConsoleCursorPosition(hdl, { 75, yPos });
  45.         }
  46.  
  47.         if (_kbhit())
  48.             {done = (_getch() == 27);}
  49.     }
  50.  
  51.     return 0;
  52. }
RAW Paste Data