Skip to content

Commit

Permalink
Add "Unlimited" frame limiter option. (#324)
Browse files Browse the repository at this point in the history
Also changed FFmpeg parsing code from 0b36328 (thanks @tpenguinltg).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Feb 12, 2018
1 parent 0b36328 commit 6449b73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
24 changes: 18 additions & 6 deletions src/itdelatrisu/opsu/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,24 +399,34 @@ public void selectItem(int index, GameContainer container) {

@Override
public String getValueString() {
return String.format((getTargetFPS() == 60) ? "%dfps (vsync)" : "%dfps", getTargetFPS());
int fps = getTargetFPS();
return (fps == -1) ? "Unlimited" :
String.format((fps == 60) ? "%dfps (vsync)" : "%dfps", fps);
}

@Override
public Object[] getItemList() {
if (itemList == null) {
itemList = new String[targetFPS.length];
for (int i = 0; i < targetFPS.length; i++)
itemList[i] = String.format((targetFPS[i] == 60) ? "%dfps (vsync)" : "%dfps", targetFPS[i]);
for (int i = 0; i < targetFPS.length; i++) {
int fps = targetFPS[i];
itemList[i] = (fps == -1) ? "Unlimited" :
String.format((fps == 60) ? "%dfps (vsync)" : "%dfps", fps);
}
}
return itemList;
}

@Override
public void selectItem(int index, GameContainer container) {
targetFPSindex = index;
container.setTargetFrameRate(getTargetFPS());
container.setVSync(getTargetFPS() == 60);

int fps = getTargetFPS();
boolean vsync = (fps == 60);
container.setTargetFrameRate(fps);
if (container.isVSyncRequested() != vsync) {
container.setVSync(vsync);
}
}

@Override
Expand Down Expand Up @@ -954,7 +964,7 @@ public boolean hasFullscreenDisplayMode() {
private static Skin skin;

/** Frame limiters. */
private static final int[] targetFPS = { 60, 120, 240 };
private static final int[] targetFPS = { 60, 120, 240, -1 /* Unlimited */ };

/** Index in targetFPS[] array. */
private static int targetFPSindex = 0;
Expand Down Expand Up @@ -986,6 +996,8 @@ private Options() {}
*/
public static void setNextFPS(GameContainer container) {
int index = (targetFPSindex + 1) % targetFPS.length;
if (index == targetFPS.length - 1)
index = 0; // Skip "Unlimited" option
GameOption.TARGET_FPS.selectItem(index, container);
UI.getNotificationManager().sendBarNotification(String.format("Frame limiter: %s", GameOption.TARGET_FPS.getValueString()));
}
Expand Down
9 changes: 4 additions & 5 deletions src/itdelatrisu/opsu/video/FFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ public static VideoMetadata extractMetadata(File srcMovieFile) throws IOExceptio
// Parse framerate
// Note: Can contain 'k' suffix (*1000), see dump.c#print_fps.
// https://www.ffmpeg.org/doxygen/3.1/dump_8c_source.html#l00119
String fps = RegexUtil.findFirst(line, Pattern.compile("\\s(\\d+(\\.\\d+)?k?)\\stbr,"), 1);
if (fps.endsWith("k"))
framerate = Float.parseFloat(fps.substring(0, fps.length() - 1)) * 1000f;
else
framerate = Float.parseFloat(fps);
String[] fr = RegexUtil.find(line, Pattern.compile("\\s(\\d+(\\.\\d+)?)(k?)\\stbr,"), 1, 3);
framerate = Float.parseFloat(fr[0]);
if (!fr[1].isEmpty())
framerate *= 1000f;

// Parse width/height
int[] wh = TextValues.parseInts(RegexUtil.find(line, Pattern.compile("\\s(\\d+)x(\\d+)[\\s,]"), 1, 2));
Expand Down

0 comments on commit 6449b73

Please sign in to comment.