Cleanup: disambiguate variable naming relating to selection

- Both "hit_resullt" & "hitresult" were used in the same functions
  with different meanings. Rename `hitresult` to `select_id`,
  a convention already widely used.

- Armature selection shadowed "result", using it to store two kinds
  of selection results, use "hit_result" for GPUSelectResult.
This commit is contained in:
Campbell Barton
2024-10-19 10:05:45 +11:00
parent 8da0cfa000
commit ba77368455
2 changed files with 38 additions and 38 deletions

View File

@@ -642,17 +642,17 @@ static EditBone *get_nearest_editbonepoint(
{
GPUSelectBuffer buffer;
struct Result {
uint hitresult;
uint select_id;
Base *base;
EditBone *ebone;
};
Result *result = nullptr;
Result result_cycle{};
result_cycle.hitresult = -1;
result_cycle.select_id = -1;
result_cycle.base = nullptr;
result_cycle.ebone = nullptr;
Result result_bias{};
result_bias.hitresult = -1;
result_bias.select_id = -1;
result_bias.base = nullptr;
result_bias.ebone = nullptr;
@@ -723,9 +723,9 @@ cache_end:
/* See if there are any selected bones in this group */
if (hits > 0) {
if (hits == 1) {
result_bias.hitresult = buffer.storage[0].id;
result_bias.select_id = buffer.storage[0].id;
result_bias.base = ED_armature_base_and_ebone_from_select_buffer(
bases, result_bias.hitresult, &result_bias.ebone);
bases, result_bias.select_id, &result_bias.ebone);
}
else {
int bias_max = INT_MIN;
@@ -763,12 +763,12 @@ cache_end:
int min_depth = INT_MAX;
for (int i = 0; i < hits; i++) {
const GPUSelectResult &result = buffer.storage[i];
const uint hitresult = result.id;
const GPUSelectResult &hit_result = buffer.storage[i];
const uint select_id = hit_result.id;
Base *base = nullptr;
EditBone *ebone;
base = ED_armature_base_and_ebone_from_select_buffer(bases, hitresult, &ebone);
base = ED_armature_base_and_ebone_from_select_buffer(bases, select_id, &ebone);
/* If this fails, selection code is setting the selection ID's incorrectly. */
BLI_assert(base && ebone);
@@ -780,13 +780,13 @@ cache_end:
{
int bias;
/* clicks on bone points get advantage */
if (hitresult & (BONESEL_ROOT | BONESEL_TIP)) {
if (select_id & (BONESEL_ROOT | BONESEL_TIP)) {
/* but also the unselected one */
if (findunsel) {
if ((hitresult & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) {
if ((select_id & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) {
bias = 4;
}
else if ((hitresult & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) {
else if ((select_id & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) {
bias = 4;
}
else {
@@ -815,14 +815,14 @@ cache_end:
if (bias > bias_max) {
bias_max = bias;
result_bias.hitresult = hitresult;
result_bias.select_id = select_id;
result_bias.base = base;
result_bias.ebone = ebone;
}
else if (bias == bias_max && do_nearest) {
if (min_depth > result.depth) {
min_depth = result.depth;
result_bias.hitresult = hitresult;
if (min_depth > hit_result.depth) {
min_depth = hit_result.depth;
result_bias.select_id = select_id;
result_bias.base = base;
result_bias.ebone = ebone;
}
@@ -831,8 +831,8 @@ cache_end:
/* Cycle selected items (objects & bones). */
if (use_cycle) {
cycle_order.test.ob = hitresult & 0xFFFF;
cycle_order.test.bone = (hitresult & ~BONESEL_ANY) >> 16;
cycle_order.test.ob = select_id & 0xFFFF;
cycle_order.test.bone = (select_id & ~BONESEL_ANY) >> 16;
if (ebone == ebone_active_orig) {
BLI_assert(cycle_order.test.ob == cycle_order.offset.ob);
BLI_assert(cycle_order.test.bone == cycle_order.offset.bone);
@@ -851,7 +851,7 @@ cache_end:
(cycle_order.test.as_u32 && (cycle_order.test.as_u32 < cycle_order.best.as_u32)))
{
cycle_order.best = cycle_order.test;
result_cycle.hitresult = hitresult;
result_cycle.select_id = select_id;
result_cycle.base = base;
result_cycle.ebone = ebone;
}
@@ -861,17 +861,17 @@ cache_end:
result = (use_cycle && result_cycle.ebone) ? &result_cycle : &result_bias;
if (result->hitresult != -1) {
if (result->select_id != -1) {
*r_base = result->base;
*r_selmask = 0;
if (result->hitresult & BONESEL_ROOT) {
if (result->select_id & BONESEL_ROOT) {
*r_selmask |= BONE_ROOTSEL;
}
if (result->hitresult & BONESEL_TIP) {
if (result->select_id & BONESEL_TIP) {
*r_selmask |= BONE_TIPSEL;
}
if (result->hitresult & BONESEL_BONE) {
if (result->select_id & BONESEL_BONE) {
*r_selmask |= BONE_SELECTED;
}
return result->ebone;

View File

@@ -1911,15 +1911,15 @@ static bool bone_mouse_select_menu(bContext *C,
for (const GPUSelectResult &hit_result : hit_results) {
void *bone_ptr = nullptr;
Base *bone_base = nullptr;
uint hitresult = hit_result.id;
uint select_id = hit_result.id;
if (!(hitresult & BONESEL_ANY)) {
if (!(select_id & BONESEL_ANY)) {
/* To avoid including objects in selection. */
continue;
}
hitresult &= ~BONESEL_ANY;
const uint hit_object = hitresult & 0xFFFF;
select_id &= ~BONESEL_ANY;
const uint hit_object = select_id & 0xFFFF;
/* Find the hit bone base (armature object). */
CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
@@ -1936,7 +1936,7 @@ static bool bone_mouse_select_menu(bContext *C,
/* Determine what the current bone is */
if (is_editmode) {
const uint hit_bone = (hitresult & ~BONESEL_ANY) >> 16;
const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
bArmature *arm = static_cast<bArmature *>(bone_base->object->data);
EditBone *ebone = static_cast<EditBone *>(BLI_findlink(arm->edbo, hit_bone));
if (ebone && !(ebone->flag & BONE_UNSELECTABLE)) {
@@ -1944,7 +1944,7 @@ static bool bone_mouse_select_menu(bContext *C,
}
}
else {
const uint hit_bone = (hitresult & ~BONESEL_ANY) >> 16;
const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
bPoseChannel *pchan = static_cast<bPoseChannel *>(
BLI_findlink(&bone_base->object->pose->chanbase, hit_bone));
if (pchan && !(pchan->bone->flag & BONE_UNSELECTABLE)) {
@@ -2493,21 +2493,21 @@ static bool ed_object_select_pick_camera_track(bContext *C,
MovieTrackingTrack *track = nullptr;
for (int i = 0; i < hits; i++) {
const int hitresult = buffer.storage[i].id;
const int select_id = buffer.storage[i].id;
/* If there's bundles in buffer select bundles first,
* so non-camera elements should be ignored in buffer. */
if (basact->object->runtime->select_id != (hitresult & 0xFFFF)) {
if (basact->object->runtime->select_id != (select_id & 0xFFFF)) {
continue;
}
/* Index of bundle is 1<<16-based. if there's no "bone" index
* in height word, this buffer value belongs to camera. not to bundle. */
if ((hitresult & 0xFFFF0000) == 0) {
if ((select_id & 0xFFFF0000) == 0) {
continue;
}
track = BKE_tracking_track_get_for_selection_index(
&clip->tracking, hitresult >> 16, &tracksbase);
&clip->tracking, select_id >> 16, &tracksbase);
found = true;
break;
}
@@ -4021,27 +4021,27 @@ static bool do_meta_box_select(const ViewContext *vc, const rcti *rect, const eS
bool is_inside_stiff = false;
for (a = 0; a < hits; a++) {
const int hitresult = buffer.storage[a].id;
const int select_id = buffer.storage[a].id;
if (hitresult == -1) {
if (select_id == -1) {
continue;
}
const uint hit_object = hitresult & 0xFFFF;
const uint hit_object = select_id & 0xFFFF;
if (vc->obedit->runtime->select_id != hit_object) {
continue;
}
if (metaelem_id != (hitresult & 0xFFFF0000 & ~MBALLSEL_ANY)) {
if (metaelem_id != (select_id & 0xFFFF0000 & ~MBALLSEL_ANY)) {
continue;
}
if (hitresult & MBALLSEL_RADIUS) {
if (select_id & MBALLSEL_RADIUS) {
is_inside_radius = true;
break;
}
if (hitresult & MBALLSEL_STIFF) {
if (select_id & MBALLSEL_STIFF) {
is_inside_stiff = true;
break;
}