Browse Source

Fix tracing support

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
27d334654d
  1. 22
      sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc
  2. 1
      sources/Gameplay/KF1Frontend/KF1_Frontend.uc
  3. 29
      sources/Gameplay/KF1Frontend/World/KF1_TracingIterator.uc
  4. 7
      sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc

22
sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc

@ -20,6 +20,20 @@
class TracingIterator extends Iter
abstract;
/**
* Returns position from which tracing is started.
*
* @return Position from which stracing has started.
*/
public function Vector GetTracingStart();
/**
* Returns position at which tracing has ended.
*
* @return Position at which tracing has ended.
*/
public function Vector GetTracingEnd();
/**
* Returns only `EPlaceable` interfaces for traced entities.
*
@ -79,6 +93,14 @@ public function EPawn GetPawn();
*/
public function TracingIterator LeaveOnlyPawns();
/**
* Makes caller iterator skip any entities that are not visible in the game
* world.
*
* @return Reference to caller `TracingIterator` to allow for method chaining.
*/
public function TracingIterator LeaveOnlyVisible();
defaultproperties
{
}

1
sources/Gameplay/KF1Frontend/KF1_Frontend.uc

@ -34,6 +34,7 @@ public function EItemTemplateInfo GetItemTemplateInfo(BaseText templateName)
defaultproperties
{
templatesClass = class'KF1_TemplatesComponent'
worldClass = class'KF1_WorldComponent'
tradingClass = class'KF1_TradingComponent'
healthClass = class'KF1_HealthComponent'
}

29
sources/Gameplay/KF1Frontend/World/KF1_TracingIterator.uc

@ -35,6 +35,7 @@ var private bool traced;
// Iterator filters
var private bool onlyPawns;
var private bool onlyVisible;
protected function Finalizer()
{
@ -57,10 +58,21 @@ public final function Initialize(Vector start, Vector end)
initialized = true;
}
public function Vector GetTracingStart()
{
return startPosition;
}
public function Vector GetTracingEnd()
{
return endPosition;
}
// Does actual tracing, but only once per iterator's lifecycle.
// Assumes `initialized` is `true`.
private final function TryTracing()
{
local bool isVisible;
local Pawn nextPawn;
local Actor nextActor;
local class<Actor> targetClass;
@ -87,6 +99,14 @@ private final function TryTracing()
endPosition,
startPosition)
{
if (onlyVisible)
{
isVisible = (!nextActor.bHidden || nextActor.bWorldGeometry);
isVisible = isVisible && (nextActor.drawType != DT_None);
if (!isVisible) {
continue;
}
}
hitLocations[hitLocations.length] = nextHitLocation;
hitNormals[hitNormals.length] = nextHitNormal;
nextPawn = Pawn(nextActor);
@ -173,6 +193,7 @@ public function EPawn GetPawn()
public function bool HasFinished()
{
TryTracing();
return (currentIndex >= tracedActors.length);
}
@ -190,6 +211,14 @@ public function TracingIterator LeaveOnlyPawns()
return self;
}
public function TracingIterator LeaveOnlyVisible()
{
if (initialized && !traced) {
onlyVisible = true;
}
return self;
}
defaultproperties
{
}

7
sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc

@ -17,8 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/
class KF1_WorldComponent extends AWorldComponent
abstract;
class KF1_WorldComponent extends AWorldComponent;
var private const float tracingDistance;
@ -63,7 +62,7 @@ public function TracingIterator TracePlayerSight(EPlayer player)
if (controller != none)
{
controller.PlayerCalcView(dummy, start, direction);
return Trace(start, direction);
return Trace(start, controller.rotation);
}
return none;
}
@ -80,7 +79,7 @@ public function TracingIterator TraceSight(EPawn pawn)
if (nativePawn == none) return none;
start = nativePawn.location + nativePawn.EyePosition();
end = start + tracingDistance * Vector(nativePawn.rotation);
end = start + tracingDistance * Vector(nativePawn.controller.rotation);
return TraceBetween(start, end);
}

Loading…
Cancel
Save