BGE fix: 3DDview not redrawing when exiting BGE
[blender.git] / source / blender / editors / space_view3d / view3d_view.c
index a569eff1ebe155e7de7825a18087c056633e6df4..bbf728d31c00773b5c6d5eb594bd4124f08b70cd 100644 (file)
@@ -297,7 +297,7 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
                        if(rv3d->smooth_timer)
                                WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rv3d->smooth_timer);
                        /* TIMER1 is hardcoded in keymap */
-                       rv3d->smooth_timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/30.0);  /* max 30 frs/sec */
+                       rv3d->smooth_timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/100.0); /* max 30 frs/sec */
                        
                        return;
                }
@@ -395,6 +395,7 @@ void VIEW3D_OT_smoothview(wmOperatorType *ot)
 static void setcameratoview3d(View3D *v3d, RegionView3D *rv3d, Object *ob)
 {
        float dvec[3];
+       float mat3[3][3];
        
        dvec[0]= rv3d->dist*rv3d->viewinv[2][0];
        dvec[1]= rv3d->dist*rv3d->viewinv[2][1];
@@ -404,7 +405,10 @@ static void setcameratoview3d(View3D *v3d, RegionView3D *rv3d, Object *ob)
        sub_v3_v3v3(ob->loc, ob->loc, rv3d->ofs);
        rv3d->viewquat[0]= -rv3d->viewquat[0];
 
-       quat_to_eul( ob->rot,rv3d->viewquat);
+       // quat_to_eul( ob->rot,rv3d->viewquat); // in 2.4x for xyz eulers only
+       quat_to_mat3(mat3, rv3d->viewquat);
+       object_mat3_to_rot(ob, mat3, 0);
+
        rv3d->viewquat[0]= -rv3d->viewquat[0];
        
        ob->recalc= OB_RECALC_OB;
@@ -1709,6 +1713,7 @@ static int game_engine_exec(bContext *C, wmOperator *unused)
        Scene *startscene = CTX_data_scene(C);
        ScrArea *sa, *prevsa= CTX_wm_area(C);
        ARegion *ar, *prevar= CTX_wm_region(C);
+       wmWindow *prevwin= CTX_wm_window(C);
        RegionView3D *rv3d;
        rcti cam_frame;
 
@@ -1742,11 +1747,15 @@ static int game_engine_exec(bContext *C, wmOperator *unused)
 
 
        SaveState(C);
+
        StartKetsjiShell(C, ar, &cam_frame, 1);
-       RestoreState(C);
        
+       /* restore context, in case it changed in the meantime, for
+          example by working in another window or closing it */
        CTX_wm_region_set(C, prevar);
+       CTX_wm_window_set(C, prevwin);
        CTX_wm_area_set(C, prevsa);
+       RestoreState(C);
 
        //XXX restore_all_scene_cfra(scene_cfra_store);
        set_scene_bg(startscene);
@@ -1909,7 +1918,7 @@ typedef struct FlyInfo {
 #define FLY_CANCEL             1
 #define FLY_CONFIRM            2
 
-int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event)
+static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event)
 {
        float upvec[3]; // tmp
        float mat[3][3];
@@ -2036,7 +2045,7 @@ static int flyEnd(bContext *C, FlyInfo *fly)
        else if (fly->persp_backup==RV3D_CAMOB) {       /* camera */
                float mat3[3][3];
                copy_m3_m4(mat3, v3d->camera->obmat);
-               mat3_to_compatible_eul( v3d->camera->rot, fly->rot_backup,mat3);
+               object_mat3_to_rot(v3d->camera, mat3, TRUE);
 
                DAG_id_flush_update(&v3d->camera->id, OB_RECALC_OB);
 #if 0 //XXX2.5
@@ -2073,7 +2082,7 @@ static int flyEnd(bContext *C, FlyInfo *fly)
        return OPERATOR_CANCELLED;
 }
 
-void flyEvent(FlyInfo *fly, wmEvent *event)
+static void flyEvent(FlyInfo *fly, wmEvent *event)
 {
        if (event->type == TIMER && event->customdata == fly->timer) {
                fly->redraw = 1;
@@ -2196,7 +2205,7 @@ void flyEvent(FlyInfo *fly, wmEvent *event)
 }
 
 //int fly_exec(bContext *C, wmOperator *op)
-int flyApply(FlyInfo *fly)
+static int flyApply(FlyInfo *fly)
 {
        /*
        fly mode - Shift+F