[#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.
This commit is contained in:
Campbell Barton
2008-05-01 14:51:06 +00:00
parent 6613ac0d88
commit 09e102fd01

View File

@@ -3394,8 +3394,12 @@ static double swaptime;
static int curmode; static int curmode;
/* used for fps display */ /* used for fps display */
#define REDRAW_FRAME_AVERAGE 8
static double redrawtime; static double redrawtime;
static double lredrawtime; static double lredrawtime;
static float redrawtimes_fps[REDRAW_FRAME_AVERAGE];
static short redrawtime_index;
int update_time(void) int update_time(void)
{ {
@@ -3418,13 +3422,32 @@ static void draw_viewport_fps(ScrArea *sa)
{ {
float fps; float fps;
char printable[16]; char printable[16];
int i, tot;
if (lredrawtime == redrawtime) if (lredrawtime == redrawtime)
return; return;
printable[0] = '\0'; 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? */ /* is this more then half a frame behind? */
if (fps+0.5 < FPS) { if (fps+0.5 < FPS) {
@@ -3549,6 +3572,12 @@ void inner_play_anim_loop(int init, int mode)
cached = cached_dynamics(PSFRA,PEFRA); cached = cached_dynamics(PSFRA,PEFRA);
redrawtime = 1.0/FPS; redrawtime = 1.0/FPS;
redrawtime_index = REDRAW_FRAME_AVERAGE;
while(redrawtime_index--) {
redrawtimes_fps[redrawtime_index] = 0.0;
}
lredrawtime = 0.0; lredrawtime = 0.0;
return; return;
} }