aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2022-04-24 17:22:53 +0800
committerGitHub <noreply@github.com>2022-04-24 11:22:53 +0200
commitf0085fb59fbae807c0e241534e05822e150199cf (patch)
tree518880e86e676cf4c50c951542e5372466d55bd8 /src/main
parenta830c14a9f0ba4476560a9d9ee91e511523c814f (diff)
downloadGT5-Unofficial-f0085fb59fbae807c0e241534e05822e150199cf.tar.gz
GT5-Unofficial-f0085fb59fbae807c0e241534e05822e150199cf.tar.bz2
GT5-Unofficial-f0085fb59fbae807c0e241534e05822e150199cf.zip
limit progress update interval to prevent too many display buffer swaps (#122)
Former-commit-id: 6a05302bfb54e96cbe58ce7d26b33fee08e20f37
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/github/bartimaeusnek/crossmod/cls/CLSCompat.java16
1 files 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
+}