Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2025-12-22 18:34:31 -05:00
+10 -4
View File
@@ -106,6 +106,10 @@ public class Pathfinder implements Runnable{
IntSeq tmpArray = new IntSeq(); IntSeq tmpArray = new IntSeq();
boolean needsRefresh; boolean needsRefresh;
/** Last time flowfields were refreshed, for timestamp-based refresh interval. */
private long lastRefreshTime;
/** Minimum interval between flowfield refreshes in milliseconds. */
private static final long refreshIntervalMs = 100;
public Pathfinder(){ public Pathfinder(){
clearCache(); clearCache();
@@ -182,9 +186,12 @@ public class Pathfinder implements Runnable{
}); });
Events.run(Trigger.afterGameUpdate, () -> { Events.run(Trigger.afterGameUpdate, () -> {
//only refresh periodically (every 2 frames) to batch flowfield updates if(!needsRefresh) return;
//TODO: is it worth switching to a timestamp based system instead that updates every X milliseconds?
if(needsRefresh && Core.graphics.getFrameId() % 2 == 0){ long now = Time.millis();
if(now - lastRefreshTime < refreshIntervalMs) return;
lastRefreshTime = now;
needsRefresh = false; needsRefresh = false;
//can't iterate through array so use the map, which should not lead to problems //can't iterate through array so use the map, which should not lead to problems
@@ -204,7 +211,6 @@ public class Pathfinder implements Runnable{
data.dirty = true; data.dirty = true;
} }
}); });
}
}); });
} }