mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-05-10 19:41:39 +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;
|
// throw e;
|
||||||
// }
|
// }
|
||||||
// world.update(dt);
|
// world.update(dt);
|
||||||
ProfilerUI.update(this.engine.fps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,24 @@ class MarbleGame {
|
||||||
touchInput.update();
|
touchInput.update();
|
||||||
}
|
}
|
||||||
if (!paused || world.isMultiplayer) {
|
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);
|
world.update(dt * Debug.timeScale);
|
||||||
|
ProfilerUI.update(h3d.Engine.getCurrent().fps);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
if (((Key.isPressed(Key.ESCAPE) #if js && paused #end) || Gamepad.isPressed(["start"]))
|
if (((Key.isPressed(Key.ESCAPE) #if js && paused #end) || Gamepad.isPressed(["start"]))
|
||||||
&& world.finishTime == null
|
&& world.finishTime == null
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ typedef OptionsSettings = {
|
||||||
var musicVolume:Float;
|
var musicVolume:Float;
|
||||||
var soundVolume:Float;
|
var soundVolume:Float;
|
||||||
var vsync:Bool;
|
var vsync:Bool;
|
||||||
|
var fpsLimit:Float;
|
||||||
var fovX:Int;
|
var fovX:Int;
|
||||||
var frameRateVis:Bool;
|
var frameRateVis:Bool;
|
||||||
var oobInsults:Bool;
|
var oobInsults:Bool;
|
||||||
|
|
@ -142,6 +143,7 @@ class Settings {
|
||||||
marbleShader: "Default",
|
marbleShader: "Default",
|
||||||
rewindEnabled: false,
|
rewindEnabled: false,
|
||||||
rewindTimescale: 1,
|
rewindTimescale: 1,
|
||||||
|
fpsLimit: -1,
|
||||||
vsync: #if js true #end
|
vsync: #if js true #end
|
||||||
#if hl
|
#if hl
|
||||||
false
|
false
|
||||||
|
|
@ -240,9 +242,10 @@ class Settings {
|
||||||
#if hl
|
#if hl
|
||||||
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
|
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
|
||||||
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
|
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
|
||||||
|
|
||||||
|
Window.getInstance().vsync = optionsSettings.vsync;
|
||||||
#end
|
#end
|
||||||
AudioManager.updateVolumes();
|
AudioManager.updateVolumes();
|
||||||
Window.getInstance().vsync = optionsSettings.vsync;
|
|
||||||
|
|
||||||
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
|
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
|
||||||
save();
|
save();
|
||||||
|
|
@ -381,6 +384,8 @@ class Settings {
|
||||||
optionsSettings.rewindEnabled = false;
|
optionsSettings.rewindEnabled = false;
|
||||||
if (optionsSettings.rewindTimescale == 0 #if js || optionsSettings.rewindTimescale == null #end)
|
if (optionsSettings.rewindTimescale == 0 #if js || optionsSettings.rewindTimescale == null #end)
|
||||||
optionsSettings.rewindTimescale = 1;
|
optionsSettings.rewindTimescale = 1;
|
||||||
|
if (optionsSettings.fpsLimit == 0 #if js || optionsSettings.fpsLimit == null #end)
|
||||||
|
optionsSettings.fpsLimit = -1;
|
||||||
controlsSettings = json.controls;
|
controlsSettings = json.controls;
|
||||||
if (json.touch != null) {
|
if (json.touch != null) {
|
||||||
touchSettings = json.touch;
|
touchSettings = json.touch;
|
||||||
|
|
|
||||||
|
|
@ -324,10 +324,42 @@ class OptionsDlg extends GuiImage {
|
||||||
["Disabled", "Enabled"], (idx) -> {
|
["Disabled", "Enabled"], (idx) -> {
|
||||||
Settings.optionsSettings.reflectiveMarble = idx == 1;
|
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"],
|
makeOption("Vertical Sync:", () -> '${Settings.optionsSettings.vsync ? "Enabled" : "Disabled"}', yPos, generalPanel, "small", ["Disabled", "Enabled"],
|
||||||
(idx) -> {
|
(idx) -> {
|
||||||
Settings.optionsSettings.vsync = idx == 1;
|
Settings.optionsSettings.vsync = idx == 1;
|
||||||
}, true);
|
}, true);
|
||||||
|
#end
|
||||||
|
|
||||||
yPos += 56;
|
yPos += 56;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue