internal void RenderFrame(bool shouldSleep = false)
{
long end = System.Diagnostics.Stopwatch.GetTimestamp();
double seconds = (double)(end - frameCalcStart) / (double)System.Diagnostics.Stopwatch.Frequency;
if (seconds >= 1.0f)
{
frameCalcStart = end;
CurrentFPS = frameCounter;
frameCounter = 0;
}
long now = System.Diagnostics.Stopwatch.GetTimestamp();
// Delta time in seconds since the last rendering pass
double delta = (double)(now - frameRenderStartTime) / (double)System.Diagnostics.Stopwatch.Frequency;
if (maxFPS >= -1)
{
// Check maxFPS delay
double minDelta = 1.0 / (double)maxFPS;
if (delta < minDelta)
{
if (shouldSleep)
{
Thread.Sleep(1);
}
return;
}
}
frameRenderStartTime = System.Diagnostics.Stopwatch.GetTimestamp();
Performance.Push("RenderManager.Draw");
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
// Apply update before rendering (adding new rendering proxies,
// updating existing proxies)
ApplyPreFrame(delta);
// Render all active proxies in rendering passes
RenderRenderPasses();
// Render the UI
RenderUI();
Performance.Pop();
frameCounter++;
// Don't fry the CPU
Thread.Sleep(1);
}