diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index 6489dc33bd4..226a8e96882 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -48,6 +48,7 @@ public class Forge implements ApplicationListener { private static int screenWidth; private static int screenHeight; private static Graphics graphics; + private static FrameRate frameRate; private static FScreen currentScreen; private static SplashScreen splashScreen; private static KeyInputAdapter keyInputAdapter; @@ -59,6 +60,7 @@ public class Forge implements ApplicationListener { public static String extrawide = "default"; public static float heigtModifier = 0.0f; private static boolean isloadingaMatch = false; + public static boolean showFPS = false; public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0) { if (GuiBase.getInterface() == null) { @@ -79,6 +81,7 @@ public class Forge implements ApplicationListener { graphics = new Graphics(); splashScreen = new SplashScreen(); + frameRate = new FrameRate(); Gdx.input.setInputProcessor(new MainInputProcessor()); /* Set CatchBackKey here and exit the app when you hit the @@ -101,6 +104,8 @@ public class Forge implements ApplicationListener { textureFiltering = prefs.getPrefBoolean(FPref.UI_LIBGDX_TEXTURE_FILTERING); + showFPS = prefs.getPrefBoolean(FPref.UI_SHOW_FPS); + final Localizer localizer = Localizer.getInstance(); //load model on background thread (using progress bar to report progress) @@ -366,6 +371,9 @@ public class Forge implements ApplicationListener { @Override public void render() { + if (showFPS) + frameRate.update(); + try { ImageCache.allowSingleLoad(); ForgeAnimation.advanceAll(); @@ -408,6 +416,8 @@ public class Forge implements ApplicationListener { graphics.end(); BugReporter.reportException(ex); } + if (showFPS) + frameRate.render(); } @Override diff --git a/forge-gui-mobile/src/forge/FrameRate.java b/forge-gui-mobile/src/forge/FrameRate.java new file mode 100644 index 00000000000..3c11b521d0b --- /dev/null +++ b/forge-gui-mobile/src/forge/FrameRate.java @@ -0,0 +1,62 @@ +package forge; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.TimeUtils; + +/** + * A nicer class for showing framerate that doesn't spam the console + * like Logger.log() + * + * @author William Hartman + */ + +public class FrameRate implements Disposable{ + long lastTimeCounted; + private float sinceChange; + private float frameRate; + private BitmapFont font; + private SpriteBatch batch; + private OrthographicCamera cam; + + public FrameRate() { + lastTimeCounted = TimeUtils.millis(); + sinceChange = 0; + frameRate = Gdx.graphics.getFramesPerSecond(); + font = new BitmapFont(); + batch = new SpriteBatch(); + cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } + + public void resize(int screenWidth, int screenHeight) { + cam = new OrthographicCamera(screenWidth, screenHeight); + cam.translate(screenWidth / 2, screenHeight / 2); + cam.update(); + batch.setProjectionMatrix(cam.combined); + } + + public void update() { + long delta = TimeUtils.timeSinceMillis(lastTimeCounted); + lastTimeCounted = TimeUtils.millis(); + sinceChange += delta; + if(sinceChange >= 1000) { + sinceChange = 0; + frameRate = Gdx.graphics.getFramesPerSecond(); + } + } + + public void render() { + batch.begin(); + font.draw(batch, (int)frameRate + " fps", 3, Gdx.graphics.getHeight() - 3); + batch.end(); + } + + public void dispose() { + font.dispose(); + batch.dispose(); + } + +} \ No newline at end of file diff --git a/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java b/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java index 5c672c12e1f..8e6812e8075 100644 --- a/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java +++ b/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java @@ -305,6 +305,16 @@ public class SettingsPage extends TabPage { "Enable Round Border Mask", "When enabled, the card corners are rounded (Preferably Card with Full Borders)."), 4); + lstSettings.addItem(new BooleanSetting(FPref.UI_SHOW_FPS, + "Show FPS Display", + "When enabled, show the FPS Display (Experimental)."){ + @Override + public void select() { + super.select(); + //update + Forge.showFPS = FModel.getPreferences().getPrefBoolean(FPref.UI_SHOW_FPS); + } + },4); lstSettings.addItem(new CustomSelectSetting(FPref.UI_CARD_COUNTER_DISPLAY_TYPE, localizer.getMessage("cbpCounterDisplayType"), diff --git a/forge-gui/src/main/java/forge/properties/ForgePreferences.java b/forge-gui/src/main/java/forge/properties/ForgePreferences.java index a43681bbcd1..3d64b2e8c55 100644 --- a/forge-gui/src/main/java/forge/properties/ForgePreferences.java +++ b/forge-gui/src/main/java/forge/properties/ForgePreferences.java @@ -135,6 +135,7 @@ public class ForgePreferences extends PreferencesStore { UI_DYNAMIC_PLANECHASE_BG("false"), UI_DISABLE_IMAGES_EFFECT_CARDS("false"), UI_ENABLE_BORDER_MASKING("false"), + UI_SHOW_FPS("false"), UI_ALLOW_ORDER_GRAVEYARD_WHEN_NEEDED ("Never"), UI_DEFAULT_FONT_SIZE("12"), UI_SELECT_FROM_CARD_DISPLAYS("true"),