From 54ac0697977e88d1e86b94a91ee8556444d801dd Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 21 Jun 2025 21:00:22 +0300 Subject: [PATCH] _dynamic list --- Source/Game/Player/PlayerMovement.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Source/Game/Player/PlayerMovement.cs b/Source/Game/Player/PlayerMovement.cs index 5885659..e1a4740 100644 --- a/Source/Game/Player/PlayerMovement.cs +++ b/Source/Game/Player/PlayerMovement.cs @@ -8,6 +8,7 @@ using FlaxEngine; using FlaxEngine.Assertions; using FlaxEngine.Networking; using Console = Game.Console; +using System.Buffers; namespace Game; @@ -83,7 +84,7 @@ public struct PlayerMovementState public struct TraceInfo { - public RayCastHit[] hitInfos; + public List hitInfos; public bool startSolid; // closest hit @@ -141,6 +142,8 @@ public class PlayerMovement : Script public uint PlayerId => playerActor ? playerActor.PlayerId : 0; + public LayersMask maskTest; + [ReadOnly] public float CurrentVelocity { @@ -757,15 +760,17 @@ public class PlayerMovement : Script //viewAnglesLastFrame = angles; } - private static bool SweepPlayerCollider(PlayerActor actor, Float3 start, Vector3 end, out RayCastHit[] hits) + private static List _cachedHits = new(); + private static bool SweepPlayerCollider(PlayerActor actor, Float3 start, Vector3 end, out List hits) { Vector3 delta = end - start; float distance = delta.Length; Vector3 direction = delta.Normalized; + //_cachedHits.Clear(); if (distance < 0.00000001f) { - hits = new RayCastHit[0];//Array.Empty(); + hits = _cachedHits;//Array.Empty(); return false; } @@ -773,7 +778,7 @@ public class PlayerMovement : Script CapsuleCollider capsuleCollider = actor.capsuleCollider; BoxCollider boxCollider = actor.boxCollider; MeshCollider meshCollider = actor.meshCollider; - if (capsuleCollider && capsuleCollider.IsActive) + /*if (capsuleCollider && capsuleCollider.IsActive) collided = Physics.CapsuleCastAll(start, capsuleCollider.Radius, capsuleCollider.Height, direction, out hits, capsuleCollider.Orientation, distance, @@ -785,16 +790,16 @@ public class PlayerMovement : Script direction, out hits, meshCollider.Orientation, distance, uint.MaxValue, false); - else if (boxCollider && boxCollider.IsActive) + else*/ if (boxCollider && boxCollider.IsActive) collided = Physics.BoxCastAll(start, boxCollider.OrientedBox.Extents, - direction, out hits, boxCollider.Orientation, distance, + direction, ref _cachedHits, boxCollider.Orientation, distance, uint.MaxValue, false); else throw new Exception("Player does not have a collider"); - + hits = _cachedHits; return collided; } @@ -857,6 +862,7 @@ public class PlayerMovement : Script return collided; } + private static List _cachedHitInfos = new List(); /// /// Sweeps the player rigidbody in world and returns geometry which was hit during the trace. /// @@ -867,6 +873,7 @@ public class PlayerMovement : Script private static TraceInfo TracePlayer(PlayerActor actor, Vector3 start, Vector3 end) { TraceInfo traceInfo = new TraceInfo(); + traceInfo.hitInfos = _cachedHitInfos; Vector3 delta = end - start; float maxDistance = delta.Length; @@ -921,7 +928,7 @@ public class PlayerMovement : Script if (hitInfo.Distance < closest.Distance) closest = hitInfo; - traceInfo.hitInfos = hitInfosFiltered.ToArray(); + traceInfo.hitInfos = hitInfosFiltered; traceInfo.fraction = closest.Distance / maxDistance; traceInfo.hitNormal = closest.Normal; @@ -943,7 +950,7 @@ public class PlayerMovement : Script if (!collided) { - traceInfo.hitInfos = new RayCastHit[0]; + traceInfo.hitInfos = new List(); traceInfo.fraction = 1f; traceInfo.endPosition = end; }