Merging r58701 through r58746 from trunk into soc-2013-depsgraph_mt
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 30 Jul 2013 19:05:29 +0000 (19:05 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 30 Jul 2013 19:05:29 +0000 (19:05 +0000)
71 files changed:
doc/python_api/rst/bge.render.rst
intern/cycles/blender/blender_mesh.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/bvh/bvh.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_types.h
intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_IWindow.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_Window.h
intern/ghost/intern/GHOST_WindowWin32.cpp
intern/ghost/intern/GHOST_WindowWin32.h
intern/ghost/intern/GHOST_WindowX11.cpp
intern/ghost/intern/GHOST_WindowX11.h
release/scripts/startup/bl_ui/properties_game.py
release/scripts/startup/bl_ui/space_view3d.py
release/scripts/templates_py/custom_nodes.py
source/blender/blenkernel/intern/key.c
source/blender/blenlib/BLI_math_matrix.h
source/blender/blenlib/BLI_math_vector.h
source/blender/blenlib/intern/math_matrix.c
source/blender/blenlib/intern/math_vector_inline.c
source/blender/bmesh/intern/bmesh_interp.c
source/blender/bmesh/intern/bmesh_polygon.c
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/intern/bmesh_queries.h
source/blender/bmesh/operators/bmo_connect_nonplanar.c
source/blender/bmesh/operators/bmo_connect_pair.c
source/blender/bmesh/operators/bmo_inset.c
source/blender/bmesh/operators/bmo_utils.c
source/blender/collada/ArmatureImporter.cpp
source/blender/collada/DocumentImporter.cpp
source/blender/collada/SkinInfo.cpp
source/blender/collada/TransformReader.cpp
source/blender/collada/collada_internal.cpp
source/blender/collada/collada_internal.h
source/blender/collada/collada_utils.cpp
source/blender/collada/collada_utils.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/render/render_preview.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_node/node_select.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_outliner/outliner_edit.c
source/blender/editors/space_outliner/outliner_intern.h
source/blender/editors/space_outliner/outliner_tree.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/editors/transform/transform_conversions.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_scene.c
source/blender/nodes/shader/nodes/node_shader_math.c
source/blender/nodes/texture/nodes/node_texture_output.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm_window.h
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
source/gameengine/BlenderRoutines/KX_BlenderGL.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
source/gameengine/GamePlayer/ghost/GPG_Canvas.h
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Rasterizer/RAS_ICanvas.h

index c3bcf19c01b2a9e4b5bf0aa5d4cefd7125d35145..5a80b7fa5c1c55c231916a98db75b5210660f7df 100644 (file)
@@ -62,6 +62,18 @@ Constants
 .. data:: KX_BLENDER_GLSL_MATERIAL
 
    Materials approximating blender materials with GLSL.
+   
+.. DATA:: VSYNC_OFF
+
+   Disables vsync
+
+.. DATA:: VSYNC_ON
+
+   Enables vsync
+
+.. DATA:: VSYNC_ADAPTIVE
+
+   Enables adaptive vsync if supported. Adaptive vsync enables vsync if the framerate is above the monitors refresh rate. Otherwise, vsync is diabled if the framerate is too low.
 
 *********
 Functions
@@ -289,3 +301,15 @@ Functions
 
    Disable the motion blur effect.
 
+.. function:: setVsync(value)
+
+   Set the vsync value
+
+   :arg value: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE
+   :type value: integer
+
+.. function:: getVsync()
+
+   Get the current vsync value
+
+   :rtype: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE
index 9fa9e1267565a910be0462022003b8e0b1be1357..55282a1ec00b36705085d52eb7adced8d066a0dd 100644 (file)
@@ -462,7 +462,6 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tri
        mesh_synced.insert(mesh);
 
        /* create derived mesh */
-       bool need_undeformed = mesh->need_attribute(scene, ATTR_STD_GENERATED);
        PointerRNA cmesh = RNA_pointer_get(&b_ob_data.ptr, "cycles");
 
        vector<Mesh::Triangle> oldtriangle = mesh->triangles;
@@ -479,6 +478,7 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tri
                if(preview)
                        b_ob.update_from_editmode();
 
+               bool need_undeformed = mesh->need_attribute(scene, ATTR_STD_GENERATED);
                BL::Mesh b_mesh = object_to_mesh(b_data, b_ob, b_scene, true, !preview, need_undeformed);
 
                if(b_mesh) {
index 86bdbc0749f572ca3667eb4772ec3945ac36ab2b..3a46897fcac673284c71289aac12a7fd602cf205 100644 (file)
@@ -279,6 +279,11 @@ void BlenderSession::do_write_update_render_tile(RenderTile& rtile, bool do_upda
 
        BL::RenderResult::layers_iterator b_single_rlay;
        b_rr.layers.begin(b_single_rlay);
+
+       /* layer will be missing if it was disabled in the UI */
+       if(b_single_rlay == b_rr.layers.end())
+               return;
+
        BL::RenderLayer b_rlay = *b_single_rlay;
 
        if (do_update_only) {
index 00c146143b84b8acd64ee827520441a0031e9256..f2c96638b8454d817beb80b26a336080f304bef6 100644 (file)
@@ -46,7 +46,7 @@ class Progress;
 
 struct PackedBVH {
        /* BVH nodes storage, one node is 4x int4, and contains two bounding boxes,
-        * and child, triangle or object indexes dependening on the node type */
+        * and child, triangle or object indexes depending on the node type */
        array<int4> nodes; 
        /* object index to BVH node index mapping for instances */
        array<int> object_node; 
index 6e1843df50d6ccbf6ed9c39529331cbe4aa01565..0ef255786fa66c534e39ae0258b8dab68abc5701 100644 (file)
@@ -925,10 +925,7 @@ __device_noinline void kernel_path_non_progressive_lighting(KernelGlobals *kg, R
                        path_radiance_bsdf_bounce(L, &tp, &bsdf_eval, bsdf_pdf, state.bounce, label);
 
                        /* set labels */
-                       float min_ray_pdf = FLT_MAX;
-
-                       if(!(label & LABEL_TRANSPARENT))
-                               min_ray_pdf = fminf(bsdf_pdf, min_ray_pdf);
+                       float min_ray_pdf = fminf(bsdf_pdf, FLT_MAX);
 
                        /* modify path state */
                        PathState ps = state;
index 3bd0d5c3561250177a759b21a82d953482a52674..38ababa96bdbb4c5e45f67ab99c1722e21dad188 100644 (file)
@@ -436,7 +436,7 @@ typedef enum AttributeStandard {
 
 /* Closure data */
 
-#define MAX_CLOSURE 16
+#define MAX_CLOSURE 64
 
 typedef struct ShaderClosure {
        ClosureType type;
index a92d0d33b652ede9c4b0a017bc7d7f9fed4091fc..aae90179be5cd74365ddb8500316d6e760b139cd 100644 (file)
@@ -665,6 +665,19 @@ extern GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle,
  */
 extern GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle);
 
+/**
+ * Sets the swap interval for swapBuffers.
+ * \param interval The swap interval to use.
+ * \return A boolean success indicator.
+ */
+extern GHOST_TSuccess GHOST_SetSwapInterval(GHOST_WindowHandle windowhandle, int interval);
+
+/**
+ * Gets the current swap interval for swapBuffers.
+ * \return An integer.
+ */
+extern int GHOST_GetSwapInterval(GHOST_WindowHandle windowhandle);
+
 /**
  * Activates the drawing context of this window.
  * \param windowhandle The handle to the window
index a2d3e9b91fbb884822450548a0a888c605d865b8..355770752634dd00a7317886825c9ff8973327d4 100644 (file)
@@ -204,6 +204,19 @@ public:
         */
        virtual GHOST_TSuccess swapBuffers() = 0;
 
+       /**
+        * Sets the swap interval for swapBuffers.
+        * \param interval The swap interval to use.
+        * \return A boolean success indicator.
+        */
+       virtual GHOST_TSuccess setSwapInterval(int interval) = 0;
+
+       /**
+        * Gets the current swap interval for swapBuffers.
+        * \return An integer.
+        */
+       virtual int getSwapInterval() = 0;
+
        /**
         * Activates the drawing context of this window.
         * \return  A boolean success indicator.
index b73ff26c259918cacec4e31ba31fd4e46259aa67..8d4498ed759b11951bed50a4790f611857b7f665 100644 (file)
@@ -691,6 +691,19 @@ GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
        return window->swapBuffers();
 }
 
+GHOST_TSuccess GHOST_SetSwapInterval(GHOST_WindowHandle windowhandle, int interval)
+{
+       GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
+
+       return window->setSwapInterval(interval);
+}
+
+int GHOST_GetSwapInterval(GHOST_WindowHandle windowhandle)
+{
+       GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
+
+       return window->getSwapInterval();
+}
 
 
 GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
index 588de0911e302576c7d616d3cc06ec162e175146..77ee4db8543e487e26ff672c9ce4f840ee8362ac 100644 (file)
@@ -67,6 +67,8 @@ public:
         * virtual GHOST_TWindowOrder getOrder(void) = 0;
         * virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
         * virtual GHOST_TSuccess swapBuffers() = 0;
+        * virtual GHOST_TSuccess setSwapInterval() = 0;
+        * virtual int getSwapInterval() = 0;
         * virtual GHOST_TSuccess activateDrawingContext() = 0;
         * virtual GHOST_TSuccess invalidate() = 0;
         */
@@ -110,6 +112,8 @@ public:
         * virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0;
         * virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
         * virtual GHOST_TSuccess swapBuffers() = 0;
+        * virtual GHOST_TSuccess setSwapInterval() = 0;
+        * virtual int getSwapInterval() = 0;
         * virtual GHOST_TSuccess activateDrawingContext() = 0;
         * virtual GHOST_TSuccess invalidate() = 0;
         */
@@ -204,6 +208,23 @@ public:
                return GHOST_kFailure;
        }
        
+       /**
+        * Sets the swap interval for swapBuffers.
+        * \param interval The swap interval to use.
+        * \return A boolean success indicator.
+        */
+       virtual GHOST_TSuccess setSwapInterval(int interval) {
+               return GHOST_kFailure;
+       }
+       
+       /**
+        * Gets the current swap interval for swapBuffers.
+        * \return An integer.
+        */
+       virtual int getSwapInterval() {
+               return 0;
+       }
+       
        /**
         * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
         */
index b0d0b1a5b5dbed78e68a17d5cef4cf38eea4e437..c264686fbb152a96ada6fd8cee5c82c29bfd86d5 100644 (file)
@@ -648,6 +648,20 @@ GHOST_TSuccess GHOST_WindowWin32::swapBuffers()
        return ::SwapBuffers(hDC) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
 }
 
+GHOST_TSuccess GHOST_WindowWin32::setSwapInterval(int interval)
+{
+       if (!WGL_EXT_swap_control)
+               return GHOST_kFailure;
+       return wglSwapIntervalEXT(interval) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
+}
+
+int GHOST_WindowWin32::getSwapInterval()
+{
+       if (WGL_EXT_swap_control)
+               return wglGetSwapIntervalEXT();
+
+       return 0;
+}
 
 GHOST_TSuccess GHOST_WindowWin32::activateDrawingContext()
 {
index 2fd1f5b37f4eb845f943a9b15415aed3a2449fd4..6fdc963f30ae8a1c1328b5f506ce661cc17ba0f1 100644 (file)
@@ -211,6 +211,19 @@ public:
         */
        virtual GHOST_TSuccess swapBuffers();
 
+       /**
+        * Sets the swap interval for swapBuffers.
+        * \param interval The swap interval to use.
+        * \return A boolean success indicator.
+        */
+       virtual GHOST_TSuccess setSwapInterval(int interval);
+
+       /**
+        * Gets the current swap interval for swapBuffers.
+        * \return An integer.
+        */
+       virtual int getSwapInterval();
+
        /**
         * Activates the drawing context of this window.
         * \return Indication of success.
index 25d7c181b68b0e0152914cbc4a27f061030c6e72..3173736c2a5b4410a1b6493a720a12c90d7788dc 100644 (file)
@@ -30,6 +30,8 @@
  */
 
 
+#include <GL/glxew.h>
+
 #include "GHOST_WindowX11.h"
 #include "GHOST_SystemX11.h"
 #include "STR_String.h"
@@ -1513,3 +1515,23 @@ endFullScreen() const
 
        return GHOST_kSuccess;
 }
+
+GHOST_TSuccess
+GHOST_WindowX11::
+setSwapInterval(int interval) {
+       if (!GLX_EXT_swap_control)
+               return GHOST_kFailure;
+       glXSwapIntervalEXT(m_display, m_window, interval);
+       return GHOST_kSuccess;
+}
+
+int
+GHOST_WindowX11::
+getSwapInterval() {
+       if (GLX_EXT_swap_control) {
+               unsigned int value;
+               glXQueryDrawable(m_display, m_window, GLX_SWAP_INTERVAL_EXT, &value);
+               return (int)value;
+       }
+       return 0;
+}
index b8471b41a111601dcb8b9cf54837be7cf31d8586..7cbdcdeec2188a1201784535ffe6e7b25e5eda7b 100644 (file)
@@ -235,6 +235,19 @@ public:
 
        GHOST_TSuccess endFullScreen() const;
 
+       /**
+        * Sets the swap interval for swapBuffers.
+        * \param interval The swap interval to use.
+        * \return A boolean success indicator.
+        */
+       virtual GHOST_TSuccess setSwapInterval(int interval);
+
+       /**
+        * Gets the current swap interval for swapBuffers.
+        * \return An integer.
+        */
+       virtual int getSwapInterval();
+
 protected:
        /**
         * Tries to install a rendering context in this window.
index 38e49853454abcd7cec178fc3e2e0727b59ef857..025d86204f21d3d30d272a2fdfca8f6aae9ad75f 100644 (file)
@@ -413,6 +413,9 @@ class RENDER_PT_game_system(RenderButtonsPanel, Panel):
         col.prop(gs, "use_display_lists")
         col.active = gs.raster_storage != 'VERTEX_BUFFER_OBJECT'
 
+        row = layout.row()
+        row.prop(gs, "vsync")
+
         row = layout.row()
         row.prop(gs, "raster_storage")
 
index 689b1a9c9b7290310968cc1d5e779944b376a27e..58eecc2641dd3a481f1b981cb9bff9c011e495bc 100644 (file)
@@ -1973,7 +1973,9 @@ class VIEW3D_MT_edit_mesh_edges(Menu):
 
     def draw(self, context):
         layout = self.layout
+
         with_freestyle = bpy.app.build_options.freestyle
+        scene = context.scene
 
         layout.operator_context = 'INVOKE_REGION_WIN'
 
@@ -1998,11 +2000,10 @@ class VIEW3D_MT_edit_mesh_edges(Menu):
 
         layout.separator()
 
-        if with_freestyle:
+        if with_freestyle and not scene.render.use_shading_nodes:
             layout.operator("mesh.mark_freestyle_edge").clear = False
             layout.operator("mesh.mark_freestyle_edge", text="Clear Freestyle Edge").clear = True
-
-        layout.separator()
+            layout.separator()
 
         layout.operator("mesh.edge_rotate", text="Rotate Edge CW").use_ccw = False
         layout.operator("mesh.edge_rotate", text="Rotate Edge CCW").use_ccw = True
@@ -2028,7 +2029,9 @@ class VIEW3D_MT_edit_mesh_faces(Menu):
 
     def draw(self, context):
         layout = self.layout
+
         with_freestyle = bpy.app.build_options.freestyle
+        scene = context.scene
 
         layout.operator_context = 'INVOKE_REGION_WIN'
 
@@ -2044,11 +2047,10 @@ class VIEW3D_MT_edit_mesh_faces(Menu):
 
         layout.separator()
 
-        if with_freestyle:
+        if with_freestyle and not scene.render.use_shading_nodes:
             layout.operator("mesh.mark_freestyle_face").clear = False
             layout.operator("mesh.mark_freestyle_face", text="Clear Freestyle Face").clear = True
-
-        layout.separator()
+            layout.separator()
 
         layout.operator("mesh.poke")
         layout.operator("mesh.quads_convert_to_tris")
@@ -2661,6 +2663,7 @@ class VIEW3D_PT_view3d_meshdisplay(Panel):
         with_freestyle = bpy.app.build_options.freestyle
 
         mesh = context.active_object.data
+        scene = context.scene
 
         split = layout.split()
 
@@ -2680,7 +2683,7 @@ class VIEW3D_PT_view3d_meshdisplay(Panel):
             col.prop(mesh, "show_edge_seams", text="Seams")
         col.prop(mesh, "show_edge_sharp", text="Sharp", text_ctxt=i18n_contexts.plural)
         col.prop(mesh, "show_edge_bevel_weight", text="Bevel")
-        if with_freestyle:
+        if with_freestyle and not scene.render.use_shading_nodes:
             col.prop(mesh, "show_freestyle_edge_marks", text="Edge Marks")
             col.prop(mesh, "show_freestyle_face_marks", text="Face Marks")
 
index d5bb71416c9fd00409908409a82bbef7d9bbe2be..5f002f3716176dcb355dbe532d67d5884ec9769d 100644 (file)
@@ -1,5 +1,5 @@
 import bpy
-from bpy_types import NodeTree, Node, NodeSocket
+from bpy.types import NodeTree, Node, NodeSocket
 
 # Implementation of custom nodes from Python
 
index a79fa3873f517dfbf0db92dfe62932e57e7b8c8b..5b8929e49fe7f77dd8770acb7be7baaef92f01ab 100644 (file)
@@ -533,7 +533,7 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
 
                        if (me->edit_btmesh && me->edit_btmesh->bm->totvert == kb->totelem) {
                                a = 0;
-                               co = MEM_callocN(sizeof(float) * 3 * me->edit_btmesh->bm->totvert, "key_block_get_data");
+                               co = MEM_mallocN(sizeof(float) * 3 * me->edit_btmesh->bm->totvert, "key_block_get_data");
 
                                BM_ITER_MESH (eve, &iter, me->edit_btmesh->bm, BM_VERTS_OF_MESH) {
                                        copy_v3_v3(co[a], eve->co);
@@ -1091,7 +1091,7 @@ static float *get_weights_array(Object *ob, char *vgroup)
                float *weights;
                int i;
                
-               weights = MEM_callocN(totvert * sizeof(float), "weights");
+               weights = MEM_mallocN(totvert * sizeof(float), "weights");
 
                if (em) {
                        const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
@@ -1622,7 +1622,7 @@ void BKE_key_convert_from_lattice(Lattice *lt, KeyBlock *kb)
 
        if (kb->data) MEM_freeN(kb->data);
 
-       kb->data = MEM_callocN(lt->key->elemsize * tot, "kb->data");
+       kb->data = MEM_mallocN(lt->key->elemsize * tot, "kb->data");
        kb->totelem = tot;
 
        bp = lt->def;
@@ -1664,7 +1664,7 @@ void BKE_key_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb)
 
        if (kb->data) MEM_freeN(kb->data);
 
-       kb->data = MEM_callocN(cu->key->elemsize * tot, "kb->data");
+       kb->data = MEM_mallocN(cu->key->elemsize * tot, "kb->data");
        kb->totelem = tot;
 
        nu = nurb->first;
@@ -1762,7 +1762,7 @@ void BKE_key_convert_from_mesh(Mesh *me, KeyBlock *kb)
 
        if (kb->data) MEM_freeN(kb->data);
 
-       kb->data = MEM_callocN(me->key->elemsize * me->totvert, "kb->data");
+       kb->data = MEM_mallocN(me->key->elemsize * me->totvert, "kb->data");
        kb->totelem = me->totvert;
 
        mvert = me->mvert;
@@ -1812,7 +1812,7 @@ float (*BKE_key_convert_to_vertcos(Object *ob, KeyBlock *kb))[3]
 
        if (tot == 0) return NULL;
 
-       vertCos = MEM_callocN(tot * sizeof(*vertCos), "BKE_key_convert_to_vertcos vertCos");
+       vertCos = MEM_mallocN(tot * sizeof(*vertCos), "BKE_key_convert_to_vertcos vertCos");
 
        /* Copy coords to array */
        co = (float *)vertCos;
@@ -1895,7 +1895,7 @@ void BKE_key_convert_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos)[3])
                return;
        }
 
-       fp = kb->data = MEM_callocN(tot * elemsize, "BKE_key_convert_to_vertcos vertCos");
+       fp = kb->data = MEM_mallocN(tot * elemsize, "BKE_key_convert_to_vertcos vertCos");
 
        /* Copy coords to keyblock */
 
index a4b0f449dc3242a62e2298d5d8ecee33c37b3102..c305cc9a0300a5f74308de0433afaf5aa8723f1d 100644 (file)
@@ -175,7 +175,7 @@ void mat4_to_size(float r[3], float M[4][4]);
 void translate_m4(float mat[4][4], float tx, float ty, float tz);
 void rotate_m4(float mat[4][4], const char axis, const float angle);
 void rotate_m2(float mat[2][2], const float angle);
-void pivot_m4(float mat[4][4], const float pivot[3]);
+void transform_pivot_set_m4(float mat[4][4], const float pivot[3]);
 
 void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);
 void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4]);
index 6be679a90b6200d74f53790a7c8a2810dd49b6a7..38b377c640e3e600de39cce8eae220e85a431af3 100644 (file)
@@ -116,9 +116,9 @@ MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]);
 MINLINE void mul_v4_fl(float r[4], float f);
 MINLINE void mul_v4_v4fl(float r[3], const float a[3], float f);
 MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]);
-MINLINE float mul_m3_v3_single_x(float M[3][3], const float a[3]);
-MINLINE float mul_m3_v3_single_y(float M[3][3], const float a[3]);
-MINLINE float mul_m3_v3_single_z(float M[3][3], const float a[3]);
+MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]);
+MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3]);
+MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]);
 
 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
index 8565698110e26fc6fe396431465ba9f9ab354d4e..99342c4d6dcb1a00ff971f5cb374aa3397758159 100644 (file)
@@ -1374,8 +1374,15 @@ void rotate_m2(float mat[2][2], const float angle)
        mat[1][0] = -mat[0][1];
 }
 
-/* scale or rotate around a non zero pivot */
-void pivot_m4(float mat[4][4], const float pivot[3])
+/**
+ * Scale or rotate around a pivot point,
+ * a convenience function to avoid having to do inline.
+ *
+ * Since its common to make a scale/rotation matrix that pivots around an arbitrary point.
+ *
+ * Typical use case is to make 3x3 matrix, copy to 4x4, then pass to this function.
+ */
+void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
 {
        float tmat[4][4];
 
index eff735ef8d53770ad55aa3935c1743918deacc61..8e5040d983b4fd84d4375c81f30ea352f54ea9cd 100644 (file)
@@ -418,15 +418,18 @@ MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3])
               (mat[2][3] * co[2]) + mat[3][3];
 }
 
-MINLINE float mul_m3_v3_single_x(float M[3][3], const float a[3])
+/**
+ * Has the effect of mul_m3_v3(), on a single axis.
+ */
+MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3])
 {
        return M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
 }
-MINLINE float mul_m3_v3_single_y(float M[3][3], const float a[3])
+MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3])
 {
        return M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
 }
-MINLINE float mul_m3_v3_single_z(float M[3][3], const float a[3])
+MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3])
 {
        return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
 }
index 3e8a49a01fcdf4e53b27226c0cd3fd6bc97f6c42..70d1d4c81dff8750c2fff09e323106922dcf9a5a 100644 (file)
@@ -205,6 +205,7 @@ void BM_face_interp_from_face(BMesh *bm, BMFace *target, BMFace *source, const b
        int i;
 
        /* convert the 3d coords into 2d for projection */
+       BLI_assert(BM_face_is_normal_valid(source));
        axis_dominant_v3_to_m3(axis_mat, source->no);
 
        i = 0;
@@ -638,6 +639,7 @@ void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source,
        int i;
 
        /* convert the 3d coords into 2d for projection */
+       BLI_assert(BM_face_is_normal_valid(source));
        axis_dominant_v3_to_m3(axis_mat, source->no);
 
        i = 0;
@@ -678,6 +680,7 @@ void BM_vert_interp_from_face(BMesh *bm, BMVert *v, BMFace *source)
        int i;
 
        /* convert the 3d coords into 2d for projection */
+       BLI_assert(BM_face_is_normal_valid(source));
        axis_dominant_v3_to_m3(axis_mat, source->no);
 
        i = 0;
index 297458eb1d698b925b51459544eb88c9a0906794..eea5ec596746c8dd493328290096f674e32ab0e4 100644 (file)
@@ -1006,6 +1006,8 @@ void BM_face_triangulate(BMesh *bm, BMFace *f,
        float *abscoss = BLI_array_alloca(abscoss, f_len_orig);
        float mat[3][3];
 
+       BLI_assert(BM_face_is_normal_valid(f));
+
        axis_dominant_v3_to_m3(mat, f->no);
 
        /* copy vertex coordinates to vertspace area */
@@ -1061,7 +1063,7 @@ void BM_face_legal_splits(BMFace *f, BMLoop *(*loops)[2], int len)
 {
        const int len2 = len * 2;
        BMLoop *l;
-       float v1[2], v2[2], v3[2] /*, v4[3 */, no[3], mid[2], *p1, *p2, *p3, *p4;
+       float v1[2], v2[2], v3[2], mid[2], *p1, *p2, *p3, *p4;
        float out[2] = {-FLT_MAX, -FLT_MAX};
        float axis_mat[3][3];
        float (*projverts)[2] = BLI_array_alloca(projverts, f->len);
@@ -1069,10 +1071,9 @@ void BM_face_legal_splits(BMFace *f, BMLoop *(*loops)[2], int len)
        float fac1 = 1.0000001f, fac2 = 0.9f; //9999f; //0.999f;
        int i, j, a = 0, clen;
 
-       /* TODO, the face normal may already be correct */
-       BM_face_calc_normal(f, no);
+       BLI_assert(BM_face_is_normal_valid(f));
 
-       axis_dominant_v3_to_m3(axis_mat, no);
+       axis_dominant_v3_to_m3(axis_mat, f->no);
 
        for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) {
                BM_elem_index_set(l, i); /* set_loop */
index de601b1905267bf12eb8c4726bd33ce2737023fb..0e2984c53cccd18d320c5b96a680dd1b5c5efa53 100644 (file)
@@ -1719,6 +1719,18 @@ bool BM_face_is_any_edge_flag_test(BMFace *f, const char hflag)
        return false;
 }
 
+/**
+ * Use within assert's to check normals are valid.
+ */
+bool BM_face_is_normal_valid(BMFace *f)
+{
+       const float eps = 0.0001f;
+       float no[3];
+
+       BM_face_calc_normal(f, no);
+       return len_squared_v3v3(no, f->no) < (eps * eps);
+}
+
 static void bm_mesh_calc_volume_face(BMFace *f, float *r_vol)
 {
        int tottri = f->len - 2;
index 23d89cf92faf41fa0f4cb33004e135aae2e8449c..151d1de9b5b5f3e68754f62eb3601b965cf83ef7 100644 (file)
@@ -116,6 +116,8 @@ bool BM_edge_is_any_vert_flag_test(BMEdge *e, const char hflag);
 bool BM_face_is_any_vert_flag_test(BMFace *f, const char hflag);
 bool BM_face_is_any_edge_flag_test(BMFace *f, const char hflag);
 
+bool BM_face_is_normal_valid(BMFace *f);
+
 float BM_mesh_calc_volume(BMesh *bm, bool is_signed);
 
 int   BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_index)[2],
index 74f42e73aab195c49da406117e87712f86e9fd98..6d30b327a6c8b81d3b1fbe70e40d12a9f2d9ff0b 100644 (file)
@@ -77,9 +77,9 @@ static float bm_face_subset_calc_planar(BMLoop *l_first, BMLoop *l_last, const f
 
        axis_dominant_v3_to_m3(axis_mat, no);
 
-       z_prev = mul_m3_v3_single_z(axis_mat, l_last->v->co);
+       z_prev = dot_m3_v3_row_z(axis_mat, l_last->v->co);
        do {
-               z_curr = mul_m3_v3_single_z(axis_mat, l_iter->v->co);
+               z_curr = dot_m3_v3_row_z(axis_mat, l_iter->v->co);
                delta_z += fabsf(z_curr - z_prev);
                z_prev = z_curr;
        } while ((l_iter = l_iter->next) != l_term);
@@ -214,6 +214,7 @@ void bmo_connect_verts_nonplanar_exec(BMesh *bm, BMOperator *op)
                if (bm_face_split_by_angle(bm, f, f_pair, angle_limit)) {
                        int j;
                        for (j = 0; j < 2; j++) {
+                               BM_face_normal_update(f_pair[j]);
                                if (f_pair[j]->len > 3) {
                                        STACK_PUSH(fstack, f_pair[j]);
                                }
index fb9ebe31c627e3f7d7f731b7d6a272d04853a250..0bc29c5625685db05111bcf4c0c327b3a8f78a56 100644 (file)
@@ -87,8 +87,8 @@ typedef struct PathLinkState {
 static int state_isect_co_pair(const PathContext *pc,
                                const float co_a[3], const float co_b[3])
 {
-       const float diff_a = mul_m3_v3_single_x((float (*)[3])pc->matrix, co_a) - pc->axis_sep;
-       const float diff_b = mul_m3_v3_single_x((float (*)[3])pc->matrix, co_b) - pc->axis_sep;
+       const float diff_a = dot_m3_v3_row_x((float (*)[3])pc->matrix, co_a) - pc->axis_sep;
+       const float diff_b = dot_m3_v3_row_x((float (*)[3])pc->matrix, co_b) - pc->axis_sep;
 
        const int test_a = (fabsf(diff_a) < CONNECT_EPS) ? 0 : (diff_a < 0.0f) ? -1 : 1;
        const int test_b = (fabsf(diff_b) < CONNECT_EPS) ? 0 : (diff_b < 0.0f) ? -1 : 1;
@@ -104,7 +104,7 @@ static int state_isect_co_pair(const PathContext *pc,
 static int state_isect_co_exact(const PathContext *pc,
                                 const float co[3])
 {
-       const float diff = mul_m3_v3_single_x((float (*)[3])pc->matrix, co) - pc->axis_sep;
+       const float diff = dot_m3_v3_row_x((float (*)[3])pc->matrix, co) - pc->axis_sep;
        return (fabsf(diff) <= CONNECT_EPS);
 }
 
@@ -113,8 +113,8 @@ static float state_calc_co_pair_fac(const PathContext *pc,
 {
        float diff_a, diff_b, diff_tot;
 
-       diff_a = fabsf(mul_m3_v3_single_x((float (*)[3])pc->matrix, co_a) - pc->axis_sep);
-       diff_b = fabsf(mul_m3_v3_single_x((float (*)[3])pc->matrix, co_b) - pc->axis_sep);
+       diff_a = fabsf(dot_m3_v3_row_x((float (*)[3])pc->matrix, co_a) - pc->axis_sep);
+       diff_b = fabsf(dot_m3_v3_row_x((float (*)[3])pc->matrix, co_b) - pc->axis_sep);
        diff_tot = (diff_a + diff_b);
        return (diff_tot > FLT_EPSILON) ? (diff_a / diff_tot) : 0.5f;
 }
@@ -437,7 +437,7 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op)
                normalize_v3_v3(pc.matrix[2], basis_nor);
                invert_m3(pc.matrix);
 
-               pc.axis_sep = mul_m3_v3_single_x(pc.matrix, pc.v_a->co);
+               pc.axis_sep = dot_m3_v3_row_x(pc.matrix, pc.v_a->co);
        }
 
        /* add first vertex */
index 97444a504388ae862d7f2e5d31ab44236df80fe3..60fdf075d18abda1baad802c6de05927c0f41525 100644 (file)
@@ -277,6 +277,8 @@ static void bm_interp_face_store(InterpFace *iface, BMesh *bm, BMFace *f, MemAre
        void *axis_mat     = iface->axis_mat;
        int i;
 
+       BLI_assert(BM_face_is_normal_valid(f));
+
        axis_dominant_v3_to_m3(axis_mat, f->no);
 
        iface->f = f;
index fb1e8ec6a1730e2776432dfa2355a5d693024944..8b8cab9d8815657758306622ae24555deba3aee5 100644 (file)
@@ -103,7 +103,7 @@ void bmo_rotate_exec(BMesh *bm, BMOperator *op)
 
        BMO_slot_vec_get(op->slots_in, "cent", center);
        BMO_slot_mat4_get(op->slots_in, "matrix", mat);
-       pivot_m4(mat, center);
+       transform_pivot_set_m4(mat, center);
 
        BMO_op_callf(bm, op->flag, "transform matrix=%m4 space=%s verts=%s", mat, op, "space", op, "verts");
 }
index c1ba40d95f92b1a84f8bc54764e769d0660b8627..5d47ce155c8fa07650221e830bd56013541c8056 100644 (file)
@@ -50,7 +50,11 @@ static const char *bc_get_joint_name(T *node)
 }
 
 ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce) :
-       TransformReader(conv), scene(sce), empty(NULL), mesh_importer(mesh) {
+       unit_converter(conv),
+       TransformReader(conv), 
+       scene(sce), 
+       empty(NULL), 
+       mesh_importer(mesh) {
 }
 
 ArmatureImporter::~ArmatureImporter()
@@ -82,17 +86,15 @@ JointData *ArmatureImporter::get_joint_data(COLLADAFW::Node *node);
 void ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBone *parent, int totchild,
                                    float parent_mat[4][4], bArmature *arm)
 {
+       float mat[4][4];
+       float joint_inv_bind_mat[4][4];
+
        //Checking if bone is already made.
        std::vector<COLLADAFW::Node *>::iterator it;
        it = std::find(finished_joints.begin(), finished_joints.end(), node);
        if (it != finished_joints.end()) return;
 
-       float joint_inv_bind_mat[4][4];
-
        // JointData* jd = get_joint_data(node);
-
-       float mat[4][4];
-       float obmat[4][4];
        
        // TODO rename from Node "name" attrs later
        EditBone *bone = ED_armature_edit_bone_add(arm, (char *)bc_get_joint_name(node));
@@ -101,9 +103,18 @@ void ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBo
        if (skin && skin->get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) {
                // get original world-space matrix
                invert_m4_m4(mat, joint_inv_bind_mat);
+
+               // And make local to armature
+               Object *ob_arm = skin->BKE_armature_from_object();
+               if (ob_arm) {
+                       float invmat[4][4];
+                       invert_m4_m4(invmat, ob_arm->obmat);
+                       mul_m4_m4m4(mat, invmat, mat);
+               }
        }
        // create a bone even if there's no joint data for it (i.e. it has no influence)
        else {
+               float obmat[4][4];
                // bone-space
                get_node_mat(obmat, node, NULL, NULL);
 
index 80bde1842dd93780ba0b6f0cb9095b04831c3aa7..c6337e27218102c706de10b225ba17ac616139e6 100644 (file)
@@ -185,6 +185,9 @@ void DocumentImporter::finish()
        Main *bmain = CTX_data_main(mContext);
        // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
        Scene *sce = CTX_data_scene(mContext);
+       unit_converter.calculate_scale(*sce);
+
+       std::vector<Object *> *objects_to_scale = new std::vector<Object *>();
 
        /** TODO Break up and put into 2-pass parsing of DAE */
        std::vector<const COLLADAFW::VisualScene *>::iterator it;
@@ -221,13 +224,8 @@ void DocumentImporter::finish()
                // Write nodes to scene
                const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
                for (unsigned int i = 0; i < roots.getCount(); i++) {
-                       std::vector<Object *> *objects_done;
-                       objects_done = write_node(roots[i], NULL, sce, NULL, false);
-                       
-                       if (!this->import_settings->import_units) {
-                               // Match incoming scene with current unit settings
-                               bc_match_scale(objects_done, *sce, unit_converter);
-                       }
+                       std::vector<Object *> *objects_done = write_node(roots[i], NULL, sce, NULL, false);
+                       objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end());
                }
 
                // update scene
@@ -278,6 +276,8 @@ void DocumentImporter::finish()
 
                DAG_relations_tag_update(bmain);
        }
+       
+       bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);
 }
 
 
@@ -461,6 +461,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
        std::string name = node->getName();
 
        std::vector<Object *> *objects_done = new std::vector<Object *>();
+       std::vector<Object *> *root_objects = new std::vector<Object *>();
 
        fprintf(stderr,
                        "Writing node id='%s', name='%s'\n",
@@ -473,6 +474,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                        // Here we add the armature "on the fly":
                        par = bc_add_object(sce, OB_ARMATURE, std::string("Armature").c_str());
                        objects_done->push_back(par);
+                       root_objects->push_back(par);
                        object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
                        node_map[node->getUniqueId()] = node;
                }
@@ -483,7 +485,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                if (parent_node == NULL) {
                        // for skeletons without root node all has been done above.
                        // Skeletons with root node are handled further down.
-                       return objects_done;
+                       return root_objects;
                }
        }
        else {
@@ -512,6 +514,9 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                        }
                        else {
                                objects_done->push_back(ob);
+                               if (parent_node == NULL) {
+                                       root_objects->push_back(ob);
+                               }
                        }
                        ++geom_done;
                }
@@ -522,19 +527,29 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                                std::string name = node->getName();
                                fprintf(stderr, "<node id=\"%s\", name=\"%s\" >...contains a reference to an unknown instance_camera.\n", id.c_str(), name.c_str());
                        }
-                       else
+                       else {
                                objects_done->push_back(ob);
+                               if (parent_node == NULL) {
+                                       root_objects->push_back(ob);
+                               }
+                       }
                        ++camera_done;
                }
                while (lamp_done < lamp.getCount()) {
                        ob = create_lamp_object(lamp[lamp_done], sce);
                        objects_done->push_back(ob);
+                       if (parent_node == NULL) {
+                               root_objects->push_back(ob);
+                       }
                        ++lamp_done;
                }
                while (controller_done < controller.getCount()) {
                        COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry *)controller[controller_done];
                        ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map);
                        objects_done->push_back(ob);
+                       if (parent_node == NULL) {
+                               root_objects->push_back(ob);
+                       }
                        ++controller_done;
                }
                // XXX instance_node is not supported yet
@@ -550,9 +565,12 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                                        Object *source_ob = (Object *)it2->second;
                                        COLLADAFW::Node *source_node = node_map[node_id];
                                        ob = create_instance_node(source_ob, source_node, node, sce, is_library_node);
+                                       objects_done->push_back(ob);
+                                       if (parent_node == NULL) {
+                                               root_objects->push_back(ob);
+                                       }
                                }
                        }
-                       if (ob != NULL) objects_done->push_back(ob);
                        ++inst_done;
 
                        read_transform = false;
@@ -569,12 +587,14 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                                ob = bc_add_object(sce, OB_EMPTY, NULL);
                        }
                        objects_done->push_back(ob);
-
+                       if (parent_node == NULL) {
+                               root_objects->push_back(ob);
+                       }
                }
                
                // XXX: if there're multiple instances, only one is stored
 
-               if (!ob) return objects_done;
+               if (!ob) return root_objects;
 
                for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
                        ob = *it;
@@ -623,7 +643,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                write_node(child_nodes[i], node, sce, ob, is_library_node);
        }
 
-       return objects_done;
+       return root_objects;
 }
 
 /** When this method is called, the writer must write the entire visual scene.
index c2770dc3dc56378f9d9f00201d6808c2f7a60a52..7ae1750d2cadd12e9c78e9d056b5255ca584318f 100644 (file)
@@ -226,8 +226,6 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
        ArmatureModifierData *amd = (ArmatureModifierData *)md;
        amd->object = ob_arm;
 
-       copy_m4_m4(ob->obmat, bind_shape_matrix);
-       BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
 #if 1
        bc_set_parent(ob, ob_arm, C);
 #else
@@ -243,6 +241,8 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
        DAG_relations_tag_update(bmain);
        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 #endif
+       copy_m4_m4(ob->obmat, bind_shape_matrix);
+       BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
 
        amd->deformflag = ARM_DEF_VGROUP;
 
index 43faa15b4bb69c0ceef6b8cdccbf54b9a0b1288c..f8f31304d28bfa1b1e8c96091980afe18b24ea45 100644 (file)
@@ -48,7 +48,9 @@ void TransformReader::get_node_mat(float mat[4][4], COLLADAFW::Node *node, std::
 
                switch (type) {
                        case COLLADAFW::Transformation::MATRIX:
-                               // XXX why does this return and discard all following transformations?
+                               // When matrix AND Trans/Rot/Scale are defined for a node,
+                               // then this is considered as redundant information.
+                               // So if we find a Matrix we use that and return.
                                dae_matrix_to_mat4(tm, mat);
                                return;
                        case COLLADAFW::Transformation::TRANSLATE:
index 069419f938b72eb67e0c537bfe7d1f560237e7e8..567ee22b3d62cf5c8d34644e67f7ba6bafd94bb7 100644 (file)
@@ -27,7 +27,7 @@
 
 /* COLLADABU_ASSERT, may be able to remove later */
 #include "COLLADABUPlatform.h"
-#include "collada_internal.h"
+#include "collada_utils.h"
 
 #include "BLI_linklist.h"
 
@@ -40,7 +40,7 @@ UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP)
        rotate_m4(y_up_mat4, 'X', 0.5 * M_PI);
 
        unit_m4(z_up_mat4);
-
+       unit_m4(scale_mat4);
 }
 
 void UnitConverter::read_asset(const COLLADAFW::FileInfo *asset)
@@ -124,6 +124,48 @@ float(&UnitConverter::get_rotation())[4][4]
        }
 }
 
+
+float(&UnitConverter::get_scale())[4][4]
+{
+       return scale_mat4;
+}
+
+void UnitConverter::calculate_scale(Scene &sce)
+{
+       PointerRNA scene_ptr, unit_settings;
+       PropertyRNA *system_ptr, *scale_ptr;
+       RNA_id_pointer_create(&sce.id, &scene_ptr);
+
+       unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
+       system_ptr    = RNA_struct_find_property(&unit_settings, "system");
+       scale_ptr     = RNA_struct_find_property(&unit_settings, "scale_length");
+
+       int   type    = RNA_property_enum_get(&unit_settings, system_ptr);
+
+       float bl_scale;
+
+       switch (type) {
+               case USER_UNIT_NONE:
+                       bl_scale = 1.0; // map 1 Blender unit to 1 Meter
+                       break;
+
+               case USER_UNIT_METRIC:
+                       bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
+                       break;
+
+               default :
+                       bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
+                       // it looks like the conversion to Imperial is done implicitly.
+                       // So nothing to do here.
+                       break;
+       }
+
+       float rescale[3];
+       rescale[0] = rescale[1] = rescale[2] = getLinearMeter() / bl_scale;
+
+       size_to_mat4(scale_mat4, rescale);
+}
+
 void TransformBase::decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size)
 {
        mat4_to_size(size, mat);
index 2e855764f4ba1d4718fb2d36fda000179be3b0e3..4aa637a687639a8d796e514fbbe4b581311d3352 100644 (file)
@@ -50,7 +50,8 @@ private:
        float x_up_mat4[4][4];
        float y_up_mat4[4][4];
        float z_up_mat4[4][4];
-
+       float scale_mat4[4][4];
+       
 public:
 
        enum UnitSystem {
@@ -79,7 +80,8 @@ public:
        void mat4_to_dae_double(double out[4][4], float in[4][4]);
 
        float(&get_rotation())[4][4];
-
+       float(&get_scale())[4][4];
+       void calculate_scale(Scene &sce);
 
 };
 
index d4196bacf0d1487320d73fb1f7ed57592d693f16..3e17472e9c2c603ff9dfb2c241f6eb89fc0f97c9 100644 (file)
@@ -324,65 +324,30 @@ std::string bc_replace_string(std::string data, const std::string& pattern,
  * Calculate a rescale factor such that the imported scene's scale
  * is preserved. I.e. 1 meter in the import will also be
  * 1 meter in the current scene.
- * XXX : I am not sure if it is correct to map 1 Blender Unit
- * to 1 Meter for unit type NONE. But it looks reasonable to me.
  */
-void bc_match_scale(std::vector<Object *> *objects_done, 
-                    Scene &sce,
-                    UnitConverter &bc_unit)
-{
-       Object *ob = NULL;
-
-       PointerRNA scene_ptr, unit_settings;
-       PropertyRNA *system_ptr, *scale_ptr;
-       RNA_id_pointer_create(&sce.id, &scene_ptr);
-
-       unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
-       system_ptr = RNA_struct_find_property(&unit_settings, "system");
-       scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length");
-
-       int   type  = RNA_property_enum_get(&unit_settings, system_ptr);
 
-       float bl_scale;
-       
-       switch (type) {
-               case USER_UNIT_NONE:
-                       bl_scale = 1.0; // map 1 Blender unit to 1 Meter
-                       break;
-
-               case USER_UNIT_METRIC:
-                       bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
-                       break;
-
-               default :
-                       bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
-                       // it looks like the conversion to Imperial is done implicitly.
-                       // So nothing to do here.
-                       break;
+void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
+{
+       if (scale_to_scene) {
+               mul_m4_m4m4(ob->obmat, bc_unit.get_scale(), ob->obmat);
        }
-       
-       float scale_conv = bc_unit.getLinearMeter() / bl_scale;
-
-       float rescale[3];
-       rescale[0] = rescale[1] = rescale[2] = scale_conv;
-
-       float size_mat4[4][4];
-
-       float axis_mat4[4][4];
-       unit_m4(axis_mat4);
-
-       size_to_mat4(size_mat4, rescale);
+       mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
+       BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
+}
 
+void bc_match_scale(std::vector<Object *> *objects_done, 
+                       UnitConverter &bc_unit,
+                       bool scale_to_scene)
+{
        for (std::vector<Object *>::iterator it = objects_done->begin();
                        it != objects_done->end();
                        ++it) 
        {
-               ob = *it;
-               mul_m4_m4m4(ob->obmat, size_mat4, ob->obmat);
-               mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
-               BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
+               Object *ob = *it;
+               if (ob -> parent == NULL) {
+                       bc_match_scale(*it, bc_unit, scale_to_scene);
+               }
        }
-
 }
 
 void bc_triangulate_mesh(Mesh *me)
index f8e6f09e4983420525e3a986621579532ad1ffe7..4bc2f55cf333e27ea794be16f93adb3eaef5ed7b 100644 (file)
@@ -83,7 +83,8 @@ extern int  bc_get_active_UVLayer(Object *ob);
 
 extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement); 
 extern std::string bc_url_encode(std::string data); 
-extern void bc_match_scale(std::vector<Object *> *objects_done, Scene &sce, UnitConverter &unit_converter);
+extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene);
+extern void bc_match_scale(std::vector<Object *> *objects_done, UnitConverter &unit_converter, bool scale_to_scene);
 
 extern void bc_triangulate_mesh(Mesh *me);
 
index 6504c198b21a3aa470fa2ad8383f17b8282eba1c..21a63183c1a27e5ec42c50ee73f0c08de929c757 100644 (file)
@@ -3964,7 +3964,8 @@ void uiButSetFocusOnEnter(wmWindow *win, uiBut *but)
 {
        wmEvent event;
        
-       event = *(win->eventstate);
+       wm_event_init_from_window(win, &event);
+
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
index 8efad17133f904e0e91387da2010ace51d484fde..b3df719d95abe016c9c65ccb3e0522c893dbd01e 100644 (file)
@@ -6193,7 +6193,7 @@ void ui_button_activate_do(bContext *C, ARegion *ar, uiBut *but)
        
        button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER);
        
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
index 8da66c114d5e4b7b99505f82ef565dd7aaa91dbe..4bd8a7d426a87476e8a99ac549208c93bd24bbb6 100644 (file)
@@ -964,7 +964,7 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
 
                br->icon_imbuf = get_brush_icon(br);
 
-               memset(sp->pr_rect, 0x888888, sp->sizex * sp->sizey * sizeof(unsigned int));
+               memset(sp->pr_rect, 0x88, sp->sizex * sp->sizey * sizeof(unsigned int));
 
                if (!(br->icon_imbuf) || !(br->icon_imbuf->rect))
                        return;
index 4670d6598860fdd1d544d65e7db51ba9763f6764..3066b733fc52a333bfee0048c55daa6db284df51 100644 (file)
@@ -649,7 +649,8 @@ static void actionzone_apply(bContext *C, wmOperator *op, int type)
        
        sad->modifier = RNA_int_get(op->ptr, "modifier");
        
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
+
        if (type == AZONE_AREA)
                event.type = EVT_ACTIONZONE_AREA;
        else
index 6181861a6e30fb9b646da99cc2964948d9449b4b..9720256df056954ea723179f51d18de4865c0569 100644 (file)
@@ -4591,14 +4591,21 @@ void sculpt_dynamic_topology_enable(bContext *C)
        Object *ob = CTX_data_active_object(C);
        SculptSession *ss = ob->sculpt;
        Mesh *me = ob->data;
+       const BMAllocTemplate allocsize = {me->totvert,
+                                          me->totedge,
+                                          me->totloop,
+                                          me->totpoly};
 
        sculpt_pbvh_clear(ob);
 
        ss->bm_smooth_shading = (scene->toolsettings->sculpt->flags &
                                 SCULPT_DYNTOPO_SMOOTH_SHADING);
 
+       /* Dynamic topology doesn't ensure selection state is valid, so remove [#36280] */
+       BKE_mesh_mselect_clear(me);
+
        /* Create triangles-only BMesh */
-       ss->bm = BM_mesh_create(&bm_mesh_allocsize_default);
+       ss->bm = BM_mesh_create(&allocsize);
 
        BM_mesh_bm_from_me(ss->bm, me, true, true, ob->shapenr);
        sculpt_dynamic_topology_triangulate(ss->bm);
index bd0c9848b239d83abdadfc34c6a3a2ca0e7e3bf0..e17699309ef9bf127f63557776a2427862c1c266 100644 (file)
@@ -926,7 +926,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op)
        uiEndBlock(C, block);
        
        //      uiButActiveOnly(C, ar, block, but); XXX using this here makes Blender hang - investigate
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
index 81207deea0172d0c58188baca97254ed2b59197b..aec7213ee05e0f9758d789feda8b46c70438d010 100644 (file)
@@ -539,21 +539,21 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF,
-                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                   &ptr, "hide", -1, 0, 0, -1, -1,
                                                   TIP_("Restrict viewport visibility (Ctrl - Recursive)"));
                                uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
                                
                                bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
-                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                   &ptr, "hide_select", -1, 0, 0, -1, -1,
                                                   TIP_("Restrict viewport selection (Ctrl - Recursive)"));
                                uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
                                
                                bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
-                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                   &ptr, "hide_render", -1, 0, 0, -1, -1,
                                                   TIP_("Restrict rendering (Ctrl - Recursive)"));
                                uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
@@ -570,21 +570,21 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
 
                                restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW);
                                bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow visibility in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 
                                restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT);
                                bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow selection in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 
                                restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER);
                                bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)te->ys, UI_UNIT_X, UI_UNIT_Y,
+                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
                                                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
                                uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
@@ -596,7 +596,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                
                                bt = uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT - 1,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, te->directdata, 0, 0, 0, 0, TIP_("Render this RenderLayer"));
                                uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
@@ -611,7 +611,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                
                                
                                bt = uiDefIconButBitI(block, ICONTOG, passflag, 0, ICON_CHECKBOX_HLT - 1,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Render this Pass"));
                                uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
@@ -621,7 +621,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                          SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT))
                                {
                                        bt = uiDefIconButBitI(block, TOG, passflag, 0, (*layflag & passflag) ? ICON_DOT : ICON_BLANK1,
-                                                             (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X,
+                                                             (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
                                                              UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Exclude this Pass from Combined"));
                                        uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                        uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
@@ -635,14 +635,14 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(md->mode), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow visibility in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
                                
                                bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(md->mode), 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
                                uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
@@ -656,14 +656,14 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow visibility in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_bone_visibility_cb, ob->data, bone);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
                                
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow selection in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_bone_select_cb, ob->data, bone);
@@ -676,14 +676,14 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow visibility in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_ebone_visibility_cb, NULL, ebone);
                                uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
                                
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow selection in the 3D View"));
                                uiButSetFunc(bt, restrictbutton_ebone_select_cb, NULL, ebone);
@@ -735,7 +735,7 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa
                                prop = te->directdata;
                                
                                if (!(RNA_property_type(prop) == PROP_POINTER && (TSELEM_OPEN(tselem, soops)))) {
-                                       uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX,
+                                       uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, te->ys, OL_RNA_COL_SIZEX,
                                                      UI_UNIT_Y - 1);
                                }
                        }
@@ -743,7 +743,7 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa
                                ptr = &te->rnaptr;
                                prop = te->directdata;
                                
-                               uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX,
+                               uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, te->ys, OL_RNA_COL_SIZEX,
                                              UI_UNIT_Y - 1);
                        }
                }
@@ -811,7 +811,7 @@ static uiBlock *operator_search_menu(bContext *C, ARegion *ar, void *arg_kmi)
        uiBlockSetDirection(block, UI_DOWN);
        uiEndBlock(C, block);
        
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
@@ -960,7 +960,7 @@ static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soo
                                        /* pass */
                                }
                                else {
-                                       uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, (int)te->ys + 1, butw1, UI_UNIT_Y - 1,
+                                       uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, te->ys + 1, butw1, UI_UNIT_Y - 1,
                                                      TIP_("Assign new Operator"));
                                }
                                xstart += butw1 + 10;
@@ -969,7 +969,7 @@ static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soo
                                kmi->maptype = keymap_menu_type(kmi->type);
                                
                                str = keymap_type_menu();
-                               but = uiDefButS(block, MENU, 0, str,    xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->maptype,
+                               but = uiDefButS(block, MENU, 0, str,    xstart, te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->maptype,
                                                0, 0, 0, 0, TIP_("Event type"));
                                uiButSetFunc(but, keymap_type_cb, kmi, NULL);
                                xstart += butw2 + 5;
@@ -977,48 +977,48 @@ static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soo
                                /* edit actual event */
                                switch (kmi->maptype) {
                                        case OL_KM_KEYBOARD:
-                                               uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
+                                               uiDefKeyevtButS(block, 0, "", xstart, te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
                                                                TIP_("Key code"));
                                                xstart += butw2 + 5;
                                                break;
                                        case OL_KM_MOUSE:
                                                str = keymap_mouse_menu();
-                                               uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
+                                               uiDefButS(block, MENU, 0, str, xstart, te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
                                                          0, 0, 0, 0, TIP_("Mouse button"));
                                                xstart += butw2 + 5;
                                                break;
                                        case OL_KM_TWEAK:
                                                str = keymap_tweak_menu();
-                                               uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
+                                               uiDefButS(block, MENU, 0, str, xstart, te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type,
                                                          0, 0, 0, 0, TIP_("Tweak gesture"));
                                                xstart += butw2 + 5;
                                                str = keymap_tweak_dir_menu();
-                                               uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->val,
+                                               uiDefButS(block, MENU, 0, str, xstart, te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->val,
                                                          0, 0, 0, 0, TIP_("Tweak gesture direction"));
                                                xstart += butw2 + 5;
                                                break;
                                }
                                
                                /* modifiers */
-                               uiDefButS(block, OPTION, 0, IFACE_("Shift"), xstart, (int)te->ys + 1, butw3 + 5, UI_UNIT_Y - 1,
+                               uiDefButS(block, OPTION, 0, IFACE_("Shift"), xstart, te->ys + 1, butw3 + 5, UI_UNIT_Y - 1,
                                          &kmi->shift, 0, 0, 0, 0, TIP_("Modifier"));
                                xstart += butw3 + 5;
-                               uiDefButS(block, OPTION, 0, IFACE_("Ctrl"), xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->ctrl,
+                               uiDefButS(block, OPTION, 0, IFACE_("Ctrl"), xstart, te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->ctrl,
                                          0, 0, 0, 0, TIP_("Modifier"));
                                xstart += butw3;
-                               uiDefButS(block, OPTION, 0, IFACE_("Alt"), xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->alt,
+                               uiDefButS(block, OPTION, 0, IFACE_("Alt"), xstart, te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->alt,
                                          0, 0, 0, 0, TIP_("Modifier"));
                                xstart += butw3;
-                               uiDefButS(block, OPTION, 0, IFACE_("OS"), xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->oskey,
+                               uiDefButS(block, OPTION, 0, IFACE_("OS"), xstart, te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->oskey,
                                          0, 0, 0, 0, TIP_("Modifier"));
                                xstart += butw3 + 5;
-                               uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->keymodifier,
+                               uiDefKeyevtButS(block, 0, "", xstart, te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->keymodifier,
                                                TIP_("Key Modifier code"));
                                xstart += butw3 + 5;
                                
                                /* rna property */
                                if (kmi->ptr && kmi->ptr->data) {
-                                       uiDefBut(block, LABEL, 0, IFACE_("(RNA property)"), xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1,
+                                       uiDefBut(block, LABEL, 0, IFACE_("(RNA property)"), xstart, te->ys + 1, butw2, UI_UNIT_Y - 1,
                                                 NULL, 0, 0, 0, 0, "");
                                        xstart += butw2;
                                }
@@ -1064,7 +1064,7 @@ static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, Spa
                                spx = te->xs + 1.8f * UI_UNIT_X;
                                if (spx + dx + 0.5f * UI_UNIT_X > ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax - spx - 0.5f * UI_UNIT_X;
 
-                               bt = uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (int)te->ys, dx + UI_UNIT_X, UI_UNIT_Y - 1, (void *)te->name,
+                               bt = uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, te->ys, dx + UI_UNIT_X, UI_UNIT_Y - 1, (void *)te->name,
                                              1.0, (float)len, 0, 0, "");
                                uiButSetRenameFunc(bt, namebutton_cb, tselem);
                                
@@ -1440,8 +1440,8 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
                        }
                        
                        tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
-                       te->xs = (float)*offsx;
-                       te->ys = (float)ys;
+                       te->xs = *offsx;
+                       te->ys = ys;
                        te->xend = (short)*offsx + UI_UNIT_X;
                        te->flag |= TE_ICONROW; // for click
                        
@@ -1456,13 +1456,13 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
 }
 
 /* closed tree element */
-static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
+static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int starty)
 {
        TreeElement *ten;
        
        /* store coord and continue, we need coordinates for elements outside view too */
-       te->xs = (float)startx;
-       te->ys = (float)(*starty);
+       te->xs = startx;
+       te->ys = starty;
        
        for (ten = te->subtree.first; ten; ten = ten->next) {
                outliner_set_coord_tree_element(soops, ten, startx + UI_UNIT_X, starty);
@@ -1656,8 +1656,8 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene
                }
        }
        /* store coord and continue, we need coordinates for elements outside view too */
-       te->xs = (float)startx;
-       te->ys = (float)*starty;
+       te->xs = startx;
+       te->ys = *starty;
        te->xend = startx + offsx;
                
        if (TSELEM_OPEN(tselem, soops)) {
@@ -1668,7 +1668,7 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene
        }
        else {
                for (ten = te->subtree.first; ten; ten = ten->next)
-                       outliner_set_coord_tree_element(soops, te, startx, starty);
+                       outliner_set_coord_tree_element(soops, ten, startx, *starty);
                
                *starty -= UI_UNIT_Y;
        }
index 0161f53e6905925cce37b35f8c07569005592bcf..cef5fe53407efe52d95d9a9927dbcaa6bbf26194 100644 (file)
@@ -618,7 +618,7 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
        te = outliner_find_id(so, &so->tree, (ID *)OBACT);
        if (te) {
                /* make te->ys center of view */
-               ytop = (int)(te->ys + BLI_rcti_size_y(&v2d->mask) / 2);
+               ytop = te->ys + BLI_rcti_size_y(&v2d->mask) / 2;
                if (ytop > 0) ytop = 0;
                
                v2d->cur.ymax = (float)ytop;
index fe07a7dae9f8829ac1a89efb18fc5637d26bcf77..2310ca9b4b5cb90cd6a09d417d27aa6c180a9265 100644 (file)
@@ -48,7 +48,7 @@ struct Object;
 typedef struct TreeElement {
        struct TreeElement *next, *prev, *parent;
        ListBase subtree;
-       float xs, ys;       // do selection
+       int xs, ys;         // do selection
        int store_index;    // offset in tree store
        short flag;         // flag for non-saved stuff
        short index;        // index for data arrays
index eb33d799dff1dade2a104cf4487207f3ad23abfc..17734f00997b3c6a4e19d0c7cf0ae13853031bd8 100644 (file)
@@ -804,7 +804,6 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
        TreeElement *te;
        TreeStoreElem *tselem;
        ID *id = idv;
-       int a = 0;
        
        if (ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
                id = ((PointerRNA *)idv)->id.data;
@@ -1084,7 +1083,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                te->name = km->idname;
                
                if (TSELEM_OPEN(tselem, soops)) {
-                       a = 0;
+                       int a = 0;
                        
                        for (kmi = km->items.first; kmi; kmi = kmi->next, a++) {
                                const char *key = WM_key_event_string(kmi->type);
@@ -1131,7 +1130,7 @@ static int need_add_seq_dup(Sequence *seq)
 {
        Sequence *p;
 
-       if ((!seq->strip) || (!seq->strip->stripdata) || (!seq->strip->stripdata->name))
+       if ((!seq->strip) || (!seq->strip->stripdata))
                return(1);
 
        /*
index facbd45606dffcb9973b91007940de7bf324a6b3..0f2f07a1053efe088d050b66caf0a63777ef44f8 100644 (file)
@@ -660,7 +660,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name = "Snap Selection to Grid";
-       ot->description = "Snap selected item(s) to nearest grid node";
+       ot->description = "Snap selected item(s) to nearest grid division";
        ot->idname = "VIEW3D_OT_snap_selected_to_grid";
        
        /* api callbacks */
@@ -867,7 +867,7 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name = "Snap Cursor to Grid";
-       ot->description = "Snap cursor to nearest grid node";
+       ot->description = "Snap cursor to nearest grid division";
        ot->idname = "VIEW3D_OT_snap_cursor_to_grid";
        
        /* api callbacks */
index f5f59c935df426badcfc46f74db8169d0b7955ce..bdb203ab003121a4b9f2600df391d11d035b3d8c 100644 (file)
@@ -195,7 +195,7 @@ static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase)
        uiBlockSetDirection(block, UI_DOWN);
        uiEndBlock(C, block);
        
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
index c2ca8cd46b6b04bfaa7f788e90b56b176198c1b7..b154acc74560dbd9b2d536609eec67d0f231349f 100644 (file)
@@ -2128,7 +2128,7 @@ static void createTransEditVerts(TransInfo *t)
        float *mappedcos = NULL, *quats = NULL;
        float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
        float *dists = NULL;
-       int count = 0, countsel = 0, a, totleft;
+       int a;
        int propmode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
        int mirror = 0;
        int cd_vert_bweight_offset = -1;
@@ -2164,10 +2164,6 @@ static void createTransEditVerts(TransInfo *t)
                BLI_assert(0);
        }
 
-       countsel = bm->totvertsel;
-       if (propmode) {
-               count = bm->totvert;
-       }
 
        /* check active */
        eve_act = BM_mesh_active_vert_get(bm);
@@ -2178,6 +2174,13 @@ static void createTransEditVerts(TransInfo *t)
        }
 
        if (propmode) {
+               unsigned int count = 0;
+               BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+                       if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+                               count++;
+                       }
+               }
+
                t->total = count;
 
                /* allocating scratch arrays */
@@ -2185,7 +2188,7 @@ static void createTransEditVerts(TransInfo *t)
                        dists = MEM_mallocN(em->bm->totvert * sizeof(float), "scratch nears");
        }
        else {
-               t->total = countsel;
+               t->total = bm->totvertsel;
        }
 
        tob = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mesh EditMode)");
@@ -2217,6 +2220,7 @@ static void createTransEditVerts(TransInfo *t)
        /* detect CrazySpace [tm] */
        if (modifiers_getCageIndex(t->scene, t->obedit, NULL, 1) >= 0) {
                if (modifiers_isCorrectableDeformed(t->obedit)) {
+                       int totleft;
                        /* check if we can use deform matrices for modifier from the
                         * start up to stack, they are more accurate than quats */
                        totleft = editbmesh_get_first_deform_matrices(t->scene, t->obedit, em, &defmats, &defcos);
index ac38578b981b8e1b9907d9c661860352405385e2..035238299f85a0315703bbd5d69290e2f7ab9571 100644 (file)
@@ -653,7 +653,8 @@ typedef struct GameData {
        short mode, matmode;
        short occlusionRes;             /* resolution of occlusion Z buffer in pixel */
        short physicsEngine;
-       short exitkey, pad;
+       short exitkey;
+       short vsync; /* Controls vsync: off, on, or adaptive (if supported) */
        short ticrate, maxlogicstep, physubstep, maxphystep;
        short obstacleSimulation;
        short raster_storage;
@@ -689,6 +690,11 @@ typedef struct GameData {
 #define RAS_STORE_VA           2
 #define RAS_STORE_VBO          3
 
+/* vsync */
+#define VSYNC_OFF      0
+#define VSYNC_ON       1
+#define VSYNC_ADAPTIVE 2
+
 /* GameData.flag */
 #define GAME_RESTRICT_ANIM_UPDATES                     (1 << 0)
 #define GAME_ENABLE_ALL_FRAMES                         (1 << 1)
index faf348302e4ac5bb936b2c041a7466604ecc9fe0..f382caaccba0b883fde3552b10f46dccc48e79b8 100644 (file)
@@ -177,8 +177,8 @@ static int replace_if_different(char *tmpfile, const char *dep_files[])
 
 
        if (len_new != len_org) {
-               fclose(fp_new);
-               fclose(fp_org);
+               fclose(fp_new); fp_new = NULL;
+               fclose(fp_org); fp_org = NULL;
                REN_IF_DIFF;
        }
 
@@ -191,8 +191,8 @@ static int replace_if_different(char *tmpfile, const char *dep_files[])
        if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
                fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
 
-       fclose(fp_new);
-       fclose(fp_org);
+       fclose(fp_new); fp_new = NULL;
+       fclose(fp_org); fp_org = NULL;
 
        cmp = memcmp(arr_new, arr_org, len_new);
 
@@ -319,15 +319,15 @@ static void rna_print_c_string(FILE *f, const char *str)
 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
 {
        if (dp->dnastructfromname && dp->dnastructfromprop)
-               fprintf(f, "    %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname,
+               fprintf(f, "    %s *data = (%s *)(((%s *)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname,
                        dp->dnastructfromname, dp->dnastructfromprop);
        else
-               fprintf(f, "    %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
+               fprintf(f, "    %s *data = (%s *)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
 }
 
 static void rna_print_id_get(FILE *f, PropertyDefRNA *UNUSED(dp))
 {
-       fprintf(f, "    ID *id= ptr->id.data;\n");
+       fprintf(f, "    ID *id = ptr->id.data;\n");
 }
 
 static void rna_construct_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
@@ -647,13 +647,13 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
                                                                                        "get_length");
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
-                                               fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
-                                               fprintf(f, "    for (i=0; i < len; i++) {\n");
+                                               fprintf(f, "    int len = %s(ptr, arraylen);\n\n", lenfunc);
+                                               fprintf(f, "    for (i = 0; i < len; i++) {\n");
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
-                                               fprintf(f, "    for (i=0; i < %u; i++) {\n", prop->totarraylength);
+                                               fprintf(f, "    for (i = 0; i < %u; i++) {\n", prop->totarraylength);
                                        }
 
                                        if (dp->dnaarraylength == 1) {
@@ -674,11 +674,11 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                        fprintf(f, ") != 0);\n");
                                                }
                                                else if (rna_color_quantize(prop, dp)) {
-                                                       fprintf(f, "            values[i] = (%s)(data->%s[i]*(1.0f / 255.0f));\n",
+                                                       fprintf(f, "            values[i] = (%s)(data->%s[i] * (1.0f / 255.0f));\n",
                                                                rna_type_type(prop), dp->dnaname);
                                                }
                                                else if (dp->dnatype) {
-                                                       fprintf(f, "            values[i] = (%s)%s(((%s*)data->%s)[i]);\n",
+                                                       fprintf(f, "            values[i] = (%s)%s(((%s *)data->%s)[i]);\n",
                                                                rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnatype, dp->dnaname);
                                                }
                                                else {
@@ -897,15 +897,15 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
                                                                                        "set_length");
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
-                                               fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
+                                               fprintf(f, "    int len = %s(ptr, arraylen);\n\n", lenfunc);
                                                rna_clamp_value_range(f, prop);
-                                               fprintf(f, "    for (i=0; i < len; i++) {\n");
+                                               fprintf(f, "    for (i = 0; i < len; i++) {\n");
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
                                                rna_clamp_value_range(f, prop);
-                                               fprintf(f, "    for (i=0; i < %u; i++) {\n", prop->totarraylength);
+                                               fprintf(f, "    for (i = 0; i < %u; i++) {\n", prop->totarraylength);
                                        }
 
                                        if (dp->dnaarraylength == 1) {
@@ -934,7 +934,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                }
                                                else {
                                                        if (dp->dnatype)
-                                                               fprintf(f, "            ((%s*)data->%s)[i] = %s", dp->dnatype, dp->dnaname,
+                                                               fprintf(f, "            ((%s *)data->%s)[i] = %s", dp->dnatype, dp->dnaname,
                                                                        (dp->booleannegative) ? "!" : "");
                                                        else
                                                                fprintf(f, "            (data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
@@ -1072,8 +1072,8 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
                rna_print_data_get(f, dp);
 
        fprintf(f, "\n  memset(iter, 0, sizeof(*iter));\n");
-       fprintf(f, "    iter->parent= *ptr;\n");
-       fprintf(f, "    iter->prop= (PropertyRNA *)&rna_%s_%s;\n", srna->identifier, prop->identifier);
+       fprintf(f, "    iter->parent = *ptr;\n");
+       fprintf(f, "    iter->prop = (PropertyRNA *)&rna_%s_%s;\n", srna->identifier, prop->identifier);
 
        if (dp->dnalengthname || dp->dnalengthfixed) {
                if (manualfunc) {
@@ -1100,7 +1100,7 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
        getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
 
        fprintf(f, "\n  if (iter->valid)\n");
-       fprintf(f, "            iter->ptr= %s(iter);\n", getfunc);
+       fprintf(f, "            iter->ptr = %s(iter);\n", getfunc);
 
        fprintf(f, "}\n\n");
 
@@ -1139,14 +1139,14 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
                return func;
        }
 
-       fprintf(f, "    int found= 0;\n");
+       fprintf(f, "    int found = 0;\n");
        fprintf(f, "    CollectionPropertyIterator iter;\n\n");
 
        fprintf(f, "    %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
        fprintf(f, "    if (iter.valid) {\n");
 
        if (strcmp(nextfunc, "rna_iterator_array_next") == 0) {
-               fprintf(f, "            ArrayIterator *internal= iter.internal;\n");
+               fprintf(f, "            ArrayIterator *internal = iter.internal;\n");
                fprintf(f, "            if (index < 0 || index >= internal->length) {\n");
                fprintf(f, "#ifdef __GNUC__\n");
                fprintf(f, "                    printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
@@ -1158,25 +1158,25 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
                fprintf(f, "                    while (index-- > 0 && iter.valid) {\n");
                fprintf(f, "                            rna_iterator_array_next(&iter);\n");
                fprintf(f, "                    }\n");
-               fprintf(f, "                    found= (index == -1 && iter.valid);\n");
+               fprintf(f, "                    found = (index == -1 && iter.valid);\n");
                fprintf(f, "            }\n");
                fprintf(f, "            else {\n");
-               fprintf(f, "                    internal->ptr += internal->itemsize*index;\n");
-               fprintf(f, "                    found= 1;\n");
+               fprintf(f, "                    internal->ptr += internal->itemsize * index;\n");
+               fprintf(f, "                    found = 1;\n");
                fprintf(f, "            }\n");
        }
        else if (strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
-               fprintf(f, "            ListBaseIterator *internal= iter.internal;\n");
+               fprintf(f, "            ListBaseIterator *internal = iter.internal;\n");
                fprintf(f, "            if (internal->skip) {\n");
                fprintf(f, "                    while (index-- > 0 && iter.valid) {\n");
                fprintf(f, "                            rna_iterator_listbase_next(&iter);\n");
                fprintf(f, "                    }\n");
-               fprintf(f, "                    found= (index == -1 && iter.valid);\n");
+               fprintf(f, "                    found = (index == -1 && iter.valid);\n");
                fprintf(f, "            }\n");
                fprintf(f, "            else {\n");
                fprintf(f, "                    while (index-- > 0 && internal->link)\n");
-               fprintf(f, "                            internal->link= internal->link->next;\n");
-               fprintf(f, "                    found= (index == -1 && internal->link);\n");
+               fprintf(f, "                            internal->link = internal->link->next;\n");
+               fprintf(f, "                    found = (index == -1 && internal->link);\n");
                fprintf(f, "            }\n");
        }
 
@@ -1318,7 +1318,7 @@ static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *p
        getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
 
        fprintf(f, "\n  if (iter->valid)\n");
-       fprintf(f, "            iter->ptr= %s(iter);\n", getfunc);
+       fprintf(f, "            iter->ptr = %s(iter);\n", getfunc);
 
        fprintf(f, "}\n\n");
 
@@ -2202,7 +2202,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                else if ((type == PROP_POINTER) && (flag & PROP_RNAPTR) && !(flag & PROP_THICK_WRAP))
                        ptrstr = "*";
                /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
-                * but type name for string props is already char*, so leave empty */
+                * but type name for string props is already (char *), so leave empty */
                else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
                        ptrstr = "";
                else
@@ -2225,19 +2225,19 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
 
        /* assign self */
        if (func->flag & FUNC_USE_SELF_ID) {
-               fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
+               fprintf(f, "\t_selfid = (struct ID *)_ptr->id.data;\n");
        }
        
        if ((func->flag & FUNC_NO_SELF) == 0) {
-               if (dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
-               else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
+               if (dsrna->dnaname) fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", dsrna->dnaname);
+               else fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", srna->identifier);
        }
        else if (func->flag & FUNC_USE_SELF_TYPE) {
-               fprintf(f, "\t_type= _ptr->type;\n");
+               fprintf(f, "\t_type = _ptr->type;\n");
        }
 
        if (has_data) {
-               fprintf(f, "\t_data= (char *)_parms->data;\n");
+               fprintf(f, "\t_data = (char *)_parms->data;\n");
        }
 
        dparm = dfunc->cont.properties.first;
@@ -2248,7 +2248,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
 
                if (dparm->prop == func->c_ret)
-                       fprintf(f, "\t_retdata= _data;\n");
+                       fprintf(f, "\t_retdata = _data;\n");
                else {
                        const char *data_str;
                        if (cptr || (flag & PROP_DYNAMIC)) {
@@ -2275,7 +2275,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                        /* this must be kept in sync with RNA_parameter_length_get_data,
                         * we could just call the function directly, but this is faster */
                        if (flag & PROP_DYNAMIC) {
-                               fprintf(f, "\t%s_len= %s((int *)_data);\n", dparm->prop->identifier, pout ? "" : "*");
+                               fprintf(f, "\t%s_len = %s((int *)_data);\n", dparm->prop->identifier, pout ? "" : "*");
                                data_str = "(&(((char *)_data)[sizeof(void *)]))";
                        }
                        else {
@@ -2286,7 +2286,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                        if (!pout)
                                fprintf(f, "%s", valstr);
 
-                       fprintf(f, "((%s%s%s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
+                       fprintf(f, "((%s%s %s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
                                ptrstr, data_str);
                }
 
@@ -2356,7 +2356,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                        dparm = rna_find_parameter_def(func->c_ret);
                        ptrstr = (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) ||
                                  (dparm->prop->arraydimension)) ? "*" : "";
-                       fprintf(f, "\t*((%s%s%s*)_retdata) = %s;\n", rna_type_struct(dparm->prop),
+                       fprintf(f, "\t*((%s%s %s*)_retdata) = %s;\n", rna_type_struct(dparm->prop),
                                rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
                }
        }
@@ -2915,9 +2915,9 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
        fprintf(f, ", %d, ", prop->flag);
        rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
        rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
-       fprintf(f, "%d,\n", prop->icon);
-       rna_print_c_string(f, prop->translation_context); fprintf(f, ",\n\t");
-       fprintf(f, "\t%s, %s|%s, %s, %u, {%u, %u, %u}, %u,\n",
+       fprintf(f, "%d, ", prop->icon);
+       rna_print_c_string(f, prop->translation_context); fprintf(f, ",\n");
+       fprintf(f, "\t%s, %s | %s, %s, %u, {%u, %u, %u}, %u,\n",
                RNA_property_typename(prop->type),
                rna_property_subtypename(prop->subtype),
                rna_property_subtype_unit(prop->subtype),
@@ -3155,14 +3155,14 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        else fprintf(f, "NULL}},\n");
        fprintf(f, "\t");
        rna_print_c_string(f, srna->identifier);
-       fprintf(f, "\t, NULL,NULL\n"); /* PyType - Cant initialize here */
+       fprintf(f, ", NULL, NULL"); /* PyType - Cant initialize here */
        fprintf(f, ", %d, ", srna->flag);
        rna_print_c_string(f, srna->name);
-       fprintf(f, ", ");
+       fprintf(f, ",\n\t");
        rna_print_c_string(f, srna->description);
-       fprintf(f, ", ");
+       fprintf(f, ",\n\t");
        rna_print_c_string(f, srna->translation_context);
-       fprintf(f, ",\n\t%d,\n", srna->icon);
+       fprintf(f, ", %d,\n", srna->icon);
 
        prop = srna->nameproperty;
        if (prop) {
@@ -3392,7 +3392,7 @@ static void rna_generate_header(BlenderRNA *UNUSED(brna), FILE *f)
        fprintf(f, "            CollectionPropertyIterator rna_macro_iter; \\\n");
        fprintf(f, "            for (property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; "
                "property##_next(&rna_macro_iter)) { \\\n");
-       fprintf(f, "                    itemptr= rna_macro_iter.ptr;\n\n");
+       fprintf(f, "                    itemptr = rna_macro_iter.ptr;\n\n");
 
        fprintf(f, "#define FOREACH_END(property) \\\n");
        fprintf(f, "            } \\\n");
@@ -3495,7 +3495,7 @@ static const char *cpp_classes = ""
 "\n"
 "#define STRING_PROPERTY(sname, identifier) \\\n"
 "      inline std::string sname::identifier(void) { \\\n"
-"              int len= sname##_##identifier##_length(&ptr); \\\n"
+"              int len = sname##_##identifier##_length(&ptr); \\\n"
 "              std::string str; str.resize(len); \\\n"
 "              sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
 "      inline void sname::identifier(const std::string& value) { \\\n"
@@ -3604,7 +3604,7 @@ static const char *cpp_classes = ""
 "\n"
 "      Array() {}\n"
 "      Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n"
-"      const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); "
+"      const Array<T, Tsize>& operator = (const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); "
 "return *this; }\n"
 "\n"
 "      operator T*() { return data; }\n"
@@ -3619,7 +3619,7 @@ static const char *cpp_classes = ""
 "      DynamicArray() : data(NULL), length(0) {}\n"
 "      DynamicArray(int new_length) : data(NULL), length(new_length) { data = (float *)malloc(sizeof(T) * new_length); }\n"
 "      DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
-"      const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
+"      const DynamicArray<T>& operator = (const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
 "\n"
 "      ~DynamicArray() { if (data) free(data); }\n"
 "\n"
@@ -3644,7 +3644,7 @@ static const char *cpp_classes = ""
 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
 "class CollectionIterator {\n"
 "public:\n"
-"      CollectionIterator() : t(iter.ptr), init(false) { iter.valid= false; }\n"
+"      CollectionIterator() : t(iter.ptr), init(false) { iter.valid = false; }\n"
 "      ~CollectionIterator(void) { if (init) Tend(&iter); };\n"
 "\n"
 "      operator bool(void)\n"
@@ -3653,7 +3653,7 @@ static const char *cpp_classes = ""
 "\n"
 "      T& operator*(void) { return t; }\n"
 "      T* operator->(void) { return &t; }\n"
-"      bool operator==(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
+"      bool operator == (const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
 "{ return iter.valid == other.iter.valid; }\n"
 "      bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
 "{ return iter.valid != other.iter.valid; }\n"
@@ -3662,7 +3662,7 @@ static const char *cpp_classes = ""
 "      { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA *)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
 "\n"
 "private:\n"
-"      const CollectionIterator<T, Tbegin, Tnext, Tend>& operator="
+"      const CollectionIterator<T, Tbegin, Tnext, Tend>& operator = "
 "(const CollectionIterator<T, Tbegin, Tnext, Tend>& copy) {}\n"
 ""
 "      CollectionPropertyIterator iter;\n"
index 79085538a3c31aea7e9bcf07a5652275ddf404c3..34c4fbfc6093a7afbe74403a248a6a23c1d4f820 100644 (file)
@@ -3126,6 +3126,13 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
                {0, NULL, 0, NULL, NULL}
        };
 
+       static EnumPropertyItem vsync_items[] = {
+               {VSYNC_OFF, "OFF", 0, "Off", "Disables vsync"},
+               {VSYNC_ON, "ON", 0, "On", "Enables vsync"},
+               {VSYNC_ADAPTIVE, "ADAPTIVE", 0, "Adaptive", "Enables adaptive vsync (if supported)"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
        static EnumPropertyItem storage_items[] = {
                {RAS_STORE_AUTO, "AUTO", 0, "Auto Select", "Chooses the best supported mode"},
                {RAS_STORE_IMMEDIATE, "IMMEDIATE", 0, "Immediate Mode", "Slowest performance, requires OpenGL (any version)"},
@@ -3152,6 +3159,11 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
        RNA_def_property_range(prop, 4, 10000);
        RNA_def_property_ui_text(prop, "Resolution Y", "Number of vertical pixels in the screen");
        RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop = RNA_def_property(srna, "vsync", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "vsync");
+       RNA_def_property_enum_items(prop, vsync_items);
+       RNA_def_property_ui_text(prop, "Vsync", "Change vsync settings");
        
        prop = RNA_def_property(srna, "samples", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "aasamples");
index b0570a7d67394464f61692e859b1f88c4ea1194d..49a7de47fc3cb240ae017ef130f685be6593dc3f 100644 (file)
@@ -232,6 +232,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
                case 13:
                case 15:
                case 16:
+               case 17:
                        GPU_stack_link(mat, names[node->custom1], in, out);
                        break;
                case 4:
index 235cb560a99a45aae89aa502699e0accbd5cd4f4..37e527f611aca98fb17ac329e093a68beda5496b 100644 (file)
@@ -80,12 +80,13 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe
 static void unique_name(bNode *node)
 {
        TexNodeOutput *tno = (TexNodeOutput *)node->storage;
-       char *new_name = NULL;
+       char new_name[sizeof(tno->name)];
        int new_len = 0;
        int suffix;
        bNode *i;
        char *name = tno->name;
        
+       new_name[0] = '\0';
        i = node;
        while (i->prev) i = i->prev;
        for (; i; i = i->next) {
@@ -96,7 +97,7 @@ static void unique_name(bNode *node)
                        continue;
                }
 
-               if (!new_name) {
+               if (new_name[0] == '\0') {
                        int len = strlen(name);
                        if (len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) {
                                new_len = len;
@@ -107,17 +108,15 @@ static void unique_name(bNode *node)
                                if (new_len > (sizeof(tno->name) - 1))
                                        new_len = (sizeof(tno->name) - 1);
                        }
-                       
-                       new_name = MEM_mallocN(new_len + 1, "new_name");
-                       strcpy(new_name, name);
+
+                       BLI_strncpy(new_name, name, sizeof(tno->name));
                        name = new_name;
                }
                sprintf(new_name + new_len - 4, ".%03d", ++suffix);
        }
        
-       if (new_name) {
-               strcpy(tno->name, new_name);
-               MEM_freeN(new_name);
+       if (new_name[0] != '\0') {
+               BLI_strncpy(tno->name, new_name, sizeof(tno->name));
        }
 }
 
index d293ca07c5a9f34186412362dcdb5c88f5dea643..918acb78193a99da295cf650b025224f356edff9 100644 (file)
@@ -187,6 +187,8 @@ __attribute__ ((format(printf, 3, 4)))
 ;
 
 void           wm_event_add(struct wmWindow *win, const struct wmEvent *event_to_add);
+void           wm_event_init_from_window(struct wmWindow *win, struct wmEvent *event);
+
 
                        /* at maximum, every timestep seconds it triggers event_type events */
 struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep);
index a83ce2efabfae0499ee2cceb3e4f69f0124f845c..2377a2cbc84bed5e5f6062310adec42f93c9d988 100644 (file)
@@ -132,6 +132,14 @@ void wm_event_free_all(wmWindow *win)
        }
 }
 
+void wm_event_init_from_window(wmWindow *win, wmEvent *event)
+{
+       /* make sure we don't copy any owned pointers */
+       BLI_assert(win->eventstate->tablet_data == NULL);
+
+       *event = *(win->eventstate);
+}
+
 /* ********************* notifiers, listeners *************** */
 
 static int wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, void *reference)
@@ -445,7 +453,9 @@ static void wm_handler_ui_cancel(bContext *C)
                nexthandler = handler->next;
 
                if (handler->ui_handle) {
-                       wmEvent event = *(win->eventstate);
+                       wmEvent event;
+
+                       wm_event_init_from_window(win, &event);
                        event.type = EVT_BUT_CANCEL;
                        handler->ui_handle(C, &event, handler->ui_userdata);
                }
index 39584882d0e956f80acb4c152744bedcf434b376..f1a9f6dc007b9843d22879e02b2fbae96b24f614 100644 (file)
@@ -978,7 +978,7 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg_op)
        uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
        uiEndBlock(C, block);
 
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
@@ -1751,7 +1751,7 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *UNUSED(arg_
        uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
        uiEndBlock(C, block);
        
-       event = *(win->eventstate);  /* XXX huh huh? make api call */
+       wm_event_init_from_window(win, &event);
        event.type = EVT_BUT_OPEN;
        event.val = KM_PRESS;
        event.customdata = but;
@@ -2988,7 +2988,7 @@ static void tweak_gesture_modal(bContext *C, const wmEvent *event)
                        if ((val = wm_gesture_evaluate(gesture))) {
                                wmEvent tevent;
 
-                               tevent = *(window->eventstate);
+                               wm_event_init_from_window(window, &tevent);
                                if (gesture->event_type == LEFTMOUSE)
                                        tevent.type = EVT_TWEAK_L;
                                else if (gesture->event_type == RIGHTMOUSE)
index e0595e3c8ab40910cd46f897f9479179992d28a5..062107f834ecc7384e39b4021985d65ed631f03b 100644 (file)
@@ -808,7 +808,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
                                 * currently it seems to be common practice to generate new event for, but probably
                                 * we'll need utility function for this? (sergey)
                                 */
-                               event = *(win->eventstate);
+                               wm_event_init_from_window(win, &event);
                                event.type = MOUSEMOVE;
                                event.prevx = event.x;
                                event.prevy = event.y;
@@ -957,7 +957,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
                                win->eventstate->x = wx;
                                win->eventstate->y = wy;
                                
-                               event = *(win->eventstate);  /* copy last state, like mouse coords */
+                               wm_event_init_from_window(win, &event);  /* copy last state, like mouse coords */
                                
                                /* activate region */
                                event.type = MOUSEMOVE;
@@ -1065,7 +1065,8 @@ static int wm_window_timer(const bContext *C)
                                else if (wt->event_type == TIMERAUTOSAVE)
                                        wm_autosave_timer(C, wm, wt);
                                else if (win) {
-                                       wmEvent event = *(win->eventstate);
+                                       wmEvent event;
+                                       wm_event_init_from_window(win, &event);
                                        
                                        event.type = wt->event_type;
                                        event.val = 0;
@@ -1323,6 +1324,16 @@ void wm_window_swap_buffers(wmWindow *win)
 #endif
 }
 
+void wm_window_set_swap_interval (wmWindow *win, int interval)
+{
+       GHOST_SetSwapInterval(win->ghostwin, interval);
+}
+
+int wm_window_get_swap_interval (wmWindow *win)
+{
+       return GHOST_GetSwapInterval(win->ghostwin);
+}
+
 
 /* ******************* exported api ***************** */
 
index 22fa2423f6117866424ec4a6d23d318c1c189e16..d7e938fec7c9a8da5ea7eb1d48b4cb4a31cfd302 100644 (file)
@@ -58,6 +58,8 @@ void          wm_window_lower                 (wmWindow *win);
 void           wm_window_set_size              (wmWindow *win, int width, int height);
 void           wm_window_get_position  (wmWindow *win, int *posx_r, int *posy_r);
 void           wm_window_swap_buffers  (wmWindow *win);
+void           wm_window_set_swap_interval     (wmWindow *win, int interval);
+int                    wm_window_get_swap_interval     (wmWindow *win);
 
 void           wm_get_cursor_position  (wmWindow *win, int *x, int *y);
 
index bb4c3fd2cbc087f1eb76f79ed0a248d907f09efc..5703527eae0c0040408f1256378aeefbf1a5a01f 100644 (file)
@@ -284,6 +284,14 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
                        canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
                else
                        canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
+
+               // Setup vsync
+               int previous_vsync = canvas->GetSwapInterval();
+               if (startscene->gm.vsync == VSYNC_ADAPTIVE)
+                       canvas->SetSwapInterval(-1);
+               else
+                       canvas->SetSwapInterval(startscene->gm.vsync); // VSYNC_OFF == 0, VSYNC_ON == 1, so this works
+
                RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
                RAS_IRasterizer* rasterizer = NULL;
                //Don't use displaylists with VBOs
@@ -663,6 +671,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
                }
                if (canvas)
                {
+                       canvas->SetSwapInterval(previous_vsync); // Set the swap interval back
                        delete canvas;
                        canvas = NULL;
                }
index 3bd1c02f12e5dc3d558de0c0d9370ae3087198ce..3089b3fd44d465f7d390f7ec07e546386ac10213 100644 (file)
@@ -66,6 +66,16 @@ void KX_BlenderCanvas::SwapBuffers()
        BL_SwapBuffers(m_win);
 }
 
+void KX_BlenderCanvas::SetSwapInterval(int interval)
+{
+       BL_SetSwapInterval(m_win, interval);
+}
+
+int    KX_BlenderCanvas::GetSwapInterval()
+{
+       return BL_GetSwapInterval(m_win);
+}
+
 void KX_BlenderCanvas::ResizeWindow(int width, int height)
 {
        // Not implemented for the embedded player
index c201d866efecb49a526015d52add3d639aa704a7..c5318b882fa8a75c900eb7c983c9a90ab12d88da 100644 (file)
@@ -80,6 +80,16 @@ public:
                void 
        SwapBuffers(
        );
+
+               void
+       SetSwapInterval(
+               int interval
+       );
+
+               int
+       GetSwapInterval(
+       );
+
                void 
        ResizeWindow(
                int width,
index 61598995040c8c1e24891bd5ee1be3017be4d0f9..6ed4866579cccc66337e89e9be3c06100a0e4fe0 100644 (file)
@@ -98,6 +98,16 @@ void BL_MakeDrawable(wmWindowManager *wm, wmWindow *win)
        wm_window_make_drawable(wm, win);
 }
 
+void BL_SetSwapInterval(struct wmWindow *win, int interval)
+{
+       wm_window_set_swap_interval(win, interval);
+}
+
+int BL_GetSwapInterval(struct wmWindow *win)
+{
+       return wm_window_get_swap_interval(win);
+}
+
 static void DisableForText()
 {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
index 54e76ff6489f2d38c8083a1a9549ff4d5a1b6477..8032d9a594abb4820ac4457853491db9567a39cc 100644 (file)
@@ -43,6 +43,8 @@ struct wmWindowManager;
 
 // special swapbuffers, that takes care of which area (viewport) needs to be swapped
 void   BL_SwapBuffers(struct wmWindow *win);
+void   BL_SetSwapInterval(struct wmWindow *win, int interval);
+int            BL_GetSwapInterval(struct wmWindow *win);
 
 void   BL_MakeDrawable(struct wmWindowManager *wm, struct wmWindow *win);
 
index bedee5d9a4757d1e250b1b01c6b9c6edf2822131..6f7a87804dcf73dd23771131d8ffaf7a3179efaa 100644 (file)
@@ -582,7 +582,12 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                m_canvas = new GPG_Canvas(window);
                if (!m_canvas)
                        return false;
-                               
+
+               if (gm->vsync == VSYNC_ADAPTIVE)
+                       m_canvas->SetSwapInterval(-1);
+               else
+                       m_canvas->SetSwapInterval(gm->vsync); // VSYNC_OFF == 0, VSYNC_ON == 1, so this works
+
                m_canvas->Init();
                if (gm->flag & GAME_SHOW_MOUSE)
                        m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
index a1d00dad0e1335040a7a7a93062a1ccaebf3c879..e0559385ee64ab81ff649833ca493fa46c27fca9 100644 (file)
@@ -107,6 +107,20 @@ void GPG_Canvas::SwapBuffers()
        }
 }
 
+void GPG_Canvas::SetSwapInterval(int interval)
+{
+       if (m_window)
+               m_window->setSwapInterval(interval);
+}
+
+int GPG_Canvas::GetSwapInterval()
+{
+       if (m_window)
+               return m_window->getSwapInterval();
+
+       return 0;
+}
+
 void GPG_Canvas::ResizeWindow(int width, int height)
 {
        if (m_window->getState() == GHOST_kWindowStateFullScreen)
index 6168d96b3371cade1e64dce91e9abcf01514fad2..6e1f86cac0e365a015549628006c5c8107083f7e 100644 (file)
@@ -55,6 +55,9 @@ public:
        virtual void SetMousePosition(int x, int y);
        virtual void SetMouseState(RAS_MouseState mousestate);
        virtual void SwapBuffers();
+       virtual void SetSwapInterval(int interval);
+       virtual int     GetSwapInterval();
+
        virtual int GetMouseX(int x) { return x; }
        virtual int GetMouseY(int y) { return y; }
        virtual float GetMouseNormalizedX(int x);
index 58996f7b86fe43c5e4559ba61486a4b6a8286f58..e595f24a6624578d7f524c059375f58bad0e5170 100644 (file)
@@ -1372,6 +1372,29 @@ static PyObject *gPyGetMipmapping(PyObject *)
        return PyLong_FromLong(gp_Rasterizer->GetMipmapping());
 }
 
+static PyObject *gPySetVsync(PyObject *, PyObject *args)
+{
+       int interval;
+
+       if (!PyArg_ParseTuple(args, "i:setVsync", &interval))
+               return NULL;
+
+       if (interval < VSYNC_OFF || interval > VSYNC_ADAPTIVE) {
+               PyErr_SetString(PyExc_ValueError, "Rasterizer.setVsync(value): value must be VSYNC_OFF, VSYNC_ON, or VSYNC_ADAPTIVE");
+               return NULL;
+       }
+
+       if (interval == VSYNC_ADAPTIVE)
+               interval = -1;
+       gp_Canvas->SetSwapInterval(interval);
+       Py_RETURN_NONE;
+}
+
+static PyObject *gPyGetVsync(PyObject *)
+{
+       return PyLong_FromLong(gp_Canvas->GetSwapInterval());
+}
+
 static struct PyMethodDef rasterizer_methods[] = {
        {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
         METH_VARARGS, "getWindowWidth doc"},
@@ -1417,6 +1440,8 @@ static struct PyMethodDef rasterizer_methods[] = {
        {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""},
        {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""},
        {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""},
+       {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""},
+       {"getVsync", (PyCFunction) gPyGetVsync, METH_NOARGS, ""},
        { NULL, (PyCFunction) NULL, 0, NULL }
 };
 
@@ -2122,6 +2147,7 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene *startscene, Main *
                                                "'render':__import__('Rasterizer'), "
                                                "'events':__import__('GameKeys'), "
                                                "'constraints':__import__('PhysicsConstraints'), "
+                                               "'physics':__import__('PhysicsConstraints'),"
                                                "'types':__import__('GameTypes'), "
                                                "'texture':__import__('VideoTexture')});"
                           /* so we can do 'import bge.foo as bar' */
@@ -2130,6 +2156,7 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene *startscene, Main *
                                               "'bge.render':bge.render, "
                                               "'bge.events':bge.events, "
                                               "'bge.constraints':bge.constraints, "
+                                              "'bge.physics':bge.physics,"
                                               "'bge.types':bge.types, "
                                               "'bge.texture':bge.texture})"
                           );
@@ -2187,6 +2214,11 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
        KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NEAREST, RAS_IRasterizer::RAS_MIPMAP_NEAREST);
        KX_MACRO_addTypesToDict(d, RAS_MIPMAP_LINEAR, RAS_IRasterizer::RAS_MIPMAP_LINEAR);
 
+       /* for get/setVsync */
+       KX_MACRO_addTypesToDict(d, VSYNC_OFF, VSYNC_OFF);
+       KX_MACRO_addTypesToDict(d, VSYNC_ON, VSYNC_ON);
+       KX_MACRO_addTypesToDict(d, VSYNC_ADAPTIVE, VSYNC_ADAPTIVE);
+
        // XXXX Add constants here
 
        // Check for errors
index 1b1e43a52572ed0b9009f76f8f20005405c94ab2..9e8a6e8ccf64d970627785e6d2146240dab5d2d3 100644 (file)
@@ -105,6 +105,17 @@ public:
                void 
        SwapBuffers(
        )=0;
+       
+       virtual
+               void
+       SetSwapInterval(
+               int interval
+       )=0;
+
+       virtual
+               int
+       GetSwapInterval(
+       )=0;
  
        virtual 
                void