Skip to content
Open
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
43 changes: 29 additions & 14 deletions src/bms/player/beatoraja/MainController.java
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for anybody wondering why we're also calling timer.update(); on render(), it is possible that the input polling thread somehow magically fails to acquire timerLock for prolonged time. So we want every entity acquiring the timer lock to update the timer ASAP.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +79,7 @@ public class MainController {
private MainState current;

private TimerManager timer;
private Lock timerLock;

private Config config;
private PlayerConfig player;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down