[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17998] branches/blender2.5/blender/source /blender: 2.5

Ton Roosendaal ton at blender.org
Mon Dec 22 09:54:01 CET 2008


Hi,

Yep, ghost has very bad timer code... it just only handles 1 timer step  
per 'do events', and when it falls behind it doesn't skip, and will  
loop badly. The ghost timer code is also different per platform :(

I'll ditch ghost timers, will make own reliable system in blender event  
system. :)

-Ton-

------------------------------------------------------------------------
Ton Roosendaal  Blender Foundation   ton at blender.org    www.blender.org
Blender Institute BV  Entrepotdok 57A  1018AD Amsterdam The Netherlands

On 22 Dec, 2008, at 0:08, Joshua Leung wrote:

> Hi,
>
> Here on Windows, the while loop is quite dangerous (there are reasons  
> why I almost always avoid them like the plague!), as if the mouse  
> moves out of the window and moves back in, all events are swallowed  
> and Blender freezes. Perhaps this will need a more elegant solution...
>
> Regards,
> Joshua
>
> On Mon, Dec 22, 2008 at 8:58 AM, Ton Roosendaal <ton at blender.org>  
> wrote:
>>
>>           
>>  http://projects.blender.org/plugins/scmsvn/viewcvs.php? 
>> view=rev&root=bf-blender&revision=17998
>>  Author:   ton
>>  Date:     2008-12-21 20:58:25 +0100 (Sun, 21 Dec 2008)
>>
>>  Log Message:
>>  -----------
>>  2.5
>>
>>  Animated screen! (unfinished, now only draws, no animation code yet).
>>  Fun though to see it all work. :)
>>
>>  NOTE: Mac ghost has timer bug, the GHOST_ProcessEvents() doesnt wake
>>  up for timers.
>>
>>  NOTE2: Added while loop in wm_window_process_events() to force Ghost
>>  giving all events to Blender. Timers otherwise don't accumulate...
>>  might be needed to fix in ghost too.
>>
>>  I tend to think to code own timer, this ghost stuff is totally  
>> different
>>  per platform.
>>
>>  Modified Paths:
>>  --------------
>>     
>>  branches/blender2.5/blender/source/blender/editors/include/ 
>> ED_screen.h
>>     
>>  branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_edit.c
>>     
>>  branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_ops.c
>>     
>>  branches/blender2.5/blender/source/blender/editors/space_time/ 
>> time_header.c
>>     
>>  branches/blender2.5/blender/source/blender/makesdna/ 
>> DNA_windowmanager_types.h
>>     
>>  branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_event_system.c
>>     
>>  branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_window.c
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/editors/include/ 
>> ED_screen.h
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/editors/include/ 
>> ED_screen.h      2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/editors/include/ 
>> ED_screen.h      2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -74,6 +74,7 @@
>>   bScreen *ED_screen_duplicate(struct wmWindow *win, struct bScreen  
>> *sc);
>>   void   ED_screen_set_subwinactive(struct wmWindow *win, struct  
>> wmEvent *event);
>>   void   ED_screen_exit(struct bContext *C, struct wmWindow *window,  
>> struct bScreen *screen);
>>  +void   ED_animation_timer(struct wmWindow *win, int enable);
>>
>>   void   ED_operatortypes_screen(void);
>>   void   ED_keymap_screen(struct wmWindowManager *wm);
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_edit.c
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_edit.c     2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_edit.c     2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -29,6 +29,7 @@
>>   #include "MEM_guardedalloc.h"
>>
>>   #include "DNA_vec_types.h"
>>  +#include "DNA_scene_types.h"
>>
>>   #include "BLI_blenlib.h"
>>
>>  @@ -1263,3 +1264,14 @@
>>
>>   }
>>
>>  +void ED_animation_timer(wmWindow *win, int enable)
>>  +{
>>  +
>>  +       if(win->animtimer)
>>  +               WM_event_remove_window_timer(win, win->animtimer);
>>  +       win->animtimer= NULL;
>>  +
>>  +       if(enable)
>>  +               win->animtimer= WM_event_add_window_timer(win,  
>> (int)(1000/FPS), (int)(1000/FPS));
>>  +}
>>  +
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_ops.c
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_ops.c      2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/editors/screen/ 
>> screen_ops.c      2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -1310,7 +1310,6 @@
>>
>>   void ED_SCR_OT_region_flip(wmOperatorType *ot)
>>   {
>>  -
>>         /* identifiers */
>>         ot->name= "Flip Region";
>>         ot->idname= "ED_SCR_OT_region_flip";
>>  @@ -1322,7 +1321,39 @@
>>         ot->poll= ED_operator_areaactive;
>>   }
>>
>>  +/* ****************** anim player, typically with timer  
>> ***************** */
>>
>>  +static int screen_animation_play(bContext *C, wmOperator *op,  
>> wmEvent *event)
>>  +{
>>  +       wmWindow *win= CTX_wm_window(C);
>>  +
>>  +       if(win->animtimer==event->customdata) {
>>  +               Scene *scene= CTX_data_scene(C);
>>  +
>>  +               scene->r.cfra++;
>>  +               if(scene->r.cfra > scene->r.efra)
>>  +                       scene->r.cfra= scene->r.sfra;
>>  +
>>  +               WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0,  
>> NULL);
>>  +
>>  +               return OPERATOR_FINISHED;
>>  +       }
>>  +       return OPERATOR_PASS_THROUGH;
>>  +}
>>  +
>>  +void ED_SCR_OT_animation_play(wmOperatorType *ot)
>>  +{
>>  +       /* identifiers */
>>  +       ot->name= "Animation player";
>>  +       ot->idname= "ED_SCR_OT_animation_play";
>>  +
>>  +       /* api callbacks */
>>  +       ot->invoke= screen_animation_play;
>>  +
>>  +       ot->poll= ED_operator_screenactive;
>>  +
>>  +}
>>  +
>>   /* ************** border select operator (template)  
>> ***************************** */
>>
>>   /* operator state vars used: (added by default WM callbacks)
>>  @@ -1402,7 +1433,8 @@
>>
>>         /*frame changes*/
>>         WM_operatortype_append(ED_SCR_OT_frame_offset);
>>  -
>>  +       WM_operatortype_append(ED_SCR_OT_animation_play);
>>  +
>>         /* tools shared by more space types */
>>         ED_marker_operatortypes();
>>
>>  @@ -1430,6 +1462,7 @@
>>         RNA_enum_set(WM_keymap_add_item(keymap,  
>> "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "dir",  
>> 'v');
>>
>>         /*frame offsets*/
>>  +       WM_keymap_add_item(keymap, "ED_SCR_OT_animation_play",  
>> TIMER, KM_ANY, 0, 0);
>>         RNA_int_set(WM_keymap_add_item(keymap,  
>> "ED_SCR_OT_frame_offset", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "delta",  
>> 10);
>>         RNA_int_set(WM_keymap_add_item(keymap,  
>> "ED_SCR_OT_frame_offset", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr,  
>> "delta", -10);
>>         RNA_int_set(WM_keymap_add_item(keymap,  
>> "ED_SCR_OT_frame_offset", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr,  
>> "delta", -1);
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/editors/space_time/ 
>> time_header.c
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/editors/space_time/ 
>> time_header.c 2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/editors/space_time/ 
>> time_header.c 2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -337,24 +337,7 @@
>>         return block;
>>   }
>>
>>  -static void start_animated_screen(SpaceTime *stime)
>>  -{
>>  -       // XXX  add_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM,  
>> stime->redraws);
>>  -
>>  -       //      if(stime->redraws & TIME_WITH_SEQ_AUDIO)
>>  -       //              audiostream_start( CFRA );
>>  -
>>  -       //      BKE_ptcache_set_continue_physics((stime->redraws &  
>> TIME_CONTINUE_PHYSICS));
>>  -}
>>
>>  -static void end_animated_screen(SpaceTime *stime)
>>  -{
>>  -       //      rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
>>  -
>>  -       //      audiostream_stop();
>>  -       //      BKE_ptcache_set_continue_physics(0);
>>  -}
>>  -
>>   #define B_REDRAWALL            750
>>   #define B_TL_REW               751
>>   #define B_TL_PLAY              752
>>  @@ -374,7 +357,7 @@
>>
>>   void do_time_buttons(bContext *C, void *arg, int event)
>>   {
>>  -       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
>>  +//     SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
>>         Scene *scene= CTX_data_scene(C);
>>
>>         switch(event) {
>>  @@ -386,10 +369,10 @@
>>                         //update_for_newframe();
>>                         break;
>>                 case B_TL_PLAY:
>>  -                       start_animated_screen(stime);
>>  +                       ED_animation_timer(CTX_wm_window(C), 1);
>>                         break;
>>                 case B_TL_STOP:
>>  -                       end_animated_screen(stime);
>>  +                       ED_animation_timer(CTX_wm_window(C), 0);
>>                         WM_event_add_notifier(C,  
>> WM_NOTE_WINDOW_REDRAW, 0, NULL);
>>                         break;
>>                 case B_TL_FF:
>>  @@ -524,10 +507,10 @@
>>                                  xco, yco, XIC, YIC, 0, 0, 0, 0, 0,  
>> "Skip to previous keyframe (Ctrl PageDown)");
>>         xco+= XIC+4;
>>
>>  -//     if(has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
>>  -//             uiDefIconBut(block, BUT, B_TL_STOP, ICON_PAUSE,
>>  -//                                      xco, 0, XIC, YIC, 0, 0, 0,  
>> 0, 0, "Stop Playing Timeline");
>>  -//     else
>>  +       if(CTX_wm_window(C)->animtimer)
>>  +               uiDefIconBut(block, BUT, B_TL_STOP, ICON_PAUSE,
>>  +                                        xco, yco, XIC, YIC, 0, 0,  
>> 0, 0, 0, "Stop Playing Timeline");
>>  +       else
>>                 uiDefIconBut(block, BUT, B_TL_PLAY, ICON_PLAY,
>>                                          xco, yco, XIC, YIC, 0, 0, 0,  
>> 0, 0, "Play Timeline ");
>>
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/makesdna/ 
>> DNA_windowmanager_types.h
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/makesdna/ 
>> DNA_windowmanager_types.h       2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/makesdna/ 
>> DNA_windowmanager_types.h       2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -47,6 +47,7 @@
>>   struct bScreen;
>>   struct uiBlock;
>>   struct wmSubWindow;
>>  +struct wmTimerHandle;
>>   struct StructRNA;
>>   struct PointerRNA;
>>
>>  @@ -93,6 +94,8 @@
>>
>>         struct wmSubWindow *curswin;    /* internal for  
>> wm_subwindow.c only */
>>
>>  +       struct wmTimerHandle *animtimer;
>>  +
>>         ListBase queue;                         /* all events (ghost  
>> level events were handled) */
>>         ListBase handlers;                      /* window+screen  
>> handlers, overriding all queues */
>>
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_event_system.c
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_event_system.c   2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_event_system.c   2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -675,7 +675,7 @@
>>                         CTX_wm_area_set(C, area_event_inside(C,  
>> event));
>>                         CTX_wm_region_set(C, region_event_inside(C,  
>> event));
>>
>>  -                       /* MVC demands to not draw in event  
>> handlers... for now we leave it */
>>  +                       /* MVC demands to not draw in event  
>> handlers... but we need to leave it for ogl selecting etc */
>>                         wm_window_make_drawable(C, win);
>>
>>                         action= wm_handlers_do(C, event,  
>> &win->handlers);
>>
>>  Modified:  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_window.c
>>  ===================================================================
>>  ---  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_window.c 2008-12-21 19:40:47 UTC (rev 17997)
>>  +++  
>> branches/blender2.5/blender/source/blender/windowmanager/intern/ 
>> wm_window.c 2008-12-21 19:58:25 UTC (rev 17998)
>>  @@ -498,8 +498,21 @@
>>
>>   void wm_window_process_events(int wait_for_event)
>>   {
>>  -       GHOST_ProcessEvents(g_system, wait_for_event);
>>  -       GHOST_DispatchEvents(g_system);
>>  +       int handled= 0;
>>  +
>>  +       /* ghost only processes 1 (timer?) event a time... we want  
>> to accumulate all */
>>  +       while(1) {
>>  +               if(GHOST_ProcessEvents(g_system, 0)) {
>>  +                       GHOST_DispatchEvents(g_system);
>>  +                       handled= 1;
>>  +               }
>>  +               else
>>  +                       break;
>>  +       }
>>  +       if(handled==0 && wait_for_event) {
>>  +               GHOST_ProcessEvents(g_system, wait_for_event);
>>  +               GHOST_DispatchEvents(g_system);
>>  +       }
>>   }
>>
>>   /* **************** init ********************** */
>>
>>
>>  _______________________________________________
>>  Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers



More information about the Bf-committers mailing list