Skip to content

Commit

Permalink
Merge pull request #543 from FFXIV-CombatReborn/mergeWIP
Browse files Browse the repository at this point in the history
some cleanup
  • Loading branch information
CarnifexOptimus authored Jan 5, 2025
2 parents 608d884 + 3afeb4e commit 74b8c96
Show file tree
Hide file tree
Showing 23 changed files with 406 additions and 101 deletions.
26 changes: 15 additions & 11 deletions BossMod/BossModule/AOEShapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ public enum OperandType
// shapes1 for unions, shapes 2 for shapes for XOR/intersection with shapes1, differences for shapes that get subtracted after previous operations
// always create a new instance of AOEShapeCustom if something other than the invertforbiddenzone changes
// if the origin of the AOE can change, edit the origin default value to prevent cache issues
public sealed record class AOEShapeCustom(IEnumerable<Shape> Shapes1, IEnumerable<Shape>? DifferenceShapes = null, IEnumerable<Shape>? Shapes2 = null, bool InvertForbiddenZone = false, OperandType Operand = OperandType.Union, WPos Origin = default) : AOEShape
public sealed record class AOEShapeCustom(Shape[] Shapes1, Shape[]? DifferenceShapes = null, Shape[]? Shapes2 = null, bool InvertForbiddenZone = false, OperandType Operand = OperandType.Union, WPos Origin = default) : AOEShape
{
public RelSimplifiedComplexPolygon? Polygon;
private PolygonWithHolesDistanceFunction? shapeDistance;
private readonly int hashkey = CreateCacheKey(Shapes1, Shapes2 ?? [], DifferenceShapes ?? [], Operand, Origin);
private static readonly Dictionary<int, RelSimplifiedComplexPolygon> cache = [];
private static readonly LinkedList<int> cacheOrder = new();

public void AddToCache(RelSimplifiedComplexPolygon value)
{
if (cache.Count >= 50)
Expand Down Expand Up @@ -246,8 +247,9 @@ public RelSimplifiedComplexPolygon GetCombinedPolygon(WPos origin)
if (Shapes2 != null)
{
Polygon = clipper.Simplify(shapes1);
foreach (var shape in Shapes2)
for (var i = 0; i < Shapes2.Length; ++i)
{
var shape = Shapes2[i];
var singleShapeOperand = CreateOperandFromShape(shape, origin);

switch (Operand)
Expand All @@ -274,27 +276,29 @@ private static PolygonClipper.Operand CreateOperandFromShape(Shape shape, WPos o
return operand;
}

private static PolygonClipper.Operand CreateOperandFromShapes(IEnumerable<Shape>? shapes, WPos origin)
private static PolygonClipper.Operand CreateOperandFromShapes(Shape[]? shapes, WPos origin)
{
var operand = new PolygonClipper.Operand();
if (shapes != null)
foreach (var shape in shapes)
operand.AddPolygon(shape.ToPolygon(origin));
for (var i = 0; i < shapes.Length; ++i)
operand.AddPolygon(shapes[i].ToPolygon(origin));
return operand;
}

public override bool Check(WPos position, WPos origin, Angle rotation)
{
var (x, z) = position - origin;
var result = (Polygon ?? GetCombinedPolygon(origin)).Contains(new(x, z));
return result;
return (Polygon ?? GetCombinedPolygon(origin)).Contains(position - origin);
}

private static int CreateCacheKey(IEnumerable<Shape> shapes1, IEnumerable<Shape> shapes2, IEnumerable<Shape> differenceShapes, OperandType operand, WPos origin)
private static int CreateCacheKey(Shape[] shapes1, Shape[] shapes2, Shape[] differenceShapes, OperandType operand, WPos origin)
{
var hashCode = new HashCode();
foreach (var shape in shapes1.Concat(shapes2).Concat(differenceShapes))
hashCode.Add(shape.GetHashCode());
for (var i = 0; i < shapes1.Length; ++i)
hashCode.Add(shapes1[i].GetHashCode());
for (var i = 0; i < shapes2.Length; ++i)
hashCode.Add(shapes2[i].GetHashCode());
for (var i = 0; i < differenceShapes.Length; ++i)
hashCode.Add(differenceShapes[i].GetHashCode());
hashCode.Add(operand);
hashCode.Add(origin);
return hashCode.ToHashCode();
Expand Down
4 changes: 2 additions & 2 deletions BossMod/BossModule/ArenaBounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ private static (WPos Center, float HalfWidth, float HalfHeight, float Radius, Re
var combinedPoly = CombinePolygons(unionPolygons, differencePolygons, additionalPolygons);

float minX = float.MaxValue, maxX = float.MinValue, minZ = float.MaxValue, maxZ = float.MinValue;
var count = combinedPoly.Parts.Count;
for (var i = 0; i < count; ++i)

for (var i = 0; i < combinedPoly.Parts.Count; ++i)
{
var part = combinedPoly.Parts[i];
for (var j = 0; j < part.Exterior.Length; ++j)
Expand Down
77 changes: 72 additions & 5 deletions BossMod/Components/StackSpread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ public struct Stack(Actor target, float radius, int minSize = 2, int maxSize = i
public DateTime Activation = activation;
public BitMask ForbiddenPlayers = forbiddenPlayers; // raid members that aren't allowed to participate in the stack

public readonly int NumInside(BossModule module) => module.Raid.WithSlot().ExcludedFromMask(ForbiddenPlayers).InRadius(Target.Position, Radius).Count();
public readonly int NumInside(BossModule module)
{
var count = 0;
var party = module.Raid.WithSlot();
for (var i = 0; i < party.Length; ++i)
{
var indexActor = party[i];
if (!ForbiddenPlayers[indexActor.Item1] && indexActor.Item2.Position.InCircle(Target.Position, Radius))
++count;
}
return count;
}
public readonly bool CorrectAmountInside(BossModule module) => NumInside(module) is var count && count >= MinSize && count <= MaxSize;
public readonly bool InsufficientAmountInside(BossModule module) => NumInside(module) is var count && count < MaxSize;
public readonly bool TooManyInside(BossModule module) => NumInside(module) is var count && count > MaxSize;
Expand All @@ -36,11 +47,67 @@ public record struct Spread(
public const string StackHint = "Stack!";

public bool Active => Stacks.Count + Spreads.Count > 0;
public IEnumerable<Stack> ActiveStacks => IncludeDeadTargets ? Stacks : Stacks.Where(s => !s.Target.IsDead);
public IEnumerable<Spread> ActiveSpreads => IncludeDeadTargets ? Spreads : Spreads.Where(s => !s.Target.IsDead);
public List<Stack> ActiveStacks
{
get
{
if (IncludeDeadTargets)
return Stacks;
else
{
var count = Stacks.Count;
var activeStacks = new List<Stack>(count);
for (var i = 0; i < count; ++i)
{
var stack = Stacks[i];
if (!stack.Target.IsDead)
activeStacks.Add(stack);
}
return activeStacks;
}
}
}

public List<Spread> ActiveSpreads
{
get
{
if (IncludeDeadTargets)
return Spreads;
else
{
var count = Spreads.Count;
var activeSpreads = new List<Spread>(count);
for (var i = 0; i < count; ++i)
{
var spread = Spreads[i];
if (!spread.Target.IsDead)
activeSpreads.Add(spread);
}
return activeSpreads;
}
}
}

public bool IsStackTarget(Actor? actor)
{
for (var i = 0; i < Stacks.Count; ++i)
{
if (Stacks[i].Target == actor)
return true;
}
return false;
}

public bool IsStackTarget(Actor? actor) => Stacks.Any(s => s.Target == actor);
public bool IsSpreadTarget(Actor? actor) => Spreads.Any(s => s.Target == actor);
public bool IsSpreadTarget(Actor? actor)
{
for (var i = 0; i < Spreads.Count; ++i)
{
if (Spreads[i].Target == actor)
return true;
}
return false;
}

public override void AddHints(int slot, Actor actor, TextHints hints)
{
Expand Down
Loading

0 comments on commit 74b8c96

Please sign in to comment.