Skip to content

Commit

Permalink
peak
Browse files Browse the repository at this point in the history
Added Rainbow FPS
Fixed FPS counter not updating when on 60 FPS
Sort of GC improvements
barely any performance improvements
  • Loading branch information
JordanSantiagoYT committed Nov 18, 2023
1 parent a180416 commit 4eb6376
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 36 deletions.
5 changes: 5 additions & 0 deletions source/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ClientPrefs { //default settings if it can't find a save file containing y
public static var showRamUsage:Bool = true;
public static var showMaxRamUsage:Bool = true;
public static var rainbowNotes:Bool = false;
public static var rainbowFPS:Bool = false;
public static var widescreenSweep:Bool = false;
public static var bfIconStyle:String = 'Default';
public static var strumLitStyle:String = 'Full Anim';
Expand Down Expand Up @@ -324,6 +325,7 @@ class ClientPrefs { //default settings if it can't find a save file containing y
FlxG.save.data.ratingCounter = ratingCounter;
FlxG.save.data.colorRatingHit = colorRatingHit;
FlxG.save.data.rainbowNotes = rainbowNotes;
FlxG.save.data.rainbowFPS = rainbowFPS;
FlxG.save.data.widescreenSweep = widescreenSweep;
FlxG.save.data.healthGainType = healthGainType;
FlxG.save.data.oppNoteAlpha = oppNoteAlpha;
Expand Down Expand Up @@ -535,6 +537,9 @@ class ClientPrefs { //default settings if it can't find a save file containing y
if(FlxG.save.data.rainbowNotes != null) {
rainbowNotes = FlxG.save.data.rainbowNotes;
}
if(FlxG.save.data.rainbowFPS != null) {
rainbowFPS = FlxG.save.data.rainbowFPS;
}
if(FlxG.save.data.widescreenSweep != null) {
widescreenSweep = FlxG.save.data.widescreenSweep;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Main extends Sprite {
#end
}

public function changeFPSColor(color:FlxColor) {
public static function changeFPSColor(color:FlxColor) {
fpsVar.textColor = color;
}

Expand Down
41 changes: 36 additions & 5 deletions source/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import lime.media.AudioBuffer;

import flash.media.Sound;

#if cpp
import cpp.vm.Gc;
#elseif hl
import hl.Gc;
#elseif neko
import neko.vm.Gc;
#end

using StringTools;

class Paths
Expand Down Expand Up @@ -70,6 +78,29 @@ class Paths
SUtil.getPath() + 'assets/shared/music/breakfast.$SOUND_EXT',
SUtil.getPath() + 'assets/shared/music/tea-time.$SOUND_EXT',
];

@:noCompletion private inline static function _gc(major:Bool) {
#if (cpp || neko)
Gc.run(major);
#elseif hl
Gc.major();
#end
}

@:noCompletion public inline static function compress() {
#if cpp
Gc.compact();
#elseif hl
Gc.major();
#elseif neko
Gc.run(true);
#end
}

public inline static function gc(major:Bool = false, repeat:Int = 1) {
while(repeat-- > 0) _gc(major);
}

/// haya I love you for the base cache dump I took to the max
public static function clearUnusedMemory() {
// clear non local assets in the tracked assets list
Expand All @@ -91,12 +122,10 @@ class Paths
}
}
// run the garbage collector for good measure lmfao
#if sys
openfl.system.System.gc();
#elseif cpp
cpp.vm.Gc.run();
#end
compress();
gc(true);
}

// define the locally tracked assets
public static var localTrackedAssets:Array<String> = [];
public static function clearStoredMemory(?cleanUnused:Bool = false) {
Expand All @@ -123,6 +152,8 @@ class Paths
// flags everything to be cleared out next unused memory clear
localTrackedAssets = [];
#if !html5 openfl.Assets.cache.clear("songs"); #end
gc(true);
compress();
}

static public var currentModDirectory:String = '';
Expand Down
52 changes: 30 additions & 22 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class PlayState extends MusicBeatState
public static var deathanim:Bool = false;
public static var dead:Bool = false;

public static var iconOffset:Int = 26;

var tankmanAscend:Bool = false; // funni (2021 nostalgia oh my god)

public var notes:FlxTypedGroup<Note>;
Expand Down Expand Up @@ -4803,7 +4805,7 @@ class PlayState extends MusicBeatState
}

if(!inCutscene) {
var lerpVal:Float = CoolUtil.boundTo(elapsed * 2.4 * cameraSpeed * playbackRate, 0, 1);
final lerpVal:Float = CoolUtil.boundTo(elapsed * 2.4 * cameraSpeed * playbackRate, 0, 1);
camFollowPos.setPosition(FlxMath.lerp(camFollowPos.x + moveCamTo[0]/102, camFollow.x + moveCamTo[0]/102, lerpVal), FlxMath.lerp(camFollowPos.y + moveCamTo[1]/102, camFollow.y + moveCamTo[1]/102, lerpVal));
if (ClientPrefs.charsAndBG) {
if(!startingSong && !endingSong && boyfriend.animation.curAnim != null && boyfriend.animation.curAnim.name.startsWith('idle')) {
Expand Down Expand Up @@ -4915,9 +4917,6 @@ if (ClientPrefs.showNPS) {
+ '\nVideo Speedup: ' + Math.abs(playbackRate / playbackRate / playbackRate) + 'x';
}

if (combo > maxCombo)
maxCombo = combo;

super.update(elapsed);
judgeCountUpdateFrame = 0;
compactUpdateFrame = 0;
Expand Down Expand Up @@ -5177,13 +5176,13 @@ if (ClientPrefs.showNPS) {
iconP2.setGraphicSize(Std.int(FlxMath.lerp(150, iconP2.width, 0.8 / playbackRate)),Std.int(FlxMath.lerp(150, iconP2.height, 0.8 / playbackRate)));
}
if (ClientPrefs.iconBounceType == 'Plank Engine') {
var funnyBeat = (Conductor.songPosition / 1000) * (Conductor.bpm / 60);
final funnyBeat = (Conductor.songPosition / 1000) * (Conductor.bpm / 60);

iconP1.offset.y = Math.abs(Math.sin(funnyBeat * Math.PI)) * 16 - 4;
iconP2.offset.y = Math.abs(Math.sin(funnyBeat * Math.PI)) * 16 - 4;
}
if (ClientPrefs.iconBounceType == 'New Psych' || ClientPrefs.iconBounceType == 'SB Engine') {
var mult:Float = FlxMath.lerp(1, iconP1.scale.x, CoolUtil.boundTo(1 - (elapsed * 9 * playbackRate), 0, 1));
final mult:Float = FlxMath.lerp(1, iconP1.scale.x, CoolUtil.boundTo(1 - (elapsed * 9 * playbackRate), 0, 1));
iconP1.scale.set(mult, mult);
iconP1.updateHitbox();

Expand All @@ -5192,7 +5191,7 @@ if (ClientPrefs.showNPS) {
iconP2.updateHitbox();
}
if (ClientPrefs.iconBounceType == 'VS Steve') {
var mult:Float = FlxMath.lerp(1, iconP1.scale.x, CoolUtil.boundTo(1 - (elapsed * 9 * playbackRate), 0, 1));
final mult:Float = FlxMath.lerp(1, iconP1.scale.x, CoolUtil.boundTo(1 - (elapsed * 9 * playbackRate), 0, 1));
iconP1.scale.set(mult, mult);
iconP1.updateHitbox();

Expand Down Expand Up @@ -5230,8 +5229,6 @@ if (ClientPrefs.showNPS) {
}
iconP1.updateHitbox();
iconP2.updateHitbox();

var iconOffset:Int = 26;

if (ClientPrefs.smoothHealth && ClientPrefs.smoothHealthType != 'Golden Apple 1.5' || !ClientPrefs.smoothHealth) //checks if you're using smooth health. if you are, but are not using the indie cross one then you know what that means
{
Expand Down Expand Up @@ -5382,27 +5379,34 @@ if (ClientPrefs.showNPS) {
if(secondsShown.length < 2) secondsShown = '0' + secondsShown; //let's see if the old time format works actually
if (minutesShownShit.length < 2) minutesShownShit = '0' + minutesShown;


if(ClientPrefs.timeBarType != 'Song Name' && songLength <= 3600000)
switch (ClientPrefs.timeBarType)
{
case 'Time Left', 'Time Elapsed':
if(songLength <= 3600000)
timeTxt.text = FlxStringUtil.formatTime(secondsTotal, false);
else
timeTxt.text = hoursRemaining + ':' + minutesRemainingShit + ':' + secondsRemaining;

if(ClientPrefs.timeBarType != 'Song Name' && songLength >= 3600000)
timeTxt.text = hoursRemaining + ':' + minutesRemainingShit + ':' + secondsRemaining;

if(ClientPrefs.timeBarType == 'Modern Time' && songLength <= 3600000)
case 'Modern Time':
if(songLength <= 3600000)
timeTxt.text = FlxStringUtil.formatTime(secondsTotal, false) + ' / ' + FlxStringUtil.formatTime(songLength / 1000, false);

if(ClientPrefs.timeBarType == 'Modern Time' && songLength >= 3600000)
else
timeTxt.text = hoursRemaining + ':' + minutesRemainingShit + ':' + secondsRemaining + ' / ' + hoursShown + ':' + minutesShownShit + ':' + secondsShown;

if(ClientPrefs.timeBarType == 'Song Name + Time' && songLength <= 3600000)

case 'Song Name + Time':
if(songLength <= 3600000)
timeTxt.text = SONG.song + ' (' + FlxStringUtil.formatTime(secondsTotal, false) + ' / ' + FlxStringUtil.formatTime(songLength / 1000, false) + ')';

if(ClientPrefs.timeBarType == 'Song Name + Time' && songLength >= 3600000)
else
timeTxt.text = SONG.song + ' (' + hoursRemaining + ':' + minutesRemainingShit + ':' + secondsRemaining + ' / ' + hoursShown + ':' + minutesShownShit + ':' + secondsShown + ')';
}

if(ClientPrefs.timebarShowSpeed && ClientPrefs.timeBarType != 'Song Name') timeTxt.text += ' (' + playbackRateDecimal + 'x)';
if(ClientPrefs.timebarShowSpeed && ClientPrefs.timeBarType == 'Song Name') timeTxt.text = SONG.song + ' (' + playbackRateDecimal + 'x)';
if(ClientPrefs.timebarShowSpeed)
{
if (ClientPrefs.timeBarType != 'Song Name')
timeTxt.text += ' (' + playbackRateDecimal + 'x)';
else timeTxt.text = SONG.song + ' (' + playbackRateDecimal + 'x)';
}
if (cpuControlled && ClientPrefs.timeBarType != 'Song Name' && !ClientPrefs.communityGameBot) timeTxt.text += ' (Bot)';
if(ClientPrefs.timebarShowSpeed && cpuControlled && ClientPrefs.timeBarType == 'Song Name') timeTxt.text = SONG.song + ' (' + playbackRateDecimal + 'x) (Bot)';
}
Expand Down Expand Up @@ -8123,6 +8127,10 @@ if (!allSicks && ClientPrefs.colorRatingFC && songMisses > 0 && ClientPrefs.hudT
}
popUpScore(note);
}

if (combo > maxCombo)
maxCombo = combo;

if (ClientPrefs.healthGainType == 'Psych Engine' || ClientPrefs.healthGainType == 'Leather Engine' || ClientPrefs.healthGainType == 'Kade (1.2)' || ClientPrefs.healthGainType == 'Kade (1.6+)' || ClientPrefs.healthGainType == 'Doki Doki+' || ClientPrefs.healthGainType == 'VS Impostor') {
health += note.hitHealth * healthGain * polyphony;
}
Expand Down
68 changes: 60 additions & 8 deletions source/openfl/display/FPS.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import external.memory.Memory;
import openfl.system.System;
#end
import Main;
import flixel.util.FlxColor;

/**
The FPS class provides an easy-to-use monitor to display
Expand Down Expand Up @@ -51,7 +52,7 @@ class FPS extends TextField
currentFPS = 0;
selectable = false;
mouseEnabled = false;
defaultTextFormat = new TextFormat("_sans", 12, color);
defaultTextFormat = new TextFormat("VCR OSD Mono", 12, color);
autoSize = LEFT;
multiline = true;
text = "FPS: ";
Expand All @@ -69,6 +70,11 @@ class FPS extends TextField
#end
}

// All the colors: Red, Orange, Yellow, Green, Blue, Violet/Purple
final rainbowColors:Array<Int> = [0xFFFF0000, 0xFFFFA500, 0xFFFFFF00, 0xFF00FF00, 0xFF0000FF, 0xFFFF00FF];
var colorInterp:Float = 0;
var currentColor:Int = 0;

// Event Handlers
@:noCompletion
private #if !flash override #end function __enterFrame(deltaTime:Float):Void
Expand All @@ -81,14 +87,12 @@ class FPS extends TextField
times.shift();
}

//Literally the stupidest thing i've done for the FPS counter but it allows it to update correctly when on 60 FPS??
var currentCount = times.length;
currentFPS = Math.round((currentCount + cacheCount) / 2);
if (currentFPS > ClientPrefs.framerate) currentFPS = ClientPrefs.framerate;

if (currentCount != cacheCount /*&& visible*/)
{
text = (ClientPrefs.showFPS ? "FPS: " + currentFPS : "");
var memoryMegas:Float = 0;

if (ClientPrefs.showRamUsage) text += "\nMemory: " + CoolUtil.formatBytes(Memory.getCurrentUsage(), false, 2) + (ClientPrefs.showMaxRamUsage ? " / " + CoolUtil.formatBytes(Memory.getPeakUsage(), false, 2) : "");

Expand All @@ -100,10 +104,35 @@ class FPS extends TextField
text += "\nText bitmaps generated: " + Main.textGenerations;
}

textColor = 0xFFFFFFFF;
if (currentFPS <= ClientPrefs.framerate / 2)
if (ClientPrefs.rainbowFPS)
{
colorInterp += deltaTime / 330; // Division so that it doesn't give you a seizure on 60 FPS
var colorIndex1:Int = Math.floor(colorInterp);
var colorIndex2:Int = (colorIndex1 + 1) % rainbowColors.length;

var startColor:Int = rainbowColors[colorIndex1];
var endColor:Int = rainbowColors[colorIndex2];

var segmentInterp:Float = colorInterp - colorIndex1;

var interpolatedColor:Int = interpolateColor(startColor, endColor, segmentInterp);

textColor = interpolatedColor;

// Check if the current color segment interpolation is complete
if (colorInterp >= rainbowColors.length) {
// Reset colorInterp to start the interpolation cycle again
textColor = rainbowColors[0];
colorInterp = 0;
}
}
else
{
textColor = 0xFFFF0000;
textColor = 0xFFFFFFFF;
if (currentFPS <= ClientPrefs.framerate / 2)
{
textColor = 0xFFFF0000;
}
}

#if (gl_stats && !disable_cffi && (!html5 || !canvas))
Expand All @@ -113,8 +142,31 @@ class FPS extends TextField
#end

text += "\n";
}

cacheCount = currentCount;
}
private function interpolateColor(startColor:Int, endColor:Int, t:Float):Int {
// Extract color components (RGBA) from startColor
var startR:Int = (startColor >> 16) & 0xFF;
var startG:Int = (startColor >> 8) & 0xFF;
var startB:Int = startColor & 0xFF;
var startA:Int = (startColor >> 24) & 0xFF;

// Extract color components (RGBA) from endColor
var endR:Int = (endColor >> 16) & 0xFF;
var endG:Int = (endColor >> 8) & 0xFF;
var endB:Int = endColor & 0xFF;
var endA:Int = (endColor >> 24) & 0xFF;

// Perform linear interpolation for each color component
var interpolatedR:Int = Math.round(startR + t * (endR - startR));
var interpolatedG:Int = Math.round(startG + t * (endG - startG));
var interpolatedB:Int = Math.round(startB + t * (endB - startB));
var interpolatedA:Int = Math.round(startA + t * (endA - startA));

// Combine interpolated color components into a single color value
var interpolatedColor:Int = (interpolatedA << 24) | (interpolatedR << 16) | (interpolatedG << 8) | interpolatedB;

return interpolatedColor;
}
}
17 changes: 17 additions & 0 deletions source/options/SuperSecretDebugMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ class SuperSecretDebugMenu extends BaseOptionsMenu
option.onChange = doDaUpdate;
addOption(option);

var option:Option = new Option('Rainbow FPS',
"If checked, allows the FPS color to be rainbow.",
'rainbowFPS',
'bool',
false);

option.onChange = onChangeRainbowFPS;
addOption(option);

/* doesnt work
var option:Option = new Option('WIDESCREEN SWEEP',
"cool stuff hehe, hidden cause not every mod is compatible with it.",
Expand Down Expand Up @@ -184,4 +193,12 @@ class SuperSecretDebugMenu extends BaseOptionsMenu

MusicBeatState.switchState(new OutdatedState());
}

function onChangeRainbowFPS()
{
if(!ClientPrefs.rainbowFPS)
{
Main.changeFPSColor(0xFFFFFFFF);
}
}
}

0 comments on commit 4eb6376

Please sign in to comment.