mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-06 00:08:10 +07:00
Actually fixed FPS cap
This commit is contained in:
@ -13,6 +13,7 @@ import static io.anuke.arc.Core.batch;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Mindustry extends ApplicationCore{
|
||||
private long lastTime;
|
||||
|
||||
@Override
|
||||
public void setup(){
|
||||
@ -52,6 +53,27 @@ public class Mindustry extends ApplicationCore{
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
super.update();
|
||||
|
||||
int targetfps = Core.settings.getInt("fpscap", 120);
|
||||
|
||||
if(targetfps > 0 && targetfps <= 120){
|
||||
long target = (1000 * 1000000) / targetfps; //target in nanos
|
||||
long elapsed = Time.timeSinceNanos(lastTime);
|
||||
if(elapsed < target){
|
||||
try{
|
||||
Thread.sleep((target - elapsed) / 1000000, (int)((target - elapsed) % 1000000));
|
||||
}catch(InterruptedException ignored){
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastTime = Time.nanos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
setup();
|
||||
|
@ -172,15 +172,9 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
}
|
||||
});
|
||||
|
||||
graphics.sliderPref("fpscap", 125, 5, 125, 5,
|
||||
s -> {
|
||||
Core.app.setTargetFPS(s > 120 ? -1 : s);
|
||||
return (s > 120 ? Core.bundle.get("setting.fpscap.none") : Core.bundle.format("setting.fpscap.text", s));
|
||||
});
|
||||
graphics.sliderPref("fpscap", 125, 5, 125, 5, s -> (s > 120 ? Core.bundle.get("setting.fpscap.none") : Core.bundle.format("setting.fpscap.text", s)));
|
||||
graphics.sliderPref("chatopacity", 100, 0, 100, 5, s -> s + "%");
|
||||
|
||||
Core.app.setTargetFPS(Core.settings.getInt("fpscap", 125) > 120 ? -1 : Core.settings.getInt("fpscap"));
|
||||
|
||||
if(!mobile){
|
||||
graphics.checkPref("vsync", true, b -> Core.graphics.setVSync(b));
|
||||
graphics.checkPref("fullscreen", false, b -> {
|
||||
|
Reference in New Issue
Block a user