diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-05-01 18:51:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-05-01 18:51:06 +0400 |
commit | 09e102fd01ae45ca7cd47cda8f788f0b5b1ce588 (patch) | |
tree | db22c724ebfb2335862f8591d022a4b8b9b6eeef /source/blender/src/drawview.c | |
parent | 6613ac0d88a957ce787ad927037c6e7e5700946c (diff) |
[#8397] "playback fps' jumps all over the map
average over the last 8 times to reduce flickering. ideally this would show how many frames were drawn in the last second. but I think this is good enough just to get an idea how fast the animation is playing without annoying flicker.
Diffstat (limited to 'source/blender/src/drawview.c')
-rw-r--r-- | source/blender/src/drawview.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index d97701e8c1e..b0d25636cf2 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -3394,8 +3394,12 @@ static double swaptime; static int curmode; /* used for fps display */ +#define REDRAW_FRAME_AVERAGE 8 static double redrawtime; static double lredrawtime; +static float redrawtimes_fps[REDRAW_FRAME_AVERAGE]; +static short redrawtime_index; + int update_time(void) { @@ -3418,13 +3422,32 @@ static void draw_viewport_fps(ScrArea *sa) { float fps; char printable[16]; - + int i, tot; if (lredrawtime == redrawtime) return; printable[0] = '\0'; - fps = (float)(1.0/(lredrawtime-redrawtime)); + +#if 0 + /* this is too simple, better do an average */ + fps = (float)(1.0/(lredrawtime-redrawtime)) +#else + redrawtimes_fps[redrawtime_index] = (float)(1.0/(lredrawtime-redrawtime)); + + for (i=0, tot=0, fps=0.0f ; i < REDRAW_FRAME_AVERAGE ; i++) { + if (redrawtimes_fps[i]) { + fps += redrawtimes_fps[i]; + tot++; + } + } + + redrawtime_index++; + if (redrawtime_index >= REDRAW_FRAME_AVERAGE) + redrawtime_index = 0; + + fps = fps / tot; +#endif /* is this more then half a frame behind? */ if (fps+0.5 < FPS) { @@ -3549,6 +3572,12 @@ void inner_play_anim_loop(int init, int mode) cached = cached_dynamics(PSFRA,PEFRA); redrawtime = 1.0/FPS; + + redrawtime_index = REDRAW_FRAME_AVERAGE; + while(redrawtime_index--) { + redrawtimes_fps[redrawtime_index] = 0.0; + } + lredrawtime = 0.0; return; } |