HitShape, query trait via actor cached targetable positions.

This commit is contained in:
Vapre
2022-08-04 21:42:14 +02:00
committed by Matthias Mailänder
parent f88b6d78ff
commit e3aa2dc6c0
6 changed files with 61 additions and 29 deletions

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Effects;
@@ -336,9 +335,11 @@ namespace OpenRA.Mods.Common.Projectiles
continue;
// If the impact position is within any actor's HitShape, we have a direct hit
var activeShapes = victim.TraitsImplementing<HitShape>().Where(Exts.IsTraitEnabled);
if (activeShapes.Any(i => i.DistanceFromEdge(victim, pos).Length <= 0))
return true;
// PERF: Avoid using TraitsImplementing<HitShape> that needs to find the actor in the trait dictionary.
foreach (var targetPos in victim.EnabledTargetablePositions)
if (targetPos is HitShape h)
if (h.DistanceFromEdge(victim, pos).Length <= 0)
return true;
}
return false;