1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-04-09 13:54:55 +00:00

add fps option

This commit is contained in:
lemz 2024-05-25 01:11:34 +02:00
parent 25016f45f9
commit e0fe7cb1eb
4 changed files with 207 additions and 52 deletions

View file

@ -2,6 +2,7 @@ package;
import flixel.FlxGame; import flixel.FlxGame;
import flixel.FlxState; import flixel.FlxState;
import funkin.Preferences;
import funkin.util.logging.CrashHandler; import funkin.util.logging.CrashHandler;
import funkin.ui.debug.MemoryCounter; import funkin.ui.debug.MemoryCounter;
import funkin.save.Save; import funkin.save.Save;
@ -22,12 +23,6 @@ class Main extends Sprite
var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom). var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = funkin.InitState; // The FlxState the game starts with. var initialState:Class<FlxState> = funkin.InitState; // The FlxState the game starts with.
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions. var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
#if web
var framerate:Int = 60; // How many frames per second the game should run at.
#else
// TODO: This should probably be in the options menu?
var framerate:Int = 144; // How many frames per second the game should run at.
#end
var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode. var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode.
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
@ -103,7 +98,7 @@ class Main extends Sprite
// George recommends binding the save before FlxGame is created. // George recommends binding the save before FlxGame is created.
Save.load(); Save.load();
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash, startFullscreen); var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash, startFullscreen);
// FlxG.game._customSoundTray wants just the class, it calls new from // FlxG.game._customSoundTray wants just the class, it calls new from
// create() in there, which gets called when it's added to stage // create() in there, which gets called when it's added to stage

View file

@ -7,6 +7,35 @@ import funkin.save.Save;
*/ */
class Preferences class Preferences
{ {
/**
* FPS
* @default `60`
*/
public static var framerate(get, set):Int;
static function get_framerate():Int
{
#if web
return 60;
#else
return Save?.instance?.options?.framerate ?? 60;
#end
}
static function set_framerate(value:Int):Int
{
#if web
return 60;
#else
var save:Save = Save.instance;
save.options.framerate = value;
save.flush();
FlxG.updateFramerate = value;
FlxG.drawFramerate = value;
return value;
#end
}
/** /**
* Whether some particularly fowl language is displayed. * Whether some particularly fowl language is displayed.
* @default `true` * @default `true`

View file

@ -53,7 +53,8 @@ class Save
public function new(?data:RawSaveData) public function new(?data:RawSaveData)
{ {
if (data == null) this.data = Save.getDefault(); if (data == null) this.data = Save.getDefault();
else this.data = data; else
this.data = data;
} }
public static function getDefault():RawSaveData public static function getDefault():RawSaveData
@ -80,6 +81,7 @@ class Save
options: options:
{ {
// Reasonable defaults. // Reasonable defaults.
framerate: 60,
naughtyness: true, naughtyness: true,
downscroll: false, downscroll: false,
flashingLights: true, flashingLights: true,
@ -835,6 +837,12 @@ typedef SaveScoreTallyData =
*/ */
typedef SaveDataOptions = typedef SaveDataOptions =
{ {
/**
* FPS
* @default `60`
*/
var framerate:Int;
/** /**
* Whether some particularly fowl language is displayed. * Whether some particularly fowl language is displayed.
* @default `true` * @default `true`

View file

@ -3,16 +3,16 @@ package funkin.ui.options;
import flixel.FlxCamera; import flixel.FlxCamera;
import flixel.FlxObject; import flixel.FlxObject;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.math.FlxMath;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import funkin.ui.AtlasText.AtlasFont; import funkin.ui.AtlasText.AtlasFont;
import funkin.ui.options.OptionsState.Page; import funkin.ui.options.OptionsState.Page;
import funkin.graphics.FunkinCamera; import funkin.graphics.FunkinCamera;
import funkin.ui.TextMenuList.TextMenuItem;
class PreferencesMenu extends Page class PreferencesMenu extends Page
{ {
var items:TextMenuList; var curSelected:Int = 0;
var preferenceItems:FlxTypedSpriteGroup<FlxSprite>; var prefs:FlxTypedSpriteGroup<PreferenceItem>;
var menuCamera:FlxCamera; var menuCamera:FlxCamera;
var camFollow:FlxObject; var camFollow:FlxObject;
@ -26,22 +26,27 @@ class PreferencesMenu extends Page
menuCamera.bgColor = 0x0; menuCamera.bgColor = 0x0;
camera = menuCamera; camera = menuCamera;
add(items = new TextMenuList()); prefs = new FlxTypedSpriteGroup<PreferenceItem>();
add(preferenceItems = new FlxTypedSpriteGroup<FlxSprite>()); add(prefs);
createPrefItems(); createPrefItems();
camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70); camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70);
if (items != null) camFollow.y = items.selectedItem.y;
menuCamera.follow(camFollow, null, 0.06); menuCamera.follow(camFollow, null, 0.06);
var margin = 160; var margin = 160;
menuCamera.deadzone.set(0, margin, menuCamera.width, 40); menuCamera.deadzone.set(0, margin, menuCamera.width, 40);
menuCamera.minScrollY = 0; menuCamera.minScrollY = 0;
items.onChange.add(function(selected) { changeSelection(0);
camFollow.y = selected.y; }
});
function addPref(pref:PreferenceItem):Void
{
pref.x = 0;
pref.y = 120 * prefs.length;
pref.ID = prefs.length;
prefs.add(pref);
} }
/** /**
@ -49,50 +54,168 @@ class PreferencesMenu extends Page
*/ */
function createPrefItems():Void function createPrefItems():Void
{ {
createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { #if !web
Preferences.naughtyness = value; var pref:NumberedPreferenceItem = new NumberedPreferenceItem("FPS", "The framerate that the game is running on", Preferences.framerate,
}, Preferences.naughtyness); function(value:Float):Void {
createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void { Preferences.framerate = Std.int(value);
Preferences.downscroll = value; });
}, Preferences.downscroll); pref.minValue = 60;
createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void { pref.maxValue = 360;
Preferences.flashingLights = value; pref.changeRate = 1;
}, Preferences.flashingLights); pref.changeSpeed = 0.05;
createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void { addPref(pref);
Preferences.zoomCamera = value; #end
}, Preferences.zoomCamera);
createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void { // TODO: add these back
Preferences.debugDisplay = value; // createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void {
}, Preferences.debugDisplay); // Preferences.naughtyness = value;
createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void { // }, Preferences.naughtyness);
Preferences.autoPause = value; // createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void {
}, Preferences.autoPause); // Preferences.downscroll = value;
// }, Preferences.downscroll);
// createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void {
// Preferences.flashingLights = value;
// }, Preferences.flashingLights);
// createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void {
// Preferences.zoomCamera = value;
// }, Preferences.zoomCamera);
// createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void {
// Preferences.debugDisplay = value;
// }, Preferences.debugDisplay);
// createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void {
// Preferences.autoPause = value;
// }, Preferences.autoPause);
} }
function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void function changeSelection(change:Int):Void
{ {
var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue); curSelected += change;
if (curSelected < 0)
{
curSelected = prefs.length - 1;
}
else if (curSelected >= prefs.length)
{
curSelected = 0;
}
items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { for (pref in prefs)
var value = !checkbox.currentValue; {
onChange(value); pref.x = 0;
checkbox.currentValue = value; if (pref.ID == curSelected)
}); {
pref.x = 20;
preferenceItems.add(checkbox); camFollow.y = pref.y;
}
}
} }
override function update(elapsed:Float) override function update(elapsed:Float):Void
{ {
super.update(elapsed); super.update(elapsed);
// Indent the selected item. if (controls.UI_DOWN_P)
// TODO: Only do this on menu change? {
items.forEach(function(daItem:TextMenuItem) { changeSelection(1);
if (items.selectedItem == daItem) daItem.x = 150; }
else else if (controls.UI_UP_P)
daItem.x = 120; {
}); changeSelection(-1);
}
var selectedPref:PreferenceItem = prefs.members[curSelected];
selectedPref.handleInput(elapsed);
}
}
class PreferenceItem extends FlxTypedSpriteGroup<FlxSprite>
{
public var name:String = "";
public var description:String = "";
public function handleInput(deltaTime:Float):Void {}
}
class NumberedPreferenceItem extends PreferenceItem
{
public var onChange:Float->Void;
public var changeRate:Float = 1.0;
public var changeSpeed:Float = 0.1;
public var minValue(default, set):Null<Float>;
function set_minValue(value:Float):Float
{
minValue = value;
currentValue = currentValue;
return value;
}
public var maxValue(default, set):Null<Float>;
function set_maxValue(value:Float):Float
{
maxValue = value;
currentValue = currentValue;
return value;
}
public var currentValue(default, set):Float;
function set_currentValue(value:Float):Float
{
currentValue = FlxMath.bound(value, minValue, maxValue);
onChange(currentValue);
updateText();
return currentValue;
}
var valueText:AtlasText;
var preferenceText:AtlasText;
public function new(name:String, description:String, defaultValue:Float, onChange:Float->Void)
{
super();
this.valueText = new AtlasText(0, 0, '$defaultValue', AtlasFont.DEFAULT);
add(this.valueText);
this.preferenceText = new AtlasText(this.valueText.width + 30, 0, '$name', AtlasFont.BOLD);
add(this.preferenceText);
this.name = name;
this.description = description;
this.onChange = onChange;
this.currentValue = defaultValue;
}
var timeToWait:Float = 0;
public override function handleInput(deltaTime:Float):Void
{
timeToWait -= deltaTime;
if (timeToWait > 0)
{
return;
}
if (PlayerSettings.player1.controls.UI_RIGHT)
{
currentValue += changeRate;
timeToWait = changeSpeed;
}
else if (PlayerSettings.player1.controls.UI_LEFT)
{
currentValue -= changeRate;
timeToWait = changeSpeed;
}
}
function updateText():Void
{
valueText.text = '$currentValue';
preferenceText.x = valueText.width + 30;
} }
} }