Skip to content
Browse files

libxbmc: when headless, sleep to emulate ~60fps

This keeps cpu low when we don't have a GUI slowing us down.
  • Loading branch information...
1 parent b2a4e88 commit 78282960b37c3ca4bf137a579bfe54c023e77f43 theuni committed Jun 6, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 xbmc/XBApplicationEx.cpp
View
12 xbmc/XBApplicationEx.cpp
@@ -21,6 +21,7 @@
#include "system.h"
#include "XBApplicationEx.h"
#include "utils/log.h"
+#include "threads/SystemClock.h"
#ifdef HAS_PERFORMANCE_SAMPLE
#include "utils/PerformanceSample.h"
#else
@@ -75,6 +76,9 @@ INT CXBApplicationEx::Run(bool renderGUI)
BYTE processExceptionCount = 0;
BYTE frameMoveExceptionCount = 0;
BYTE renderExceptionCount = 0;
+ unsigned int lastFrameTime = 0;
+ unsigned int frameTime = 0;
+ const unsigned int noRenderFrameTime = 15; // Simulates ~66fps
#ifndef _DEBUG
const BYTE MAX_EXCEPTION_COUNT = 10;
@@ -93,6 +97,7 @@ INT CXBApplicationEx::Run(bool renderGUI)
try
{
#endif
+ lastFrameTime = XbmcThreads::SystemClockMillis();
Process();
//reset exception count
processExceptionCount = 0;
@@ -143,6 +148,13 @@ INT CXBApplicationEx::Run(bool renderGUI)
{
#endif
if (renderGUI && !m_bStop) Render();
+ else if (!renderGUI)
+ {
+ frameTime = XbmcThreads::SystemClockMillis() - lastFrameTime;
+ if(frameTime < noRenderFrameTime)
+ Sleep(noRenderFrameTime - frameTime);
+ }
+
//reset exception count
renderExceptionCount = 0;

0 comments on commit 7828296

Please sign in to comment.
Something went wrong with that request. Please try again.