speedup for EDBM_uv_vert_map_create(), reduce customdata lookups. also remove redunda...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 12 Jan 2013 20:01:09 +0000 (20:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 12 Jan 2013 20:01:09 +0000 (20:01 +0000)
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/editmesh_utils.c
source/blender/editors/transform/transform.c

index f5ab002..2ecbaf7 100644 (file)
@@ -130,7 +130,7 @@ struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace *
 
 void              EDBM_uv_vert_map_free(struct UvVertMap *vmap);
 struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
-struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, int selected, const float limit[2]);
+struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, bool use_select, const float limit[2]);
 
 void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag);
 void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);
index b95c8a0..4fd8538 100644 (file)
@@ -682,8 +682,10 @@ void undo_push_mesh(bContext *C, const char *name)
        undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL);
 }
 
-/* write comment here */
-UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float limit[2])
+/**
+ * Return a new UVVertMap from the editmesh
+ */
+UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float limit[2])
 {
        BMVert *ev;
        BMFace *efa;
@@ -696,6 +698,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float lim
        MLoopUV *luv;
        unsigned int a;
        int totverts, i, totuv;
+       const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
 
        BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
        
@@ -704,8 +707,9 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float lim
 
        /* generate UvMapVert array */
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT)))
+               if ((use_select == false) || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
                        totuv += efa->len;
+               }
        }
 
        if (totuv == 0) {
@@ -726,7 +730,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float lim
        
        a = 0;
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
+               if ((use_select == false) || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
                        i = 0;
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                                buf->tfindex = i;
@@ -761,7 +765,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float lim
                        /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
                        
                        l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
-                       luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                       luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
                        uv = luv->uv;
                        
                        lastv = NULL;
@@ -773,7 +777,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, const float lim
                                /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
                                
                                l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
-                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
                                uv2 = luv->uv;
                                
                                sub_v2_v2v2(uvdiff, uv2, uv);
@@ -831,6 +835,8 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_is
        BMFace **stack;
        int stacksize = 0;
 
+       const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
        BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
 
        totverts = em->bm->totvert;
@@ -843,8 +849,9 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_is
 
        /* generate UvElement array */
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT)))
+               if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
                        totuv += efa->len;
+               }
        }
 
        if (totuv == 0) {
@@ -869,7 +876,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_is
        j = 0;
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
                island_number[j++] = INVALID_ISLAND;
-               if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
+               if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
                        BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
                                buf->l = l;
                                buf->separate = 0;
@@ -898,7 +905,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_is
                        newvlist = v;
 
                        l = v->l;
-                       luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                       luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
                        uv = luv->uv;
 
                        lastv = NULL;
@@ -908,7 +915,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_is
                                next = iterv->next;
 
                                l = iterv->l;
-                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
                                uv2 = luv->uv;
 
                                sub_v2_v2v2(uvdiff, uv2, uv);
index 5b5e520..2f037de 100644 (file)
 #include "DNA_movieclip_types.h"
 #include "DNA_scene_types.h"  /* PET modes */
 
-#include "RNA_access.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
-#include "BLF_api.h"
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_ghash.h"
+#include "BLI_linklist.h"
+#include "BLI_smallhash.h"
 
 #include "BKE_nla.h"
 #include "BKE_bmesh.h"
@@ -69,6 +71,9 @@
 #include "BKE_unit.h"
 #include "BKE_mask.h"
 
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
 #include "ED_image.h"
 #include "ED_keyframing.h"
 #include "ED_screen.h"
 #include "ED_clip.h"
 #include "ED_mask.h"
 
-#include "UI_view2d.h"
 #include "WM_types.h"
 #include "WM_api.h"
 
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_linklist.h"
-#include "BLI_smallhash.h"
-#include "BLI_array.h"
-
+#include "UI_view2d.h"
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
 
+#include "RNA_access.h"
+
+#include "BLF_api.h"
+
 #include "transform.h"
 
 static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg);