From b35d8d21fe036eb2bab22b6cfa431db5615cef33 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Tue, 5 Nov 2024 11:10:56 +0100 Subject: [PATCH 1/5] Should not look for quads beyond the floor. --- rts/Game/TraceRay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/Game/TraceRay.cpp b/rts/Game/TraceRay.cpp index 3323b8f081..589d300343 100644 --- a/rts/Game/TraceRay.cpp +++ b/rts/Game/TraceRay.cpp @@ -406,7 +406,7 @@ float GuiTraceRay( CollisionQuery cq; QuadFieldQuery qfQuery; - quadField.GetQuadsOnRay(qfQuery, start, dir, length); + quadField.GetQuadsOnRay(qfQuery, start, dir, minRayLength); for (const int quadIdx: *qfQuery.quads) { const CQuadField::Quad& quad = quadField.GetQuad(quadIdx); From cab5dd33031964883c1697a1074222d6731f8179 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Sun, 10 Nov 2024 09:20:52 +0100 Subject: [PATCH 2/5] Account for no ground intersection on GuiTraceRay. --- rts/Game/TraceRay.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rts/Game/TraceRay.cpp b/rts/Game/TraceRay.cpp index 589d300343..ee5521daae 100644 --- a/rts/Game/TraceRay.cpp +++ b/rts/Game/TraceRay.cpp @@ -403,10 +403,12 @@ float GuiTraceRay( if (groundOnly) return minRayLength; + const float maxRayLength = minRayLength < 0.0 ? length : minRayLength; + CollisionQuery cq; QuadFieldQuery qfQuery; - quadField.GetQuadsOnRay(qfQuery, start, dir, minRayLength); + quadField.GetQuadsOnRay(qfQuery, start, dir, maxRayLength); for (const int quadIdx: *qfQuery.quads) { const CQuadField::Quad& quad = quadField.GetQuad(quadIdx); From 76d1f1679bb5da083740e4942b598c0744274fff Mon Sep 17 00:00:00 2001 From: Saurtron Date: Sun, 10 Nov 2024 09:48:42 +0100 Subject: [PATCH 3/5] Add SelectThroughGround cfg var to control ground penetration on GuiTraceRay. Apply it into max length passed into GetQuadsOnRay (brings back ground penetration). --- rts/Game/TraceRay.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rts/Game/TraceRay.cpp b/rts/Game/TraceRay.cpp index ee5521daae..7ac3a154ea 100644 --- a/rts/Game/TraceRay.cpp +++ b/rts/Game/TraceRay.cpp @@ -18,6 +18,7 @@ #include "Sim/Units/UnitTypes/Factory.h" #include "Sim/Weapons/PlasmaRepulser.h" #include "Sim/Weapons/WeaponDef.h" +#include "System/Config/ConfigHandler.h" #include "System/SpringMath.h" #include @@ -25,6 +26,8 @@ #include "System/Misc/TracyDefs.h" +CONFIG(float, SelectThroughGround).defaultValue(200.0f).minimumValue(0.0f).description("Sets how far beyond the ground to allow selecting objects."); + ////////////////////////////////////////////////////////////////////// // Local/Helper functions ////////////////////////////////////////////////////////////////////// @@ -404,11 +407,13 @@ float GuiTraceRay( return minRayLength; const float maxRayLength = minRayLength < 0.0 ? length : minRayLength; + const float lenienceBuffer = configHandler->GetFloat("SelectThroughGround"); + const float lenientRayLength = std::min(maxRayLength + lenienceBuffer, length); CollisionQuery cq; QuadFieldQuery qfQuery; - quadField.GetQuadsOnRay(qfQuery, start, dir, maxRayLength); + quadField.GetQuadsOnRay(qfQuery, start, dir, lenientRayLength); for (const int quadIdx: *qfQuery.quads) { const CQuadField::Quad& quad = quadField.GetQuad(quadIdx); @@ -495,7 +500,7 @@ float GuiTraceRay( } } - if ((minRayLength > 0.0f) && ((minRayLength + 200.0f) < minIngressDist)) { + if ((minRayLength > 0.0f) && (lenientRayLength < minIngressDist)) { minIngressDist = minRayLength; hitUnit = nullptr; From 95b9a2e9b6fcf190c592fd8bc8590a22a6407496 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Sun, 10 Nov 2024 11:20:29 +0100 Subject: [PATCH 4/5] Intersect water plane when out of map bounds. --- rts/Game/TraceRay.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rts/Game/TraceRay.cpp b/rts/Game/TraceRay.cpp index 7ac3a154ea..9c3874479f 100644 --- a/rts/Game/TraceRay.cpp +++ b/rts/Game/TraceRay.cpp @@ -406,14 +406,25 @@ float GuiTraceRay( if (groundOnly) return minRayLength; - const float maxRayLength = minRayLength < 0.0 ? length : 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; + } const float lenienceBuffer = configHandler->GetFloat("SelectThroughGround"); - const float lenientRayLength = std::min(maxRayLength + lenienceBuffer, length); + maxRayLength = std::min(maxRayLength + lenienceBuffer, length); CollisionQuery cq; QuadFieldQuery qfQuery; - quadField.GetQuadsOnRay(qfQuery, start, dir, lenientRayLength); + quadField.GetQuadsOnRay(qfQuery, start, dir, maxRayLength); for (const int quadIdx: *qfQuery.quads) { const CQuadField::Quad& quad = quadField.GetQuad(quadIdx); @@ -500,7 +511,7 @@ float GuiTraceRay( } } - if ((minRayLength > 0.0f) && (lenientRayLength < minIngressDist)) { + if ((minRayLength > 0.0f) && (maxRayLength < minIngressDist)) { minIngressDist = minRayLength; hitUnit = nullptr; From e9f58acac99bcdc96313cbd2531cb82e6b43700a Mon Sep 17 00:00:00 2001 From: Saurtron Date: Mon, 11 Nov 2024 14:27:54 +0100 Subject: [PATCH 5/5] Move SelectThroughGround config variable to GlobalConfig. --- rts/Game/TraceRay.cpp | 7 ++----- rts/System/GlobalConfig.cpp | 4 ++++ rts/System/GlobalConfig.h | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rts/Game/TraceRay.cpp b/rts/Game/TraceRay.cpp index 9c3874479f..3e31f2c0bc 100644 --- a/rts/Game/TraceRay.cpp +++ b/rts/Game/TraceRay.cpp @@ -18,7 +18,7 @@ #include "Sim/Units/UnitTypes/Factory.h" #include "Sim/Weapons/PlasmaRepulser.h" #include "Sim/Weapons/WeaponDef.h" -#include "System/Config/ConfigHandler.h" +#include "System/GlobalConfig.h" #include "System/SpringMath.h" #include @@ -26,8 +26,6 @@ #include "System/Misc/TracyDefs.h" -CONFIG(float, SelectThroughGround).defaultValue(200.0f).minimumValue(0.0f).description("Sets how far beyond the ground to allow selecting objects."); - ////////////////////////////////////////////////////////////////////// // Local/Helper functions ////////////////////////////////////////////////////////////////////// @@ -418,8 +416,7 @@ float GuiTraceRay( // pointing upwards maxRayLength = length; } - const float lenienceBuffer = configHandler->GetFloat("SelectThroughGround"); - maxRayLength = std::min(maxRayLength + lenienceBuffer, length); + maxRayLength = std::min(maxRayLength + globalConfig.selectThroughGround, length); CollisionQuery cq; diff --git a/rts/System/GlobalConfig.cpp b/rts/System/GlobalConfig.cpp index 725a72d949..a075d8a871 100644 --- a/rts/System/GlobalConfig.cpp +++ b/rts/System/GlobalConfig.cpp @@ -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: @@ -98,6 +100,8 @@ void GlobalConfig::Init() minDrawFPS = configHandler->GetInt("MinDrawFPS"); teamHighlight = configHandler->GetInt("TeamHighlight"); + + selectThroughGround = configHandler->GetFloat("SelectThroughGround"); } #endif diff --git a/rts/System/GlobalConfig.h b/rts/System/GlobalConfig.h index fca18fec0d..014b404522 100644 --- a/rts/System/GlobalConfig.h +++ b/rts/System/GlobalConfig.h @@ -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;