Fix frame-rate display using times from previous playback

The average times weren't reset so the last draw time would be used
making the FPS seem low for the first ~10 or so frames.
The averages from the last time the playback operator ran were also
used which could be misleading although this was also limited to the
first 8 frames.

Resolve by freeing the ScreenFrameRateInfo on animation start/end.
This commit is contained in:
Campbell Barton 2023-08-25 17:01:18 +10:00
parent 2c587e31dd
commit 4c0ef81926
3 changed files with 14 additions and 1 deletions

View File

@ -453,6 +453,11 @@ void ED_scene_fps_average_accumulate(struct Scene *scene, const double ltime);
* \return True when #ScreenFrameRateInfo::fps_average should be used.
*/
bool ED_scene_fps_average_calc(const struct Scene *scene);
/**
* Clear run-time data for accumulating animation playback average times.
*/
void ED_scene_fps_average_clear(Scene *scene);
/**
* Toggle operator.
*/

View File

@ -1679,11 +1679,16 @@ ScrArea *ED_screen_temp_space_open(bContext *C,
return area;
}
void ED_scene_fps_average_clear(Scene *scene)
{
MEM_SAFE_FREE(scene->fps_info);
}
void ED_scene_fps_average_accumulate(Scene *scene, const double ltime)
{
if ((U.uiflag & USER_SHOW_FPS) == 0) {
/* Playback stopped or shouldn't be running. */
MEM_SAFE_FREE(scene->fps_info);
ED_scene_fps_average_clear(scene);
return;
}
@ -1744,6 +1749,7 @@ bool ED_scene_fps_average_calc(const Scene *scene)
tot++;
}
}
printf("TOTAL WAS: %d\n", tot);
if (tot) {
fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE;
fps = fps / tot;

View File

@ -4942,6 +4942,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
if (ED_screen_animation_playing(CTX_wm_manager(C))) {
/* stop playback now */
ED_screen_animation_timer(C, 0, 0, 0);
ED_scene_fps_average_clear(scene);
BKE_sound_stop_scene(scene_eval);
BKE_callback_exec_id_depsgraph(
@ -4963,6 +4964,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
}
ED_screen_animation_timer(C, screen->redraws_flag, sync, mode);
ED_scene_fps_average_clear(scene);
if (screen->animtimer) {
wmTimer *wt = screen->animtimer;