mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
- Changed the desktop Forge Targeting Overlay from timer-based approach to a blocking mechanism which appears to work much better across systems (Linux, Mac, Windows) without causing visual artifacts and without causing the CPU overload (code submission by nefigah).
This commit is contained in:
@@ -81,7 +81,9 @@ public class TargetingOverlay {
|
|||||||
private final Set<CardView> cardsVisualized = new HashSet<CardView>();
|
private final Set<CardView> cardsVisualized = new HashSet<CardView>();
|
||||||
private CardPanel activePanel = null;
|
private CardPanel activePanel = null;
|
||||||
|
|
||||||
private long lastUpdated = System.currentTimeMillis();
|
//private long lastUpdated = System.currentTimeMillis(); // TODO: determine if timer is needed (see below)
|
||||||
|
private int allowedUpdates = 0;
|
||||||
|
private final int MAX_CONSECUTIVE_UPDATES = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Semi-transparent overlay panel. Should be used with layered panes.
|
* Semi-transparent overlay panel. Should be used with layered panes.
|
||||||
@@ -99,15 +101,27 @@ public class TargetingOverlay {
|
|||||||
return this.pnl;
|
return this.pnl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Though this is called on every repaint, we compare the last time it
|
// Though this is called on every repaint, we take means to avoid it fully
|
||||||
// ran against the current time to prevent CPU usage from spiking from overly
|
// running every time (to reduce CPU usage).
|
||||||
// frequent updates. It is also called (without the timer) in response to
|
|
||||||
// certain important UI events.
|
|
||||||
private boolean assembleArcs(final CombatView combat, boolean forceAssemble) {
|
private boolean assembleArcs(final CombatView combat, boolean forceAssemble) {
|
||||||
if (forceAssemble || System.currentTimeMillis() - lastUpdated > 50) {
|
if (!forceAssemble) {
|
||||||
lastUpdated = System.currentTimeMillis();
|
/* -- Minimum update frequency timer, currently disabled --
|
||||||
} else {
|
long now = System.currentTimeMillis();
|
||||||
return false;
|
if (now - lastUpdated <= 10) {
|
||||||
|
// TODO: Minimum timer needed? How bad are CPU spikes without this on fast machines?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (allowedUpdates >= MAX_CONSECUTIVE_UPDATES) {
|
||||||
|
// Reduce update spam by blocking every Nth attempt (zero-based).
|
||||||
|
// N should be adjusted to as low as possible to keep CPU usage low,
|
||||||
|
// while being high enough to avoid visual artifacts.
|
||||||
|
allowedUpdates = 0;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
allowedUpdates++;
|
||||||
|
//lastUpdated = now; // Uncomment if enabling timer above
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!assembler.getIsListening() && matchUI != null && matchUI.getFieldViews() != null) {
|
if (!assembler.getIsListening() && matchUI != null && matchUI.getFieldViews() != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user