Cleanup: Simplify loop syntax, decrease variable scope

Mostly changes split from D14685, which refactors the hide flags.
This commit is contained in:
Hans Goudey 2022-05-15 15:41:13 +02:00
parent 3e989e8c8d
commit e46a38942a
2 changed files with 45 additions and 86 deletions

View File

@ -1212,10 +1212,11 @@ static BLI_bitmap *looptri_no_hidden_map_get(const MPoly *mpoly,
int looptri_no_hidden_len = 0;
int looptri_iter = 0;
const MPoly *mp = mpoly;
int i_poly = 0;
while (looptri_iter != looptri_len) {
int mp_totlooptri = mp->totloop - 2;
if (mp->flag & ME_HIDE) {
int mp_totlooptri = mpoly[i_poly].totloop - 2;
const MPoly &mp = mpoly[i_poly];
if (mp.flag & ME_HIDE) {
looptri_iter += mp_totlooptri;
}
else {
@ -1225,7 +1226,7 @@ static BLI_bitmap *looptri_no_hidden_map_get(const MPoly *mpoly,
looptri_no_hidden_len++;
}
}
mp++;
i_poly++;
}
*r_looptri_active_len = looptri_no_hidden_len;

View File

@ -115,18 +115,13 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag)
void paintface_hide(bContext *C, Object *ob, const bool unselected)
{
Mesh *me;
MPoly *mpoly;
int a;
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (me == NULL || me->totpoly == 0) {
return;
}
mpoly = me->mpoly;
a = me->totpoly;
while (a--) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mpoly = &me->mpoly[i];
if ((mpoly->flag & ME_HIDE) == 0) {
if (((mpoly->flag & ME_FACE_SEL) == 0) == unselected) {
mpoly->flag |= ME_HIDE;
@ -136,8 +131,6 @@ void paintface_hide(bContext *C, Object *ob, const bool unselected)
if (mpoly->flag & ME_HIDE) {
mpoly->flag &= ~ME_FACE_SEL;
}
mpoly++;
}
BKE_mesh_flush_hidden_from_polys(me);
@ -147,23 +140,17 @@ void paintface_hide(bContext *C, Object *ob, const bool unselected)
void paintface_reveal(bContext *C, Object *ob, const bool select)
{
Mesh *me;
MPoly *mpoly;
int a;
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (me == NULL || me->totpoly == 0) {
return;
}
mpoly = me->mpoly;
a = me->totpoly;
while (a--) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mpoly = &me->mpoly[i];
if (mpoly->flag & ME_HIDE) {
SET_FLAG_FROM_TEST(mpoly->flag, select, ME_FACE_SEL);
mpoly->flag &= ~ME_HIDE;
}
mpoly++;
}
BKE_mesh_flush_hidden_from_polys(me);
@ -175,9 +162,6 @@ void paintface_reveal(bContext *C, Object *ob, const bool select)
static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bool select)
{
MPoly *mp;
MLoop *ml;
int a, b;
bool do_it = true;
bool mark = false;
@ -186,20 +170,20 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
if (index != (uint)-1) {
/* only put face under cursor in array */
mp = &me->mpoly[index];
MPoly *mp = &me->mpoly[index];
BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
BLI_BITMAP_ENABLE(poly_tag, index);
}
else {
/* fill array by selection */
mp = me->mpoly;
for (a = 0; a < me->totpoly; a++, mp++) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mp = &me->mpoly[i];
if (mp->flag & ME_HIDE) {
/* pass */
}
else if (mp->flag & ME_FACE_SEL) {
BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
BLI_BITMAP_ENABLE(poly_tag, a);
BLI_BITMAP_ENABLE(poly_tag, i);
}
}
}
@ -208,17 +192,17 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
do_it = false;
/* expand selection */
mp = me->mpoly;
for (a = 0; a < me->totpoly; a++, mp++) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mp = &me->mpoly[i];
if (mp->flag & ME_HIDE) {
continue;
}
if (!BLI_BITMAP_TEST(poly_tag, a)) {
if (!BLI_BITMAP_TEST(poly_tag, i)) {
mark = false;
ml = me->mloop + mp->loopstart;
for (b = 0; b < mp->totloop; b++, ml++) {
MLoop *ml = me->mloop + mp->loopstart;
for (int b = 0; b < mp->totloop; b++, ml++) {
if ((me->medge[ml->e].flag & ME_SEAM) == 0) {
if (BLI_BITMAP_TEST(edge_tag, ml->e)) {
mark = true;
@ -228,7 +212,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
}
if (mark) {
BLI_BITMAP_ENABLE(poly_tag, a);
BLI_BITMAP_ENABLE(poly_tag, i);
BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
do_it = true;
}
@ -238,8 +222,9 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
MEM_freeN(edge_tag);
for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) {
if (BLI_BITMAP_TEST(poly_tag, a)) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mp = &me->mpoly[i];
if (BLI_BITMAP_TEST(poly_tag, i)) {
SET_FLAG_FROM_TEST(mp->flag, select, ME_FACE_SEL);
}
}
@ -249,10 +234,9 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const bool select)
{
Mesh *me;
uint index = (uint)-1;
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (me == NULL || me->totpoly == 0) {
return;
}
@ -270,11 +254,7 @@ void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const b
bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool flush_flags)
{
Mesh *me;
MPoly *mpoly;
int a;
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (me == NULL) {
return false;
}
@ -282,22 +262,19 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
mpoly = me->mpoly;
a = me->totpoly;
while (a--) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mpoly = &me->mpoly[i];
if ((mpoly->flag & ME_HIDE) == 0 && mpoly->flag & ME_FACE_SEL) {
action = SEL_DESELECT;
break;
}
mpoly++;
}
}
bool changed = false;
mpoly = me->mpoly;
a = me->totpoly;
while (a--) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mpoly = &me->mpoly[i];
if ((mpoly->flag & ME_HIDE) == 0) {
switch (action) {
case SEL_SELECT:
@ -318,7 +295,6 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl
break;
}
}
mpoly++;
}
if (changed) {
@ -331,30 +307,25 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl
bool paintface_minmax(Object *ob, float r_min[3], float r_max[3])
{
const Mesh *me;
const MPoly *mp;
const MLoop *ml;
const MVert *mvert;
int a, b;
bool ok = false;
float vec[3], bmat[3][3];
me = BKE_mesh_from_object(ob);
const Mesh *me = BKE_mesh_from_object(ob);
if (!me || !me->mloopuv) {
return ok;
}
const MVert *mvert = me->mvert;
copy_m3_m4(bmat, ob->obmat);
mvert = me->mvert;
mp = me->mpoly;
for (a = me->totpoly; a > 0; a--, mp++) {
for (int i = 0; i < me->totpoly; i++) {
MPoly *mp = &me->mpoly[i];
if (mp->flag & ME_HIDE || !(mp->flag & ME_FACE_SEL)) {
continue;
}
ml = me->mloop + mp->loopstart;
for (b = 0; b < mp->totloop; b++, ml++) {
const MLoop *ml = me->mloop + mp->loopstart;
for (int b = 0; b < mp->totloop; b++, ml++) {
mul_v3_m3v3(vec, bmat, mvert[ml->v].co);
add_v3_v3v3(vec, vec, ob->obmat[3]);
minmax_v3v3_v3(r_min, r_max, vec);
@ -371,14 +342,13 @@ bool paintface_mouse_select(struct bContext *C,
const struct SelectPick_Params *params,
Object *ob)
{
Mesh *me;
MPoly *mpoly_sel = NULL;
uint index;
bool changed = false;
bool found = false;
/* Get the face under the cursor */
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (ED_mesh_pick_face(C, ob, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) {
if (index < me->totpoly) {
@ -493,11 +463,7 @@ void paintvert_tag_select_update(struct bContext *C, struct Object *ob)
bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
{
Mesh *me;
MVert *mvert;
int a;
me = BKE_mesh_from_object(ob);
Mesh *me = BKE_mesh_from_object(ob);
if (me == NULL) {
return false;
}
@ -505,21 +471,18 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
mvert = me->mvert;
a = me->totvert;
while (a--) {
for (int i = 0; i < me->totvert; i++) {
MVert *mvert = &me->mvert[i];
if ((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) {
action = SEL_DESELECT;
break;
}
mvert++;
}
}
bool changed = false;
mvert = me->mvert;
a = me->totvert;
while (a--) {
for (int i = 0; i < me->totvert; i++) {
MVert *mvert = &me->mvert[i];
if ((mvert->flag & ME_HIDE) == 0) {
switch (action) {
case SEL_SELECT:
@ -540,7 +503,6 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
break;
}
}
mvert++;
}
if (changed) {
@ -565,9 +527,6 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags)
{
Mesh *me = BKE_mesh_from_object(ob);
MVert *mv;
MDeformVert *dv;
int a, tot;
if (me == NULL || me->dvert == NULL) {
return;
@ -577,10 +536,9 @@ void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags)
paintvert_deselect_all_visible(ob, SEL_DESELECT, false);
}
dv = me->dvert;
tot = me->totvert;
for (a = 0, mv = me->mvert; a < tot; a++, mv++, dv++) {
for (int i = 0; i < me->totvert; i++) {
MVert *mv = &me->mvert[i];
MDeformVert *dv = &me->dvert[i];
if ((mv->flag & ME_HIDE) == 0) {
if (dv->dw == NULL) {
/* if null weight then not grouped */