From f0085fb59fbae807c0e241534e05822e150199cf Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:22:53 +0800 Subject: limit progress update interval to prevent too many display buffer swaps (#122) Former-commit-id: 6a05302bfb54e96cbe58ce7d26b33fee08e20f37 --- .../com/github/bartimaeusnek/crossmod/cls/CLSCompat.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/bartimaeusnek/crossmod/cls/CLSCompat.java b/src/main/java/com/github/bartimaeusnek/crossmod/cls/CLSCompat.java index 930360bef4..13c4de03fb 100644 --- a/src/main/java/com/github/bartimaeusnek/crossmod/cls/CLSCompat.java +++ b/src/main/java/com/github/bartimaeusnek/crossmod/cls/CLSCompat.java @@ -34,6 +34,8 @@ public class CLSCompat { private CLSCompat() { } + private static final long MINIMAL_UPDATE_INTERVAL = 1000 / 30; // target 30 fps + private static long lastUpdate = 0; private static Class alexiilMinecraftDisplayer; private static Class alexiilProgressDisplayer; private static Method displayProgress; @@ -85,10 +87,14 @@ public class CLSCompat { public static int invokeStepSize(Werkstoff werkstoff, Integer[] steps, int size) { --steps[0]; - try { - displayProgress.invoke(null, werkstoff.getDefaultName(), ((float) size) / 10000); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + long time = System.currentTimeMillis(); + if (time - lastUpdate >= MINIMAL_UPDATE_INTERVAL) { + try { + displayProgress.invoke(null, werkstoff.getDefaultName(), ((float) size) / 10000); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + lastUpdate = time; } if (steps[0] == 0 && Werkstoff.werkstoffHashSet.size() >= 100) @@ -105,4 +111,4 @@ public class CLSCompat { e.printStackTrace(); } } -} \ No newline at end of file +} -- cgit