Skip to content

Commit

Permalink
Improved performance of weapon LoS checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 6, 2024
1 parent a7a3490 commit 81ff36e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,9 @@ public float CheckHits()

if (RemainingImpacts > 0)
{
Stopwatch sw = Stopwatch.StartNew();

//List<MyLineSegmentOverlapResult<MyEntity>> intersects = new List<MyLineSegmentOverlapResult<MyEntity>>();
List<IHitInfo> intersects = new List<IHitInfo>();
MyAPIGateway.Physics.CastRay(Position, NextMoveStep, intersects);

//LineD ray = new LineD(Position, NextMoveStep);
//MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, intersects); // TODO: This is causing problems with hitting own grid

foreach (var hitInfo in intersects)
{
if (RemainingImpacts <= 0)
Expand All @@ -272,11 +266,6 @@ public float CheckHits()

RemainingImpacts--;
}

sw.Stop();

if (MyAPIGateway.Input.IsKeyPress(VRage.Input.MyKeys.Shift))
HeartData.I.Log.Log("T: " + sw.ElapsedTicks);
}

if (RemainingImpacts <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ private bool HasLineOfSight()
if (!Definition.Hardpoint.LineOfSightCheck) // Ignore if LoS check is disabled
return true;

List<IHitInfo> intersects = new List<IHitInfo>();
MyAPIGateway.Physics.CastRay(MuzzleMatrix.Translation, MuzzleMatrix.Translation + MuzzleMatrix.Forward * GridCheckRange, intersects);
List<Vector3I> intersects = new List<Vector3I>();
SorterWep.CubeGrid.RayCastCells(MuzzleMatrix.Translation, MuzzleMatrix.Translation + MuzzleMatrix.Forward * GridCheckRange, intersects);

foreach (var intersect in intersects)
if (intersect.HitEntity.EntityId == SorterWep.CubeGrid.EntityId)
if (intersect != SorterWep.Position && SorterWep.CubeGrid.CubeExists(intersect))
return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ public void UpdateReload()
else
{
// Notify item not available
MyVisualScriptLogicProvider.ShowNotification($"Unable to reload - {magazineItem} not found in inventory.", 1000 / 60, "Red");
//MyVisualScriptLogicProvider.ShowNotification($"Unable to reload - {magazineItem} not found in inventory.", 1000 / 60, "Red");
return;
}
}
else
{
// Notify when MagazineItemToConsume is not specified
MyVisualScriptLogicProvider.ShowNotification("MagazineItemToConsume not specified, proceeding with default reload behavior.", 1000 / 60, "Blue");
// TODO: Note in debug log
//MyVisualScriptLogicProvider.ShowNotification("MagazineItemToConsume not specified, proceeding with default reload behavior.", 1000 / 60, "Blue");
}

MagazinesLoaded++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ partial class HeartDefinitions
TrailWidth = 0.5f,
TrailColor = new VRageMath.Vector4(61, 24, 24, 200),
//AttachedParticle = "Smoke_Missile",
ImpactParticle = "MaterialHit_Metal",
ImpactParticle = "",
VisibleChance = 1f,
},
Audio = new Audio()
{
TravelSound = "",
TravelVolume = 100,
TravelMaxDistance = 1000,
ImpactSound = "WepSmallWarheadExpl",
ImpactSound = "",
SoundChance = 0.1f,
},
Guidance = new Guidance[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ partial class HeartDefinitions
},
Visuals = new Visuals()
{
ShootParticle = "Muzzle_Flash_Autocannon",
ShootParticle = "",
ContinuousShootParticle = false,
ReloadParticle = "",
},
Expand Down

0 comments on commit 81ff36e

Please sign in to comment.