Skip to content

Commit

Permalink
Should not GuiTraceRay for quads beyond the floor until the far plane. (
Browse files Browse the repository at this point in the history
#1754)

* Should not look for quads beyond the floor.
* Account for no ground intersection on GuiTraceRay.
* Add SelectThroughGround cfg var to control ground penetration on GuiTraceRay.
Apply it into max length passed into GetQuadsOnRay (brings back ground
penetration).
* Intersect water plane when out of map bounds.
  • Loading branch information
saurtron authored Nov 24, 2024
1 parent 2203a5d commit a624c17
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
19 changes: 17 additions & 2 deletions rts/Game/TraceRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Sim/Units/UnitTypes/Factory.h"
#include "Sim/Weapons/PlasmaRepulser.h"
#include "Sim/Weapons/WeaponDef.h"
#include "System/GlobalConfig.h"
#include "System/SpringMath.h"

#include <algorithm>
Expand Down Expand Up @@ -403,10 +404,24 @@ float GuiTraceRay(
if (groundOnly)
return minRayLength;

// set maximum ray until ground intersection taking lenience into account later
float maxRayLength;
if (minRayLength >= 0.0) {
// normal intersection
maxRayLength = minRayLength;
} else if (waterRayLength >= 0.0) {
// out of map we still want to intersect somewhere if possible
maxRayLength = waterRayLength;
} else {
// pointing upwards
maxRayLength = length;
}
maxRayLength = std::min(maxRayLength + globalConfig.selectThroughGround, length);

CollisionQuery cq;

QuadFieldQuery qfQuery;
quadField.GetQuadsOnRay(qfQuery, start, dir, length);
quadField.GetQuadsOnRay(qfQuery, start, dir, maxRayLength);

for (const int quadIdx: *qfQuery.quads) {
const CQuadField::Quad& quad = quadField.GetQuad(quadIdx);
Expand Down Expand Up @@ -493,7 +508,7 @@ float GuiTraceRay(
}
}

if ((minRayLength > 0.0f) && ((minRayLength + 200.0f) < minIngressDist)) {
if ((minRayLength > 0.0f) && (maxRayLength < minIngressDist)) {
minIngressDist = minRayLength;

hitUnit = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions rts/System/GlobalConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ CONFIG(bool, DumpGameStateOnDesync).defaultValue(true).description("Enable writi
CONFIG(float, MinSimDrawBalance).defaultValue(0.15f).description("Percent of the time for simulation is minimum spend for drawing. E.g. if set to 0.15 then 15% of the total cpu time is exclusively reserved for drawing.");
CONFIG(int, MinDrawFPS).defaultValue(2).description("Defines how many frames per second should minimally be rendered. To reach this number we will delay simframes.");

CONFIG(float, SelectThroughGround).defaultValue(200.0f).minimumValue(0.0f).description("How far beyond the ground to allow selecting objects.");

void GlobalConfig::Init()
{
// Recommended semantics for "expert" type config values:
Expand Down Expand Up @@ -98,6 +100,8 @@ void GlobalConfig::Init()
minDrawFPS = configHandler->GetInt("MinDrawFPS");

teamHighlight = configHandler->GetInt("TeamHighlight");

selectThroughGround = configHandler->GetFloat("SelectThroughGround");
}
#endif

Expand Down
7 changes: 7 additions & 0 deletions rts/System/GlobalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class GlobalConfig {
* rendered. To reach this number we will delay simframes.
*/
int minDrawFPS;

/**
* @brief selection ground penetration
*
* Defines how far beyond the ground to allow selecting objects.
*/
float selectThroughGround;
};

extern GlobalConfig globalConfig;
Expand Down

0 comments on commit a624c17

Please sign in to comment.