Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/TSMapEditor/Mutations/Classes/DrawConnectedTilesMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ private struct ConnectedTileUndoData
public byte Level;
}

private const int MaxTimeInMilliseconds = 10;
// The stall watchdog resets whenever the search progresses, so a generous budget only
// extends genuinely stuck searches. The browser gets more time to compensate for the
// interpreted runtime's higher per-node cost and coarser timer granularity.
private static readonly int MaxTimeInMilliseconds = OperatingSystem.IsBrowser() ? 100 : 10;

// Stopwatch timestamps use Stopwatch.Frequency units, which differ per platform
// (they only coincide with TimeSpan's 100ns ticks on Windows).
private static readonly long MaxTimeInStopwatchTicks = Stopwatch.Frequency / 1000 * MaxTimeInMilliseconds;
private const float TileSizePenaltyPerFoundationCell = 0.07f;
private const int RepeatPenaltyAncestorWindow = 5;
private const float RepeatPenaltyPerWeightedUse = 0.75f;
Expand Down Expand Up @@ -101,7 +108,7 @@ private void FindConnectedTilePath(Point2D start, Point2D end, bool allowInstant
lastNode.Destination = end;
}

long timeoutTimestamp = Stopwatch.GetTimestamp() + TimeSpan.FromMilliseconds(MaxTimeInMilliseconds).Ticks;
long timeoutTimestamp = Stopwatch.GetTimestamp() + MaxTimeInStopwatchTicks;
openSet.Enqueue(lastNode, (GetNodePriorityScore(lastNode), lastNode.Tile?.ExtraPriority ?? 0));

while (openSet.Count > 0)
Expand All @@ -120,7 +127,7 @@ private void FindConnectedTilePath(Point2D start, Point2D end, bool allowInstant
{
bestNode = currentNode;
bestDistance = currentDistance;
timeoutTimestamp = Stopwatch.GetTimestamp() + TimeSpan.FromMilliseconds(MaxTimeInMilliseconds).Ticks;
timeoutTimestamp = Stopwatch.GetTimestamp() + MaxTimeInStopwatchTicks;
}

if (bestDistance == 0 || Stopwatch.GetTimestamp() > timeoutTimestamp)
Expand Down
Loading