[CalcFPS] with limit FPS (old dow and up fps) - Source Mu - Mu Server Files
 

[CalcFPS] with limit FPS (old dow and up fps)

Publicado por Dakosmu, Abr 18, 2026, 05:20 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Dakosmu

[CalcFPS] with limit FPS (old dow and up fps)


void CalcFPS(float targetFPS, bool reset_FPS)
{
  static LARGE_INTEGER freq, lastLimit;
  static bool initQPC = false;

  if (!initQPC)
  {
      QueryPerformanceFrequency(&freq);
      QueryPerformanceCounter(&lastLimit);
      initQPC = true;
  }

  DWORD nowTime = timeGetTime();

  static int timeinit = 0;
  static DWORD last;

  static float smoothFPS = 0.0f;

  if (reset_FPS) timeinit = 0;

  if (!timeinit)
  {
      last = nowTime;
      timeinit = 1;
  }

  WorldTime = (float)nowTime;

  float deltaMs = (float)(nowTime - last);
  DeltaT = deltaMs * 0.001f;
  if (DeltaT < 0.0001f) DeltaT = 0.0001f;
  if (DeltaT > 0.05f) DeltaT = 0.05f;

  last = nowTime;
  float instantFPS = 1.0f / DeltaT;
  smoothFPS = smoothFPS * 0.9f + instantFPS * 0.1f;

  FPS = smoothFPS;

  smoothDelta = smoothDelta * 0.9f + DeltaT * 0.1f;

  LARGE_INTEGER nowQPC;
  QueryPerformanceCounter(&nowQPC);

  double elapsed = (double)(nowQPC.QuadPart - lastLimit.QuadPart) / freq.QuadPart;

  if (elapsed < (1.0 / targetFPS))
  {
      CheckFPSLimit_41 = false;
      return;
  }

  lastLimit = nowQPC;
  CheckFPSLimit_41 = true;
}

Creditos BDCAM
Bon Dia

🡱 🡳
Real Time Web Analytics