diff --git a/src/Main.hx b/src/Main.hx index 32af4b6f..1ce70815 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -157,7 +157,6 @@ class Main extends hxd.App { // throw e; // } // world.update(dt); - ProfilerUI.update(this.engine.fps); } } diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 12e6ad22..83bb1592 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -221,7 +221,24 @@ class MarbleGame { touchInput.update(); } if (!paused || world.isMultiplayer) { + #if hl + static var dtAccumulator; + dtAccumulator += dt * Debug.timeScale; + if (Settings.optionsSettings.fpsLimit <= 0 || Settings.optionsSettings.vsync) { + world.update(dt * Debug.timeScale); + ProfilerUI.update(h3d.Engine.getCurrent().fps); + } else { + if (dtAccumulator >= 1.0 / Settings.optionsSettings.fpsLimit) { + world.update(dtAccumulator); + ProfilerUI.update(Math.floor((100.0 / dtAccumulator)) / 100); + dtAccumulator = 0.0; + } + } + #end + #if js world.update(dt * Debug.timeScale); + ProfilerUI.update(h3d.Engine.getCurrent().fps); + #end } if (((Key.isPressed(Key.ESCAPE) #if js && paused #end) || Gamepad.isPressed(["start"])) && world.finishTime == null diff --git a/src/Settings.hx b/src/Settings.hx index 9661175e..75a7436e 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -34,6 +34,7 @@ typedef OptionsSettings = { var musicVolume:Float; var soundVolume:Float; var vsync:Bool; + var fpsLimit:Float; var fovX:Int; var frameRateVis:Bool; var oobInsults:Bool; @@ -142,6 +143,7 @@ class Settings { marbleShader: "Default", rewindEnabled: false, rewindTimescale: 1, + fpsLimit: -1, vsync: #if js true #end #if hl false @@ -240,9 +242,10 @@ class Settings { #if hl Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight); Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed; + + Window.getInstance().vsync = optionsSettings.vsync; #end AudioManager.updateVolumes(); - Window.getInstance().vsync = optionsSettings.vsync; MarbleGame.canvas.render(MarbleGame.canvas.scene2d); save(); @@ -381,6 +384,8 @@ class Settings { optionsSettings.rewindEnabled = false; if (optionsSettings.rewindTimescale == 0 #if js || optionsSettings.rewindTimescale == null #end) optionsSettings.rewindTimescale = 1; + if (optionsSettings.fpsLimit == 0 #if js || optionsSettings.fpsLimit == null #end) + optionsSettings.fpsLimit = -1; controlsSettings = json.controls; if (json.touch != null) { touchSettings = json.touch; diff --git a/src/gui/OptionsDlg.hx b/src/gui/OptionsDlg.hx index c889ea11..26153071 100644 --- a/src/gui/OptionsDlg.hx +++ b/src/gui/OptionsDlg.hx @@ -324,10 +324,42 @@ class OptionsDlg extends GuiImage { ["Disabled", "Enabled"], (idx) -> { Settings.optionsSettings.reflectiveMarble = idx == 1; }); + #if hl + makeOption("FPS:", () -> { + if (Settings.optionsSettings.vsync) + return "VSync"; + if (Settings.optionsSettings.fpsLimit == -1) + return "Unlimited"; + return '${Math.floor(Settings.optionsSettings.fpsLimit)}'; + }, yPos, generalPanel, "xlarge", + ["VSync", "60", "120", "200", "500", "Unlimited"], (idx) -> { + switch (idx) { + case 0: + Settings.optionsSettings.vsync = true; + case 1: + Settings.optionsSettings.fpsLimit = 60; + Settings.optionsSettings.vsync = false; + case 2: + Settings.optionsSettings.fpsLimit = 120; + Settings.optionsSettings.vsync = false; + case 3: + Settings.optionsSettings.fpsLimit = 200; + Settings.optionsSettings.vsync = false; + case 4: + Settings.optionsSettings.fpsLimit = 500; + Settings.optionsSettings.vsync = false; + case 5: + Settings.optionsSettings.fpsLimit = -1; + Settings.optionsSettings.vsync = false; + } + }, true); + #end + #if js makeOption("Vertical Sync:", () -> '${Settings.optionsSettings.vsync ? "Enabled" : "Disabled"}', yPos, generalPanel, "small", ["Disabled", "Enabled"], (idx) -> { Settings.optionsSettings.vsync = idx == 1; }, true); + #end yPos += 56;