diff --git a/src/bms/player/beatoraja/MainController.java b/src/bms/player/beatoraja/MainController.java index b22f1cfca..c3f0b0b1e 100644 --- a/src/bms/player/beatoraja/MainController.java +++ b/src/bms/player/beatoraja/MainController.java @@ -3,6 +3,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; import org.lwjgl.input.Mouse; @@ -77,6 +79,7 @@ public class MainController { private MainState current; private TimerManager timer; + private Lock timerLock; private Config config; private PlayerConfig player; @@ -192,6 +195,7 @@ public MainController(Path f, Config config, PlayerConfig player, BMSPlayerMode } timer = new TimerManager(); + timerLock = new ReentrantLock(); sound = new SystemSoundManager(this); if(config.isUseDiscordRPC()) { @@ -361,6 +365,13 @@ public void create() { if (time != now) { time = now; input.poll(); + if (timerLock.tryLock()) { + try { + timer.update(); + } finally { + timerLock.unlock(); + } + } } else { try { Thread.sleep(0, 500000); @@ -410,22 +421,26 @@ public void create() { public void render() { // input.poll(); - timer.update(); - - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + timerLock.lock(); + try { + timer.update(); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - current.render(); - sprite.begin(); - if (current.getSkin() != null) { - current.getSkin().updateCustomObjects(current); - current.getSkin().drawAllObjects(sprite, current); - } - sprite.end(); + current.render(); + sprite.begin(); + if (current.getSkin() != null) { + current.getSkin().updateCustomObjects(current); + current.getSkin().drawAllObjects(sprite, current); + } + sprite.end(); - final Stage stage = current.getStage(); - if (stage != null) { - stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); - stage.draw(); + final Stage stage = current.getStage(); + if (stage != null) { + stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); + stage.draw(); + } + } finally { + timerLock.unlock(); } // show fps