Skip to content

Commit

Permalink
Merge pull request #360 from Rian8337/decouple-fps-pp-counter
Browse files Browse the repository at this point in the history
Decouple FPS and pp counter settings
  • Loading branch information
Rian8337 committed May 13, 2024
2 parents 6105bc7 + 41c69fc commit 49589a3
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 65 deletions.
6 changes: 6 additions & 0 deletions res/values/options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<string name="opt_fps_title">FPS</string>
<string name="opt_fps_summary">Display (frames per second) during gameplay</string>

<string name="opt_averageoffset_title">Average offset</string>
<string name="opt_averageoffset_summary">Display average offset of hits during gameplay. Higher value means hits are more offset</string>

<string name="opt_unstablerate_title">Unstable rate</string>
<string name="opt_unstablerate_summary">Display unstable rate during gameplay. Higher value means hits are more inconsistent</string>

<!-- <string name="opt_skipoffset_title">Skip offset</string>
<string name="opt_skipoffset_summary">This offset will be added when you press the &quot;Skip&quot; button. Enter -1 for auto offset</string> -->

Expand Down
16 changes: 15 additions & 1 deletion res/xml/settings_gameplay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,21 @@
android:key="fps"
android:summary="@string/opt_fps_summary"
android:title="@string/opt_fps_title"
app:layout="@layout/settings_preference_checkbox_bottom" />
app:layout="@layout/settings_preference_checkbox" />

<CheckBoxPreference
android:defaultValue="true"
android:key="averageOffset"
android:summary="@string/opt_averageoffset_summary"
android:title="@string/opt_averageoffset_title"
app:layout="@layout/settings_preference_checkbox" />

<CheckBoxPreference
android:defaultValue="true"
android:key="unstableRate"
android:summary="@string/opt_unstablerate_summary"
android:title="@string/opt_unstablerate_title"
app:layout="@layout/settings_preference_checkbox" />

<CheckBoxPreference
android:defaultValue="true"
Expand Down
22 changes: 21 additions & 1 deletion src/ru/nsu/ccfit/zuev/osu/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class Config {
useCustomSounds,
corovans,
showFPS,
showAverageOffset,
showUnstableRate,
animateFollowCircle,
animateComboText,
snakingInSliders,
Expand Down Expand Up @@ -111,7 +113,9 @@ public static void loadConfig(final Context context) {
useCustomSounds = prefs.getBoolean("beatmapSounds", true);
comboburst = prefs.getBoolean("comboburst", false);
corovans = prefs.getBoolean("images", false);
showFPS = prefs.getBoolean("fps", false);
showFPS = prefs.getBoolean("fps", true);
showAverageOffset = prefs.getBoolean("averageOffset", true);
showUnstableRate = prefs.getBoolean("unstableRate", true);
errorMeter = Integer.parseInt(prefs.getString("errormeter", "0"));
spinnerStyle = Integer.parseInt(prefs.getString("spinnerstyle", "0"));
showFirstApproachCircle = prefs.getBoolean("showfirstapproachcircle", false);
Expand Down Expand Up @@ -322,6 +326,22 @@ public static void setShowFPS(final boolean showFPS) {
Config.showFPS = showFPS;
}

public static boolean isShowAverageOffset() {
return showAverageOffset;
}

public static void setShowAverageOffset(final boolean showAverageOffset) {
Config.showAverageOffset = showAverageOffset;
}

public static boolean isShowUnstableRate() {
return showUnstableRate;
}

public static void setShowUnstableRate(final boolean showUnstableRate) {
Config.showUnstableRate = showUnstableRate;
}

public static boolean isShowScoreboard() {
return showScoreboard;
}
Expand Down
142 changes: 79 additions & 63 deletions src/ru/nsu/ccfit/zuev/osu/game/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.entity.util.FPSCounter;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.util.Debug;

Expand Down Expand Up @@ -168,7 +167,7 @@ public class GameScene implements IUpdateHandler, GameObjectListener,
private Replay replay;
private boolean replaying;
private String replayFile;
private float avgOffset;
private float offsetSum;
private int offsetRegs;
private Rectangle dimRectangle = null;
private String title, artist, version;
Expand All @@ -186,7 +185,13 @@ public class GameScene implements IUpdateHandler, GameObjectListener,

private List<TimedDifficultyAttributes<DroidDifficultyAttributes>> droidTimedDifficultyAttributes;
private List<TimedDifficultyAttributes<StandardDifficultyAttributes>> standardTimedDifficultyAttributes;

private final List<ChangeableText> counterTexts = new ArrayList<>(5);
private ChangeableText fpsText;
private ChangeableText avgOffsetText;
private ChangeableText urText;
private ChangeableText ppText;
private ChangeableText memText;

/**
* The time at which the last frame was rendered with respect to {@link SystemClock#uptimeMillis()}.
Expand Down Expand Up @@ -593,7 +598,7 @@ private boolean loadGame(final TrackInfo track, final String rFile) {
ModifierFactory.clear();

// TODO replay
avgOffset = 0;
offsetSum = 0;
offsetRegs = 0;

File trackFile = new File(track.getFilename());
Expand Down Expand Up @@ -754,74 +759,55 @@ private void prepareScene() {
}
setBackground();

if (Config.isShowFPS() || Config.isDisplayRealTimePPCounter()) {
final Font font = ResourceManager.getInstance().getFont(
"smallFont");
final ChangeableText fpsText = new ChangeableText(Utils.toRes(790),
Utils.toRes(520), font, "00.00 FPS");
final ChangeableText urText = new ChangeableText(Utils.toRes(720),
Utils.toRes(480), font, "00.00 UR ");
final ChangeableText accText = new ChangeableText(Utils.toRes(720),
Utils.toRes(440), font, "Avg offset: 0ms ");
fpsText.setPosition(Config.getRES_WIDTH() - fpsText.getWidth() - 5, Config.getRES_HEIGHT() - fpsText.getHeight() - 10);
accText.setPosition(Config.getRES_WIDTH() - accText.getWidth() - 5, fpsText.getY() - accText.getHeight());
urText.setPosition(Config.getRES_WIDTH() - urText.getWidth() - 5, accText.getY() - urText.getHeight());
fgScene.attachChild(fpsText);
fgScene.attachChild(accText);
fgScene.attachChild(urText);

if (Config.isDisplayRealTimePPCounter()) {
ppText = new ChangeableText(Utils.toRes(720),
Utils.toRes(440), font, "0.00pp", 100);
fgScene.attachChild(ppText);
}

ChangeableText memText = null;
if (BuildConfig.DEBUG) {
memText = new ChangeableText(Utils.toRes(780),
Utils.toRes(520), font, "0 MB/0 MB ");
fgScene.attachChild(memText);
}

final ChangeableText fmemText = memText;
// Set up counter texts
for (var text : counterTexts) {
text.detachSelf();
}

counterTexts.clear();
var counterTextFont = ResourceManager.getInstance().getFont("smallFont");

if (Config.isShowFPS()) {
fpsText = new ChangeableText(790, 520, counterTextFont, "00.00 FPS");
counterTexts.add(fpsText);

fgScene.registerUpdateHandler(new FPSCounter() {
int elapsedInt = 0;
@Override
public void onUpdate(final float pSecondsElapsed) {
super.onUpdate(pSecondsElapsed);
elapsedInt++;
fpsText.setText(Math.round(this.getFPS()) + " FPS");
if (offsetRegs != 0 && elapsedInt > 200) {
float mean = avgOffset / offsetRegs;
accText.setText("Avg offset: "
+ (int) (mean * 1000f)
+ "ms");
elapsedInt = 0;
}
urText.setText(String.format(Locale.ENGLISH, "%.2f UR ", stat.getUnstableRate()));

fpsText.setPosition(Config.getRES_WIDTH() - fpsText.getWidth() - 5, Config.getRES_HEIGHT() - fpsText.getHeight() - 10);
accText.setPosition(Config.getRES_WIDTH() - accText.getWidth() - 5, fpsText.getY() - accText.getHeight());
urText.setPosition(Config.getRES_WIDTH() - urText.getWidth() - 5, accText.getY() - urText.getHeight());
if (ppText != null) {
ppText.setPosition(Config.getRES_WIDTH() - ppText.getWidth() - 5, urText.getY() - ppText.getHeight());
}

if (fmemText != null) {
Runtime runtime = Runtime.getRuntime();
fmemText.setText(
((runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024) + " MB"
+ "/" + (runtime.totalMemory() / 1024 / 1024) + " MB ");
fmemText.setPosition(
Config.getRES_WIDTH() - fmemText.getWidth() - 5,
(ppText != null ? ppText : urText).getY() - fmemText.getHeight()
);
}

fpsText.setText(Math.round(getFPS()) + " FPS");
}
});
}

if (Config.isShowUnstableRate()) {
urText = new ChangeableText(720, 480, counterTextFont, "00.00 UR ");
counterTexts.add(urText);
}

if (Config.isShowAverageOffset()) {
avgOffsetText = new ChangeableText(720, 440, counterTextFont, "Avg offset: 0ms ");
counterTexts.add(avgOffsetText);
}

if (Config.isDisplayRealTimePPCounter()) {
ppText = new ChangeableText(720, 400, counterTextFont, "0.00pp");
counterTexts.add(ppText);
}

if (BuildConfig.DEBUG) {
memText = new ChangeableText(780, 520, counterTextFont, "0/0 MB ");
counterTexts.add(memText);
}

updateCounterTexts();

// Attach the counter texts
for (var text : counterTexts) {
fgScene.attachChild(text);
}

stat = new StatisticV2();
stat.setMod(ModMenu.getInstance().getMod());
stat.canFail = !stat.getMod().contains(GameMod.MOD_NOFAIL)
Expand Down Expand Up @@ -1138,6 +1124,8 @@ public void onUpdate(final float pSecondsElapsed) {
secPassed += dt;
}

updateCounterTexts();

if (Multiplayer.isMultiplayer)
{
long mSecElapsed = (long) (pSecondsElapsed * 1000);
Expand Down Expand Up @@ -2683,7 +2671,7 @@ public void registerAccuracy(final double acc) {
if (hitErrorMeter != null) {
hitErrorMeter.putErrorResult((float) acc);
}
avgOffset += (float) acc;
offsetSum += (float) acc;
offsetRegs++;

stat.addHitOffset(acc);
Expand Down Expand Up @@ -2838,6 +2826,34 @@ public boolean saveFailedReplay() {
}
}

private void updateCounterTexts() {
// We are not updating FPS text as it is handled by FPSCounter, as well
// as PP text as it is updated in updatePPCounter.
if (avgOffsetText != null) {
float avgOffset = offsetRegs > 0 ? offsetSum / offsetRegs : 0;

avgOffsetText.setText("Avg offset: " + (int) (avgOffset * 1000f) + "ms");
}

if (urText != null) {
urText.setText(String.format(Locale.ENGLISH, "%.2f UR ", stat != null ? stat.getUnstableRate() : 0));
}

if (BuildConfig.DEBUG) {
var totalMemory = Runtime.getRuntime().totalMemory();
var usedMemory = totalMemory - Runtime.getRuntime().freeMemory();

memText.setText(usedMemory / 1024 / 1024 + "/" + totalMemory / 1024 / 1024 + " MB ");
}

// Update counter text positions
for (int i = 0; i < counterTexts.size(); ++i) {
var text = counterTexts.get(i);

text.setPosition(Config.getRES_WIDTH() - text.getWidth() - 5, Config.getRES_HEIGHT() - text.getHeight() - 10 - i * text.getHeight());
}
}

private void updatePPCounter(int objectId) {
if (ppText == null) {
return;
Expand Down

0 comments on commit 49589a3

Please sign in to comment.