Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate

Autor Topic: [Litmit FPS] set the fps limit old size  (Visto 128 veces)

SaintZeus and 1 Guest are viewing this topic.

Offline BDCAM Posteado: Today at 10:03:37 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 5
  • Gracias recibida: 5
  • vn

void LimitFPS(double targetFPS)
{
   static LARGE_INTEGER freq;
   static LARGE_INTEGER last;
   static bool init = false;

   if (!init)
   {
      QueryPerformanceFrequency(&freq);
      QueryPerformanceCounter(&last);
      timeBeginPeriod(1);
      SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
      init = true;
   }

   double frameTime = 1.0 / targetFPS;

   LARGE_INTEGER now;
   double elapsed;

   while (true)
   {
      QueryPerformanceCounter(&now);

      elapsed = (double)(now.QuadPart - last.QuadPart) / freq.QuadPart;

      if (elapsed >= frameTime) break;

      double remain = frameTime - elapsed;

      if (remain > 0.003)
      {
         DWORD ms = (DWORD)((remain - 0.001) * 1000);
         if (ms > 0) Sleep(ms);
      }
      else YieldProcessor();
   }

   QueryPerformanceCounter(&last);
   LimitFPS_Time = GetTickCount64();
}


Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate


 

Related Topics

  Subject / Started by Replies Last post
3 Replies
1893 Views
Last post May 13, 2020, 08:39:18 AM
by louis
6 Replies
2090 Views
Last post November 20, 2020, 08:45:36 PM
by Azzlaer
0 Replies
523 Views
Last post November 20, 2022, 06:52:10 AM
by usersa
2 Replies
5860 Views
Last post August 07, 2023, 12:17:11 AM
by Cheke
0 Replies
472 Views
Last post March 24, 2024, 06:28:46 PM
by Juninsj22