Author: toshok
Date: 2007-09-26 13:19:08 -0400 (Wed, 26 Sep 2007)
New Revision: 86420
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/clock.cpp
trunk/moon/src/clock.h
Log:
2007-09-26 Chris Toshok <[EMAIL PROTECTED]>
* clock.h, clock.cpp: add some very naive, rather lame fps tuning.
we just adjust fps by a fixed amount (4fps) either up or down, if
a certain number (5, by default) of ticks in a row take either
less or more time to complete (respectively), than the current
timeout.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-09-26 17:08:47 UTC (rev 86419)
+++ trunk/moon/src/ChangeLog 2007-09-26 17:19:08 UTC (rev 86420)
@@ -1,3 +1,11 @@
+2007-09-26 Chris Toshok <[EMAIL PROTECTED]>
+
+ * clock.h, clock.cpp: add some very naive, rather lame fps tuning.
+ we just adjust fps by a fixed amount (4fps) either up or down, if
+ a certain number (5, by default) of ticks in a row take either
+ less or more time to complete (respectively), than the current
+ timeout.
+
2007-09-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* moon-path.c: Fix typos.
Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp 2007-09-26 17:08:47 UTC (rev 86419)
+++ trunk/moon/src/clock.cpp 2007-09-26 17:19:08 UTC (rev 86420)
@@ -38,9 +38,11 @@
#endif
+#define MINIMUM_FPS 10
#define DEFAULT_FPS 30
#define FPS_TO_DELAY(fps) (int)(((double)1/(fps)) * 1000)
+#define DELAY_TO_FPS(delay) (1000.0 / delay)
typedef struct {
void (*func)(gpointer);
@@ -82,14 +84,7 @@
void
TimeManager::SetMaximumRefreshRate (int hz)
{
- if (current_timeout == FPS_TO_DELAY (hz))
- return;
-
- current_timeout = FPS_TO_DELAY (hz);
- if (tick_id != -1) {
- RemoveTimeout ();
- AddTimeout ();
- }
+ min_timeout = FPS_TO_DELAY (hz);
}
void
@@ -166,10 +161,13 @@
}
}
+int strikes = 0;
+
void
TimeManager::Tick ()
{
STARTTICKTIMER (tick, "TimeManager::Tick");
+ TimeSpan pre_tick = get_now();
if (flags & TIME_MANAGER_UPDATE_CLOCKS) {
STARTTICKTIMER (tick_update_clocks, "TimeManager::Tick -
UpdateClocks");
current_global_time = get_now ();
@@ -219,6 +217,47 @@
}
ENDTICKTIMER (tick, "TimeManager::Tick");
+ TimeSpan post_tick = get_now();
+
+ if (post_tick - pre_tick > (TimeSpan)(current_timeout * 10000))
+ strikes ++;
+ else
+ strikes --;
+
+#define STRIKE_COUNT 5
+#define FPS_ADJUSTMENT 4
+
+ if (strikes > STRIKE_COUNT || strikes < -STRIKE_COUNT) {
+ int new_timeout;
+
+ if (strikes > STRIKE_COUNT) {
+ /* it took us longer than our current_timeout to run
through
+ the clock update/render loop. we need to scale back
our
+ timeout (lower fps) */
+ new_timeout = current_timeout + FPS_TO_DELAY
(FPS_ADJUSTMENT);
+ }
+ else if (strikes < -STRIKE_COUNT) {
+ /* it took us less time than our
+ current_timeout to run through the clock
+ update/render loop. let's make the timeout
+ less (higher fps). */
+ new_timeout = current_timeout - FPS_TO_DELAY
(FPS_ADJUSTMENT);
+ }
+
+ strikes = 0;
+
+ if (new_timeout < min_timeout)
+ new_timeout = min_timeout;
+ else if (new_timeout > FPS_TO_DELAY (MINIMUM_FPS))
+ new_timeout = FPS_TO_DELAY (MINIMUM_FPS);
+
+ if (new_timeout != current_timeout) {
+ current_timeout = new_timeout;
+ RemoveTimeout();
+ AddTimeout();
+ printf ("new timeout is %dms (%.2ffps)\n",
current_timeout, DELAY_TO_FPS (current_timeout));
+ }
+ }
}
void
Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h 2007-09-26 17:08:47 UTC (rev 86419)
+++ trunk/moon/src/clock.h 2007-09-26 17:19:08 UTC (rev 86420)
@@ -218,6 +218,8 @@
static gboolean tick_timeout (gpointer data);
gint tick_id;
int current_timeout;
+ int min_timeout; /* corresponds to maximum FPS, as set by the monitor's
refresh rate */
+ int strikes; /* used by our lame fps tuning code */
enum TimeManagerOp {
TIME_MANAGER_UPDATE_CLOCKS = 0x01,
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches