[Bf-blender-cvs] [8c4295f3c3c] soc-2017-normal-tools: Cleanup: MLoopNorSpaceArray new 'flags' are not flags at all, they are mutually exclusive data type information.
Bastien Montagne
noreply at git.blender.org
Tue Feb 20 15:08:03 CET 2018
Commit: 8c4295f3c3c31ae52356712e6430e30bb04ff850
Author: Bastien Montagne
Date: Tue Feb 20 12:49:10 2018 +0100
Branches: soc-2017-normal-tools
https://developer.blender.org/rB8c4295f3c3c31ae52356712e6430e30bb04ff850
Cleanup: MLoopNorSpaceArray new 'flags' are not flags at all, they are mutually exclusive data type information.
Makes code easier to follow, and a tad safer too.
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/mesh_evaluate.c
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/editors/mesh/editmesh_tools.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index a50f4833370..9e985bdfe2c 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -209,7 +209,10 @@ typedef struct MLoopNorSpace {
float vec_ortho[3]; /* Third vector, orthogonal to vec_lnor and vec_ref. */
float ref_alpha; /* Reference angle, around vec_ortho, in ]0, pi] range (0.0 marks that space as invalid). */
float ref_beta; /* Reference angle, around vec_lnor, in ]0, 2pi] range (0.0 marks that space as invalid). */
- struct LinkNode *loops; /* All indices (uint_in_ptr) of loops using this lnor space (i.e. smooth fan of loops). */
+ /* All loops using this lnor space (i.e. smooth fan of loops), as (depending on owning MLoopNorSpaceArrary.flags):
+ * - Indices (uint_in_ptr), or
+ * - BMLoop pointers. */
+ struct LinkNode *loops;
char flags;
} MLoopNorSpace;
/**
@@ -218,22 +221,24 @@ typedef struct MLoopNorSpace {
enum {
MLNOR_SPACE_IS_SINGLE = 1 << 0,
};
+
/**
* Collection of #MLoopNorSpace basic storage & pre-allocation.
*/
typedef struct MLoopNorSpaceArray {
MLoopNorSpace **lspacearr; /* MLoop aligned array */
struct LinkNode *loops_pool; /* Allocated once, avoids to call BLI_linklist_prepend_arena() for each loop! */
+ char data_type; /* Whether we store loop indices, or pointers to BMLoop. */
struct MemArena *mem;
- char flags;
} MLoopNorSpaceArray;
/**
- * MLoopNorSpaceArray.flags
+ * MLoopNorSpaceArray.data_type
*/
enum {
- MLNOR_SPACEARR_LOOP_INDEX = 1 << 0,
- MLNOR_SPACEARR_BMLOOP_PTR = 1 << 1,
+ MLNOR_SPACEARR_LOOP_INDEX = 0,
+ MLNOR_SPACEARR_BMLOOP_PTR = 1,
};
+
void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops, const char flags);
void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr);
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 75f0596908d..47fcb089fc0 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2165,7 +2165,7 @@ static int split_faces_prepare_new_verts(
MLoop *ml = mloop;
MLoopNorSpace **lnor_space = lnors_spacearr->lspacearr;
- BLI_assert(lnors_spacearr->flags & MLNOR_SPACEARR_LOOP_INDEX);
+ BLI_assert(lnors_spacearr->data_type == MLNOR_SPACEARR_LOOP_INDEX);
for (int loop_idx = 0; loop_idx < num_loops; loop_idx++, ml++, lnor_space++) {
if (!BLI_BITMAP_TEST(done_loops, loop_idx)) {
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 203e1276213..2da7e0ceb78 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -444,7 +444,7 @@ cleanup:
MEM_freeN(fnors);
}
-void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops, const char flags)
+void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops, const char data_type)
{
if (!(lnors_spacearr->lspacearr && lnors_spacearr->loops_pool)) {
MemArena *mem;
@@ -456,8 +456,8 @@ void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoo
lnors_spacearr->lspacearr = BLI_memarena_calloc(mem, sizeof(MLoopNorSpace *) * (size_t)numLoops);
lnors_spacearr->loops_pool = BLI_memarena_alloc(mem, sizeof(LinkNode) * (size_t)numLoops);
}
- BLI_assert(!((flags & MLNOR_SPACEARR_BMLOOP_PTR) && (flags & MLNOR_SPACEARR_LOOP_INDEX)));
- lnors_spacearr->flags = flags;
+ BLI_assert(ELEM(data_type, MLNOR_SPACEARR_BMLOOP_PTR, MLNOR_SPACEARR_LOOP_INDEX));
+ lnors_spacearr->data_type = data_type;
}
void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr)
@@ -560,8 +560,8 @@ void BKE_lnor_space_add_loop(
MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space,
const int ml_index, void *bm_loop, const bool is_single)
{
- BLI_assert(((lnors_spacearr->flags & MLNOR_SPACEARR_LOOP_INDEX) && bm_loop == NULL) ||
- ((lnors_spacearr->flags & MLNOR_SPACEARR_BMLOOP_PTR) && bm_loop != NULL));
+ BLI_assert((lnors_spacearr->data_type == MLNOR_SPACEARR_LOOP_INDEX && bm_loop == NULL) ||
+ (lnors_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR && bm_loop != NULL));
lnors_spacearr->lspacearr[ml_index] = lnor_space;
if (bm_loop == NULL) {
@@ -1515,7 +1515,7 @@ static void mesh_normals_loop_custom_set(
}
}
- BLI_assert(lnors_spacearr.flags & MLNOR_SPACEARR_LOOP_INDEX);
+ BLI_assert(lnors_spacearr.data_type == MLNOR_SPACEARR_LOOP_INDEX);
/* Now, check each current smooth fan (one lnor space per smooth fan!), and if all its matching custom lnors
* are not (enough) equal, add sharp edges as needed.
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index ae90982b805..d0409eb8bbb 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1079,7 +1079,7 @@ void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all)
BM_mesh_elem_index_ensure(bm, BM_FACE);
- BLI_assert(bm->lnor_spacearr->flags & MLNOR_SPACEARR_BMLOOP_PTR);
+ BLI_assert(bm->lnor_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR);
MLoopNorSpace **lnors_spaces = bm->lnor_spacearr->lspacearr;
/* TODO this has to be redone, way more looping than needed here ;) */
@@ -1246,7 +1246,7 @@ static int bm_loop_normal_mark_indiv(BMesh *bm, BLI_bitmap *loops)
BM_mesh_elem_index_ensure(bm, BM_LOOP);
BLI_assert(bm->lnor_spacearr != NULL);
- BLI_assert(bm->lnor_spacearr->flags & MLNOR_SPACEARR_BMLOOP_PTR);
+ BLI_assert(bm->lnor_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR);
/* Goes from last selected to the first selected element. */
for (ese = bm->selected.last; ese; ese = ese->prev) {
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index e4eb4a5183b..c721fceb33a 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -6411,7 +6411,7 @@ static void merge_loop(bContext *C, LoopNormalData *ld)
BLI_SMALLSTACK_DECLARE(clnors, short *);
- BLI_assert(bm->lnor_spacearr->flags & MLNOR_SPACEARR_BMLOOP_PTR);
+ BLI_assert(bm->lnor_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR);
custom_loops_tag(bm, false);
@@ -6461,7 +6461,7 @@ static void split_loop(bContext *C)
BMLoop *l, *l_curr, *l_first;
BMIter fiter;
- BLI_assert(bm->lnor_spacearr->flags & MLNOR_SPACEARR_BMLOOP_PTR);
+ BLI_assert(bm->lnor_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR);
custom_loops_tag(bm, true);
More information about the Bf-blender-cvs
mailing list