Skip to content

Commit

Permalink
add fps limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael-Danilov committed Jan 6, 2025
1 parent 5f6fda1 commit 2ec9dda
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,8 @@ public static void openPlayStore() {
}
}

public static void updateFpsLimit() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ public void onFrame() {
switchScene(sceneClass.newInstance());
return;
}

while (!motionEvents.isEmpty()) {
Touchscreen.processEvent(motionEvents.poll());
}

while (!keysEvents.isEmpty()) {
Keys.processEvent(keysEvents.poll());
}

} catch (LuaError e) {
throw ModdingMode.modException(e);
} catch (Exception e) {
Expand Down Expand Up @@ -256,6 +247,14 @@ public void onFrame() {
@SneakyThrows
public void update() {
synchronized (stepLock) {
while (!motionEvents.isEmpty()) {
Touchscreen.processEvent(motionEvents.poll());
}

while (!keysEvents.isEmpty()) {
Keys.processEvent(keysEvents.poll());
}

elapsed = timeScale * step * 0.001f;
if (scene != null) {
scene.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,12 @@ static public void useLocale(String lang) {
public static void setSelectedLanguage() {
useLocale(uiLanguage());
}

public static void fps_limit(int value) {
Preferences.INSTANCE.put(CommonPrefs.KEY_FPS_LIMIT, value);
}

public static int fps_limit() {
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_FPS_LIMIT, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public class CommonPrefs {

public static final String KEY_MUSIC_VOLUME = "music_volume";
public static final String KEY_SOUND_FX_VOLUME = "soundfx_volume";
public static final String KEY_FPS_LIMIT = "fps_limit";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nyrds.pixeldungeon.windows.VBox;
import com.nyrds.platform.audio.MusicManager;
import com.nyrds.platform.audio.Sample;
import com.nyrds.platform.game.Game;
import com.nyrds.platform.util.StringsManager;
import com.watabou.noosa.Image;
import com.watabou.pixeldungeon.Assets;
Expand Down Expand Up @@ -38,25 +39,18 @@ public void onBackPressed() {
}

protected void addSoundControls(VBox menuItems) {
/*
menuItems.add(new MenuCheckBox(R.string.WndSettings_Music, GamePreferences.music()) {
@Override
protected void onClick() {
super.onClick();
GamePreferences.music(checked());
}
});

menuItems.add(new MenuCheckBox(R.string.WndSettings_Sound, GamePreferences.soundFx()) {
Slider fps = new Slider(R.string.WndSettings_FpsLimit, "30", "120", 0, 2) {
@Override
protected void onClick() {
super.onClick();
GamePreferences.soundFx(checked());
Sample.INSTANCE.play(Assets.SND_CLICK);
protected void onChange() {
int value = getSelectedValue();
GamePreferences.fps_limit(value);
Game.updateFpsLimit();
}
});
*/
};
fps.setSelectedValue(GamePreferences.fps_limit());
fps.setSize(WIDTH,BUTTON_HEIGHT);
menuItems.add(fps);

Slider sfx = new Slider(R.string.WndSettings_Sound, "0", "1", 0, 10) {
@Override
Expand Down
1 change: 1 addition & 0 deletions RemixedDungeon/src/main/res/values/strings_all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2978,5 +2978,6 @@ No, there was no place for her in the light, not anymore. She turned from the me
<string name="WndInstallingMod_deleting_file">Deleting %s</string>

<string name="Badges_ThisIsSparta">This is Sparta!!!</string>
<string name="WndSettings_FpsLimit">FPS limit</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.nyrds.pixeldungeon.game.GameLoop;
import com.nyrds.pixeldungeon.game.GamePreferences;
import com.nyrds.pixeldungeon.ml.BuildConfig;
import com.nyrds.pixeldungeon.support.PlayGames;
import com.nyrds.platform.app.RemixedDungeonApp;
Expand Down Expand Up @@ -258,4 +259,9 @@ public static void takeScreenshot() {

pixmap.dispose();
}

public static void updateFpsLimit() {
int[] limit = {30, 60, 120};
Gdx.graphics.setForegroundFPS(limit[GamePreferences.fps_limit()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public static boolean canDonate() {
public static void landscape(boolean value) {
}

public static boolean storedLandscape() {
return true;
}

public static boolean landscape() {
return true;
}
Expand Down Expand Up @@ -95,6 +91,8 @@ public void create() {
ModdingMode.selectMod(GamePreferences.activeMod());
GamePreferences.uiLanguage(GamePreferences.uiLanguage());

updateFpsLimit();

super.create();
}

Expand Down

0 comments on commit 2ec9dda

Please sign in to comment.