2.5: Animation playback without sync option was slightly slower
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 21 Aug 2009 16:28:49 +0000 (16:28 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 21 Aug 2009 16:28:49 +0000 (16:28 +0000)
than expected time, even when it could keep up. Changed the WM
timer logic a bit to always target the next frame time exactly,

source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_window.c

index c400b6c9b203ca2b5e1cda642e3a64e21b5a10f3..42ee6e926fc2aff0b44e6953f161f6dcb8f649d6 100644 (file)
@@ -283,6 +283,8 @@ typedef struct wmTimer {
        double delta;                   /* time since previous step in seconds */
        
        double ltime;                   /* internal, last time timer was activated */
+       double ntime;                   /* internal, next time we want to activate the timer */
+       double stime;                   /* internal, when the timer started */
        int sleep;                              /* internal, put timers to sleep when needed */
 } wmTimer;
 
index d6bde9a468c0d580a62f1d0a1a69aa2ec00422c6..27a1b076a2853fe2ec03ca8b956a01d76935e353 100644 (file)
@@ -26,6 +26,7 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -690,12 +691,13 @@ static int wm_window_timer(const bContext *C)
                wmTimer *wt;
                for(wt= win->timers.first; wt; wt= wt->next) {
                        if(wt->sleep==0) {
-                               if(wt->timestep < time - wt->ltime) {
+                               if(time > wt->ntime) {
                                        wmEvent event= *(win->eventstate);
                                        
                                        wt->delta= time - wt->ltime;
                                        wt->duration += wt->delta;
                                        wt->ltime= time;
+                                       wt->ntime= wt->stime + wt->timestep*ceil(wt->duration/wt->timestep);
                                        
                                        event.type= wt->event_type;
                                        event.custom= EVT_DATA_TIMER;
@@ -790,6 +792,8 @@ wmTimer *WM_event_add_window_timer(wmWindow *win, int event_type, double timeste
        
        wt->event_type= event_type;
        wt->ltime= PIL_check_seconds_timer();
+       wt->ntime= wt->ltime + timestep;
+       wt->stime= wt->ltime;
        wt->timestep= timestep;
        
        BLI_addtail(&win->timers, wt);