Skip to content
Draft
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
22 changes: 20 additions & 2 deletions src/main/java/amidst/threading/ThreadMaster.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package amidst.threading;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -86,7 +89,7 @@ private void startRepainter() {
public void run() {
onRepaintTick.run();
}
}, 0, 20, TimeUnit.MILLISECONDS);
}, 0, 1000000 / getRefreshRate(), TimeUnit.MICROSECONDS);
}

private void startFragmentLoader() {
Expand All @@ -96,7 +99,7 @@ private void startFragmentLoader() {
public void run() {
onFragmentLoadTick.run();
}
}, 0, 20, TimeUnit.MILLISECONDS);
}, 0, 1000000 / getRefreshRate(), TimeUnit.MICROSECONDS);
}

public WorkerExecutor getWorkerExecutor() {
Expand All @@ -118,4 +121,19 @@ public void clearOnRepaintTick() {
public void clearOnFragmentLoadTick() {
this.onFragmentLoadTick = NOOP;
}

/**
* @return the highest refresh rate out of all graphics devices recognized by the JVM
*/
public int getRefreshRate() {
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
int refreshRate = DisplayMode.REFRESH_RATE_UNKNOWN;

for(GraphicsDevice device : devices) {
refreshRate = Math.max(refreshRate, device.getDisplayMode().getRefreshRate());
}

return refreshRate;
}

}