Skip to content

Commit

Permalink
Ease selection of entities behind nodes (#7739)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Oct 26, 2018
1 parent 622e223 commit 45b52f6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/raycast.cpp
Expand Up @@ -28,12 +28,22 @@ bool RaycastSort::operator() (const PointedThing &pt1,
// "nothing" can not be sorted
assert(pt1.type != POINTEDTHING_NOTHING);
assert(pt2.type != POINTEDTHING_NOTHING);
f32 pt1_distSq = pt1.distanceSq;

// Add some bonus when one of them is an object
if (pt1.type != pt2.type) {
if (pt1.type == POINTEDTHING_OBJECT)
pt1_distSq -= BS * BS;
else if (pt2.type == POINTEDTHING_OBJECT)
pt1_distSq += BS * BS;
}

// returns false if pt1 is nearer than pt2
if (pt1.distanceSq < pt2.distanceSq) {
if (pt1_distSq < pt2.distanceSq) {
return false;
}

if (pt1.distanceSq == pt2.distanceSq) {
if (pt1_distSq == pt2.distanceSq) {
// Sort them to allow only one order
if (pt1.type == POINTEDTHING_OBJECT)
return (pt2.type == POINTEDTHING_OBJECT
Expand Down

0 comments on commit 45b52f6

Please sign in to comment.