BMesh: store stackdepth as an index
Avoids -1 all over.
This commit is contained in:
@@ -217,7 +217,7 @@ typedef struct BMesh {
|
||||
/* operator api stuff (must be all NULL or all alloc'd) */
|
||||
struct BLI_mempool *vtoolflagpool, *etoolflagpool, *ftoolflagpool;
|
||||
|
||||
int stackdepth;
|
||||
int toolflag_index;
|
||||
struct BMOperator *currentop;
|
||||
|
||||
CustomData vdata, edata, ldata, pdata;
|
||||
|
||||
@@ -143,7 +143,7 @@ BMesh *BM_mesh_create(const BMAllocTemplate *allocsize)
|
||||
bm_mempool_init(bm, allocsize);
|
||||
|
||||
/* allocate one flag pool that we don't get rid of. */
|
||||
bm->stackdepth = 1;
|
||||
bm->toolflag_index = 0;
|
||||
bm->totflags = 0;
|
||||
|
||||
CustomData_reset(&bm->vdata);
|
||||
@@ -246,7 +246,7 @@ void BM_mesh_clear(BMesh *bm)
|
||||
/* allocate the memory pools for the mesh elements */
|
||||
bm_mempool_init(bm, &bm_mesh_allocsize_default);
|
||||
|
||||
bm->stackdepth = 1;
|
||||
bm->toolflag_index = 0;
|
||||
bm->totflags = 0;
|
||||
|
||||
CustomData_reset(&bm->vdata);
|
||||
|
||||
@@ -41,38 +41,38 @@
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE short _bmo_elem_flag_test(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
||||
{
|
||||
return oflags[bm->stackdepth - 1].f & oflag;
|
||||
return oflags[bm->toolflag_index].f & oflag;
|
||||
}
|
||||
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
||||
{
|
||||
return (oflags[bm->stackdepth - 1].f & oflag) != 0;
|
||||
return (oflags[bm->toolflag_index].f & oflag) != 0;
|
||||
}
|
||||
|
||||
ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE void _bmo_elem_flag_enable(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
||||
{
|
||||
oflags[bm->stackdepth - 1].f |= oflag;
|
||||
oflags[bm->toolflag_index].f |= oflag;
|
||||
}
|
||||
|
||||
ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE void _bmo_elem_flag_disable(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
||||
{
|
||||
oflags[bm->stackdepth - 1].f &= (short)~oflag;
|
||||
oflags[bm->toolflag_index].f &= (short)~oflag;
|
||||
}
|
||||
|
||||
ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE void _bmo_elem_flag_set(BMesh *bm, BMFlagLayer *oflags, const short oflag, int val)
|
||||
{
|
||||
if (val) oflags[bm->stackdepth - 1].f |= oflag;
|
||||
else oflags[bm->stackdepth - 1].f &= (short)~oflag;
|
||||
if (val) oflags[bm->toolflag_index].f |= oflag;
|
||||
else oflags[bm->toolflag_index].f &= (short)~oflag;
|
||||
}
|
||||
|
||||
ATTR_NONNULL(1, 2)
|
||||
BLI_INLINE void _bmo_elem_flag_toggle(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
||||
{
|
||||
oflags[bm->stackdepth - 1].f ^= oflag;
|
||||
oflags[bm->toolflag_index].f ^= oflag;
|
||||
}
|
||||
|
||||
ATTR_NONNULL(1, 2)
|
||||
|
||||
@@ -97,12 +97,12 @@ void BMO_op_flag_disable(BMesh *UNUSED(bm), BMOperator *op, const int op_flag)
|
||||
*/
|
||||
void BMO_push(BMesh *bm, BMOperator *UNUSED(op))
|
||||
{
|
||||
bm->stackdepth++;
|
||||
bm->toolflag_index++;
|
||||
|
||||
BLI_assert(bm->totflags > 0);
|
||||
|
||||
/* add flag layer, if appropriate */
|
||||
if (bm->stackdepth > 1)
|
||||
if (bm->toolflag_index > 0)
|
||||
bmo_flag_layer_alloc(bm);
|
||||
else
|
||||
bmo_flag_layer_clear(bm);
|
||||
@@ -117,10 +117,10 @@ void BMO_push(BMesh *bm, BMOperator *UNUSED(op))
|
||||
*/
|
||||
void BMO_pop(BMesh *bm)
|
||||
{
|
||||
if (bm->stackdepth > 1)
|
||||
if (bm->toolflag_index > 0)
|
||||
bmo_flag_layer_free(bm);
|
||||
|
||||
bm->stackdepth--;
|
||||
bm->toolflag_index--;
|
||||
}
|
||||
|
||||
|
||||
@@ -214,11 +214,11 @@ void BMO_op_exec(BMesh *bm, BMOperator *op)
|
||||
|
||||
BMO_push(bm, op);
|
||||
|
||||
if (bm->stackdepth == 2)
|
||||
if (bm->toolflag_index == 1)
|
||||
bmesh_edit_begin(bm, op->type_flag);
|
||||
op->exec(bm, op);
|
||||
|
||||
if (bm->stackdepth == 2)
|
||||
if (bm->toolflag_index == 1)
|
||||
bmesh_edit_end(bm, op->type_flag);
|
||||
|
||||
BMO_pop(bm);
|
||||
|
||||
Reference in New Issue
Block a user