Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should not GuiTraceRay for quads beyond the floor until the far plane. #1754

Merged
merged 5 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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