|
From: <ba...@us...> - 2006-06-06 03:51:56
|
Revision: 334 Author: bardtx Date: 2006-06-05 20:51:53 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/cadcdev/?rev=334&view=rev Log Message: ----------- tiki: Add (commented out) support for DC frame rate limiting Modified Paths: -------------- tiki/dc/src/platgl.cpp Modified: tiki/dc/src/platgl.cpp =================================================================== --- tiki/dc/src/platgl.cpp 2006-06-06 03:51:23 UTC (rev 333) +++ tiki/dc/src/platgl.cpp 2006-06-06 03:51:53 UTC (rev 334) @@ -15,6 +15,11 @@ using namespace Tiki; +static struct timeval lastFrame = { 0,0 }; +static int targetFrameRate = 60; +static uint64 firstFrame = 0; +static uint64 frameCnt = 0, totalFrameCnt = 0; + float Tiki::GL::Frame::getFrameRate() { pvr_stats_t stats; pvr_get_stats(&stats); @@ -22,12 +27,41 @@ } void Tiki::GL::Frame::setFrameRateLimit(int rate) { - (void)(rate); + targetFrameRate = rate; } extern "C" { void tiki_wait_if_needed() { +#if 0 + // Every so often we should reset the frame counters, to avoid + // having a super long term averaging effect. + if (frameCnt >= 500) { + firstFrame = 0; + frameCnt = 0; + } + + // Update frame counters. + if (!firstFrame) + firstFrame = Tiki::Time::gettime(); + frameCnt++; + totalFrameCnt++; + + if (lastFrame.tv_sec == 0) { + gettimeofday(&lastFrame, NULL); + return; + } + + struct timeval now; + gettimeofday(&now, NULL); + long long nowu = ((long long)now.tv_sec) * 1000 * 1000 + now.tv_usec; + long long lastu = ((long long)lastFrame.tv_sec) * 1000 * 1000 + lastFrame.tv_usec; + long long diffu = nowu - lastu; + if (diffu < (1000*1000 / targetFrameRate)) { + Time::sleep((1000*1000 / targetFrameRate) - diffu); + } + gettimeofday(&lastFrame, NULL); +#endif pvr_wait_ready(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |