mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-01-03 22:02:23 +00:00
fps limiter
This commit is contained in:
parent
a4254f8771
commit
0a56019a53
4 changed files with 55 additions and 2 deletions
|
|
@ -157,7 +157,6 @@ class Main extends hxd.App {
|
|||
// throw e;
|
||||
// }
|
||||
// world.update(dt);
|
||||
ProfilerUI.update(this.engine.fps);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue