From 5249807ab664a8374df157ed88de27902c74e32c Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:57:09 -0500 Subject: [PATCH] Optimizations and cleanup --- source/Alphabet.hx | 8 +-- source/Conductor.hx | 10 ++- source/FinishSubState.hx | 2 +- source/Options.hx | 2 +- source/PauseSubState.hx | 7 +-- source/PlayState.hx | 82 +++++++------------------ source/SELoader.hx | 76 ++++++++++++----------- source/TitleState.hx | 14 ++--- source/onlinemod/OnlinePauseSubState.hx | 2 +- version.downloadMe | 2 +- 10 files changed, 84 insertions(+), 121 deletions(-) diff --git a/source/Alphabet.hx b/source/Alphabet.hx index 4b89e16..c8fcc09 100644 --- a/source/Alphabet.hx +++ b/source/Alphabet.hx @@ -167,13 +167,7 @@ class Alphabet extends FlxSpriteGroup if(SESave.data.useFontEverywhere){ Frames = new flixel.graphics.frames.FlxFramesCollection(FlxGraphic.fromRectangle(1,1,0x01000000,false,"blank.mp4")); }else{ - try{ - if(!SELoader.exists("mods/alphabet.png") || !SELoader.exists("mods/alphabet.xml")) throw(''); - Frames = SELoader.loadSparrowFrames('mods/alphabet'); - }catch(e){ - Frames = SELoader.loadSparrowFrames('assets/images/alphabet'); - // Paths.getSparrowAtlas('alphabet'); - } + Frames = SELoader.loadSparrowFrames((SELoader.exists("mods/alphabet.png") && SELoader.exists("mods/alphabet.xml")) ? 'mods/alphabet' : 'assets/images/alphabet'); } } this.text = text; diff --git a/source/Conductor.hx b/source/Conductor.hx index 6d4c18d..e746ffc 100644 --- a/source/Conductor.hx +++ b/source/Conductor.hx @@ -37,8 +37,16 @@ class Conductor { public static var bpmChangeMapSteps:Map = []; public function new(){} + public static var lastFrameTime:Float = 0; public static function update(){ - songPosition = FlxG.sound.music.time; + inline updateElapsed(FlxG.elapsed); + } + public static function updateElapsed(elapsed:Float){ + if(lastFrameTime == FlxG.sound.music.time){ + songPosition += elapsed * 1000; + }else{ + lastFrameTime = songPosition = FlxG.sound.music.time; + } } @:keep inline public static function recalculateTimings() { diff --git a/source/FinishSubState.hx b/source/FinishSubState.hx index b5ee467..e907773 100644 --- a/source/FinishSubState.hx +++ b/source/FinishSubState.hx @@ -2,7 +2,7 @@ package; import openfl.Lib; -import Controls.Control; +// import Controls.Control; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxSubState; diff --git a/source/Options.hx b/source/Options.hx index 3c872b5..a87fe91 100644 --- a/source/Options.hx +++ b/source/Options.hx @@ -577,7 +577,7 @@ class ScrollSpeedOption extends HCFloatOption{ } override public function draw(){ if(note == null || strum == null) return; - var dist = (Conductor.songPosition - note.strumTime); + var dist = ((Conductor.songPosition+FlxG.elapsed*0.001) - note.strumTime); var _scrollSpeed = SESave.data.scrollSpeed; Conductor.update(); if(dist > 1000 || pressed){ diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index 2678ea8..c12982f 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -480,7 +480,7 @@ class PauseSubState extends MusicBeatSubstate { ease: FlxEase.cubeInOut, // onComplete: function(twn:FlxTween) {ready.destroy();} }); - FlxG.sound.play(Paths.sound('intro2' + altSuffix), 0.6); + SELoader.playSound('assets/sounds/intro2' + altSuffix,0.6); case 2: var set:FlxSprite = spr.loadGraphic(Paths.image(introAlts[1])); tween.cancel(); @@ -495,7 +495,7 @@ class PauseSubState extends MusicBeatSubstate { ease: FlxEase.cubeInOut, // onComplete: function(twn:FlxTween) {set.destroy();} }); - FlxG.sound.play(Paths.sound('intro1' + altSuffix), 0.6); + SELoader.playSound('assets/sounds/intro1' + altSuffix,0.6); case 3: var go:FlxSprite = spr.loadGraphic(Paths.image(introAlts[2])); tween.cancel(); @@ -509,9 +509,8 @@ class PauseSubState extends MusicBeatSubstate { ease: FlxEase.cubeInOut, onComplete: function(twn:FlxTween) {go.destroy();} }); - FlxG.sound.play(Paths.sound('introGo' + altSuffix), 0.6); + SELoader.playSound('assets/sounds/introGo' + altSuffix,0.6); case 4: - backToPlaystate(); } diff --git a/source/PlayState.hx b/source/PlayState.hx index 8bdf3e2..5e0d98b 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -374,7 +374,7 @@ class PlayState extends ScriptMusicBeatState isFunc:true, value:value, check:type, - variable:(if(variable == "def") (if(check == 0) "curBeat" else "curStep") else variable), + variable:((variable == "def") ? ((check == 0) ? "curBeat" : "curStep") : variable), func:func, type:type }; @@ -732,7 +732,6 @@ class PlayState extends ScriptMusicBeatState } //dialogue shit - loadDialog(); LoadingScreen.loadingText = "Loading stage"; // Stage management var bfPos:Array = [0,0]; @@ -861,9 +860,6 @@ class PlayState extends ScriptMusicBeatState } if(loadChars && (SESave.data.gfShow || _dadShow || SESave.data.bfShow)){ - - - LoadingScreen.loadingText = "Loading GF"; if(gf== null || !SESave.data.persistGF || (!SESave.data.gfShow && !Std.isOfType(gf,EmptyCharacter)) || gf.getNamespacedName() != player2){ if (SESave.data.gfShow && gfShow) @@ -1164,33 +1160,6 @@ class PlayState extends ScriptMusicBeatState } #end } - function loadDialog(){ - // dialogue = []; - // switch (SONG.song.toLowerCase()) - // { - // case 'tutorial': - // dialogue = CoolUtil.coolFormat("4*"); - // case 'bopeebo': - // dialogue = CoolUtil.coolFormat( - // 'dad:HEY!\n' + - // 'bf:Beep?\n' + - // "dad:You think you can just sing\\nwith my daughter like that?\n" + - // 'bf:Beep' + - // "dad:If you want to date her...\\n" + - // "dad:You're going to have to go \\nthrough ME first!\n" + - // 'bf:Beep bop!' - // ); - // case 'fresh': - // dialogue = CoolUtil.coolFormat("dad:Not too shabby $BF.\ndad:But I'd like to see you\\n keep up with this!"); - // case 'dad battle': - // dialogue = CoolUtil.coolFormat( - // "dad:Gah, you think you're hot stuff?\n"+ - // "dad:If you can beat me here...\n"+ - // "dad:Only then I will even CONSIDER letting you\\ndate my daughter!"+ - // 'bf:Beep!' - // ); - // } - } @@ -1279,7 +1248,6 @@ class PlayState extends ScriptMusicBeatState } } if(underlay != null && SESave.data.undlaSize == 0){ - underlay.x = playerStrums.members[0].x -2; } } @@ -1289,10 +1257,7 @@ class PlayState extends ScriptMusicBeatState public static var introAudio:Array = []; public static var introGraphics:Array = []; public function startCountdown():Void{ - dialogue = []; - - inCutscene = false; if(!songStarted){ @@ -1306,13 +1271,11 @@ class PlayState extends ScriptMusicBeatState playerStrums.visible = cpuStrums.visible = true; FlxG.camera.zoom = FlxMath.lerp(0.90, FlxG.camera.zoom, 0.95); camHUD.zoom = FlxMath.lerp(1, camHUD.zoom, 0.95); - // camFollow.setPosition(720, 500); startedCountdown = true; Conductor.songPosition = (introAudio.length + 1) * -500; - // Conductor.changeBPM(2); if(errorMsg != "") { @@ -1381,7 +1344,6 @@ class PlayState extends ScriptMusicBeatState }catch(e){ showTempmessage('Unable to play ${sound} at $swagCounter',0xFFFF0000); } - } } } @@ -2121,11 +2083,11 @@ class PlayState extends ScriptMusicBeatState if(iconP1.isTracked){ iconP1.trackingOffset = -26; - iconP1.updateTracking(if(healthBar.fillDirection == LEFT_TO_RIGHT) health * 0.5 else 1 - (health * 0.5)); + iconP1.updateTracking((healthBar.fillDirection == LEFT_TO_RIGHT) ? health * 0.5 : 1 - (health * 0.5)); } if(iconP2.isTracked){ iconP2.trackingOffset = -(iconP2.width - 26); - iconP2.updateTracking(if(healthBar.fillDirection == LEFT_TO_RIGHT) health * 0.5 else 1 - (health * 0.5)); + iconP2.updateTracking((healthBar.fillDirection == LEFT_TO_RIGHT) ? health * 0.5 : 1 - (health * 0.5)); } // else{ @@ -2153,13 +2115,7 @@ class PlayState extends ScriptMusicBeatState }else{ if(FlxG.sound.music != null){ recalcSpeed(); - - if(FlxG.sound.music.time == lastFrameTime){ - Conductor.songPosition += elapsed * 1000 * speed; - }else{ - Conductor.songPosition = FlxG.sound.music.time; - } - lastFrameTime = FlxG.sound.music.time; + inline Conductor.updateElapsed(elapsed*speed); if(Conductor.songPosition > FlxG.sound.music.length - 100 && !endingSong && FlxG.sound.music.onComplete != null){ var complete = FlxG.sound.music.onComplete; FlxG.sound.music.onComplete = null; @@ -3403,7 +3359,7 @@ class PlayState extends ScriptMusicBeatState callInterp("noteMiss",[player,daNote,direction,calcStats]); player.callInterp('noteMiss',[daNote,direction,calcStats]); } - onlineNoteHit(if(daNote == null) -1 else daNote.noteID,direction + 1); + onlineNoteHit((daNote == null) ? -1 : daNote.noteID,direction + 1); @@ -3497,22 +3453,28 @@ class PlayState extends ScriptMusicBeatState restartTimes++; - bf.currentAnimationPriority = -10; - dad.currentAnimationPriority = -10; - gf.currentAnimationPriority = -10; - if(bf != null) bf.dance(); - if(dad != null) dad.dance(); - if(gf != null) gf.dance(); + + + + if(bf != null) { + bf.currentAnimationPriority = -10; + bf.dance(); + } + if(dad != null) { + dad.currentAnimationPriority = -10; + dad.dance(); + } + if(gf != null) { + gf.currentAnimationPriority = -10; + gf.dance(); + } health=1; Conductor.songPosition = -5000; vocals.time = FlxG.sound.music.time = 0; vocals.volume = SESave.data.voicesVol; - startingSong=true; - songStarted = false; - startedCountdown = false; - handleHealth=true; - finished=false; + songStarted = startedCountdown = finished=false; + startingSong = handleHealth = true; for (i=>v in notes.members){ if(v == null) continue; v.acceleration.y = FlxG.random.int(200, 300); diff --git a/source/SELoader.hx b/source/SELoader.hx index b0875a2..7048c8a 100644 --- a/source/SELoader.hx +++ b/source/SELoader.hx @@ -84,10 +84,10 @@ class SELoader { public static var namespace = ""; inline public static function handleError(e:String){ + e = '${id}: '+e; trace(e); throw(e); // if((cast (FlxG.state)).handleError != null) (cast (FlxG.state)).handleError(e); else MainMenuState.handleError(e); - } // Basically clenses paths and returns the base path with the requested one. Used heavily for the Android port @:keep inline public static function getPath(path:String="",allowModded:Bool = true):String{ @@ -141,14 +141,14 @@ class SELoader { var packsFolder = modsFolder.newDirectory('packs/'); if(namespace=="") namespace=SELoader.namespace; if(namespace!=""){ // We always want to check the namespace first, It has top priority - var e = (namespace == "INTERNAL" || namespace == "assets") ? getPath() : packsFolder+namespace; + var packFolder = (namespace == "INTERNAL" || namespace == "assets") ? getPath() : packsFolder+namespace; SELoader.ignoreMods = true; var the = SELoader.anyExists([ - e+'/'+path, - e+'/shared/'+path, - e+'/assets/'+path, - e+'/assets/shared/'+path, - e+'/assets/preload/'+path + packFolder+'/'+path, + packFolder+'/shared/'+path, + packFolder+'/assets/'+path, + packFolder+'/assets/shared/'+path, + packFolder+'/assets/preload/'+path ]); SELoader.ignoreMods = false; if(the!=null) return the; @@ -174,11 +174,11 @@ class SELoader { if(!exists(p)){ // I am honestly too lazy at the moment to add a proper mods menu AssetPathCache[path]=null; { - var e = getRawPath('assets/'); + var rawAssets = getRawPath('assets/'); rawMode=defaultRawMode=true; var the = SELoader.anyExists([ - e+'/'+path, - e+'/shared/'+path, + rawAssets+'/'+path, + rawAssets+'/shared/'+path, ]); rawMode=defaultRawMode=false; if(the!=null) return AssetPathCache[path]=the; @@ -186,13 +186,13 @@ class SELoader { if(!SESave.data.HDDMode){ if(SELoader.exists(modsFolder + path)) return AssetPathCache[path]=modsFolder+path; for (directory in orderList(SELoader.readDirectory(packsFolder.toString()))){ - var e = packsFolder+directory; + var packFolder = packsFolder+directory; var the = SELoader.anyExists([ - e+'/'+path, - e+'/shared/'+path, - e+'/assets/'+path, - e+'/assets/shared/'+path, - e+'/assets/preload/'+path + packFolder+'/'+path, + packFolder+'/shared/'+path, + packFolder+'/assets/'+path, + packFolder+'/assets/shared/'+path, + packFolder+'/assets/preload/'+path ]); if(the!=null) return AssetPathCache[path]=the; } @@ -208,7 +208,7 @@ class SELoader { return cache.loadText(textPath); } if(!exists(textPath)){ - handleError('${id}: Text "${textPath}" doesn\'t exist!'); + handleError(' Text "${textPath}" doesn\'t exist!'); return ""; } return File.getContent(textPath); @@ -230,7 +230,7 @@ class SELoader { public static function loadFlxSprite(x:Float = 0,y:Float = 0,pngPath:String,?useCache:Bool = false):FlxSprite{ if(!SELoader.exists('${pngPath}')){ - handleError('${id}: Image "${pngPath}" doesn\'t exist!'); + handleError(' Image "${pngPath}" doesn\'t exist!'); return new FlxSprite(x, y); // Prevents the script from throwing a null error or something } return new FlxSprite(x, y).loadGraphic(loadGraphic(pngPath,useCache)); @@ -248,7 +248,7 @@ class SELoader { return cache.loadBitmap(pngPath); } if(!exists('${pngPath}')){ - handleError('${id}: "${pngPath}" doesn\'t exist!'); + handleError(' "${pngPath}" doesn\'t exist!'); return new BitmapData(0,0,false,0xFF000000); // Prevents the script from throwing a null error or something } return BitmapData.fromFile(pngPath); @@ -258,11 +258,11 @@ class SELoader { public static function loadStichedSparrowFrames(pngPath:String,?cache:Bool=false):FlxAtlasFrames{ pngPath = getPath(pngPath); if(!exists('${pngPath}.png')){ - handleError('${id}: SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); + handleError(' SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); return new FlxAtlasFrames(FlxGraphic.fromRectangle(0,0,0)); // Prevents the script from throwing a null error or something } if(!exists('${pngPath}.xml')){ - handleError('${id}: SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); + handleError(' SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); return new FlxAtlasFrames(FlxGraphic.fromRectangle(0,0,0)); // Prevents the script from throwing a null error or something } var atlas = FlxAtlasFrames.fromSparrow(loadGraphic('$pngPath.png',cache),loadXML('${pngPath}',cache)); @@ -284,11 +284,11 @@ class SELoader { public static function loadSparrowFrames(pngPath:String,?cache:Bool=false):FlxAtlasFrames{ pngPath = getPath(pngPath); if(!exists('${pngPath}.png')){ - handleError('${id}: SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); + handleError(' SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); return new FlxAtlasFrames(FlxGraphic.fromRectangle(0,0,0)); // Prevents the script from throwing a null error or something } if(!exists('${pngPath}.xml')){ - handleError('${id}: SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); + handleError(' SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); return new FlxAtlasFrames(FlxGraphic.fromRectangle(0,0,0)); // Prevents the script from throwing a null error or something } return FlxAtlasFrames.fromSparrow(loadGraphic('$pngPath.png',cache),loadXML('${pngPath}',cache)); @@ -381,7 +381,7 @@ class SELoader { // } textPath = getPath(textPath); if(!exists(textPath)){ - handleError('${id}: Text "${textPath}" doesn\'t exist!'); + handleError(' Text "${textPath}" doesn\'t exist!'); return null; } return File.getBytes(getPath(textPath)); @@ -411,7 +411,7 @@ class SELoader { return cache.loadSound(rawPath); } if(!exists(soundPath)){ - handleError('${id}: Sound "$soundPath" > "$rawPath" doesn\'t exist!'); + handleError(' Sound "$soundPath" > "$rawPath" doesn\'t exist!'); // return null; } return Sound.fromFile(getPath(rawPath)); @@ -421,10 +421,10 @@ class SELoader { } - static public function playSound(soundPath:String,?volume:Dynamic = null,?cache:Bool = false):FlxSound{ - if(soundPath == null || soundPath == ""){ + static public function playSound(soundPath:String = "",?volume:Dynamic = null,?cache:Bool = false):FlxSound{ + if(soundPath == ""){ try{ - throw('Tried to play a "" sound'); + throw('Tried to play an empty sound!'); }catch(e){ trace('UNABLE TO PLAY SOUND: ${e.details()}'); } @@ -459,6 +459,7 @@ class SELoader { public static function fullPath(path:String):String{ return FileSystem.fullPath(getPath(path)); } + public static function anyExists(paths:Array,?returnOriginal:Bool = false,?defaultValue:String = null):String{ for(i in paths) { var path = getPath(i); @@ -478,10 +479,10 @@ class SELoader { for(i in paths) { var path = getPath(i); var folder = path.substring(0,path.lastIndexOf('/')); - var file = path.substring(path.lastIndexOf('/')+1); + var file = path.substring(path.lastIndexOf('/')+1).toLowerCase(); for(FILE in readDirectory(folder)){ - if(FILE.toLowerCase() != file.toLowerCase()) continue; + if(FILE.toLowerCase() != file) continue; return folder+"/"+FILE; } @@ -784,8 +785,11 @@ class InternalCache{ soundArray = []; openfl.system.System.gc(); } - inline function handleError(e:String){ - SELoader.handleError(e); + inline public function handleError(e:String){ + e = '${id}: '+e; + trace(e); + throw(e); + // if((cast (FlxG.state)).handleError != null) (cast (FlxG.state)).handleError(e); else MainMenuState.handleError(e); } @@ -797,7 +801,7 @@ class InternalCache{ } public function loadGraphic(pngPath:String):FlxGraphic{ if(!exists('${pngPath}')){ - handleError('${id}: "${pngPath}" doesn\'t exist!'); + handleError(' "${pngPath}" doesn\'t exist!'); return FlxGraphic.fromRectangle(0,0,0); // Prevents the script from throwing a null error or something } if(spriteArray[pngPath] == null) cacheGraphic(pngPath); @@ -805,7 +809,7 @@ class InternalCache{ } public function loadBitmap(pngPath:String):BitmapData{ if(!exists('${pngPath}')){ - handleError('${id}: "${pngPath}" doesn\'t exist!'); + handleError(' "${pngPath}" doesn\'t exist!'); return new BitmapData(0,0,false,0xFF000000); // Prevents the script from throwing a null error or something } if(bitmapArray[pngPath] == null) cacheBitmap(pngPath); @@ -814,14 +818,14 @@ class InternalCache{ public function loadSparrowFrames(pngPath:String):FlxAtlasFrames{ // if(!exists('${pngPath}.png')){ - // handleError('${id}: SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); + // handleError(' SparrowFrame PNG "${pngPath}.png" doesn\'t exist!'); // return FlxAtlasFrames.fromSparrow(FlxGraphic.fromRectangle(1,1,0),""); // Prevents the script from throwing a null error or something // } var _txt = ""; if(exists('${pngPath}.xml')){ _txt = loadText(pngPath + ".xml"); }else{ - handleError('${id}: SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); + handleError(' SparrowFrame XML "${pngPath}.xml" doesn\'t exist!'); // return FlxAtlasFrames.fromSparrow(FlxGraphic.fromRectangle(1,1,0),""); // Prevents the script from throwing a null error or something } diff --git a/source/TitleState.hx b/source/TitleState.hx index 5a35850..de7ac68 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -1266,22 +1266,18 @@ class TitleState extends MusicBeatState // destHaxe(); case 1: - addMoreText(FlxG.random.float() < 0.1 ? 'Friday Night Fucking\' by' :'Friday Night Funkin\' by'); - credTextShit.y -= 600; + addMoreText(FlxG.random.float() < 0.1 ? "ef en ef' by" : FlxG.random.float() < 0.1 ? 'Friday Night Fucking\' by' :'Friday Night Funkin\' by',0); // addMoreText('ninjamuffin99').startTyping(0.015,Conductor.crochetSecs); // addMoreText('phantomArcade').startTyping(0.015,Conductor.crochetSecs); // addMoreText('kawaisprite').startTyping(0.02,Conductor.crochetSecs); // addMoreText('evilsk8er').startTyping(0.022,Conductor.crochetSecs); case 2: - addMoreText('ninjamuffin99'); - addMoreText('phantomArcade'); - addMoreText('kawaisprite'); - addMoreText('evilsk8er'); - credTextShit.x -= 130; - + addMoreText('ninjamuffin99',50); + addMoreText('phantomArcade',50); + addMoreText('kawaisprite',50); + addMoreText('evilsk8er',50); case 7: - credTextShit.y += 200; deleteCoolText(); case 10: // if (Main.watermarks) You're not more important than fucking newgrounds diff --git a/source/onlinemod/OnlinePauseSubState.hx b/source/onlinemod/OnlinePauseSubState.hx index 4c12c62..271155d 100644 --- a/source/onlinemod/OnlinePauseSubState.hx +++ b/source/onlinemod/OnlinePauseSubState.hx @@ -45,7 +45,7 @@ class OnlinePauseSubState extends MusicBeatSubstate var levelDifficulty:FlxText = new FlxText(20, 15 + 32, 0, "", 32); levelDifficulty.text += CoolUtil.difficultyString(); levelDifficulty.scrollFactor.set(); - levelDifficulty.setFormat(Paths.font('vcr.ttf'), 32); + levelDifficulty.setFormat(CoolUtil.font, 32); levelDifficulty.updateHitbox(); add(levelDifficulty); diff --git a/version.downloadMe b/version.downloadMe index 6745914..ec010dc 100644 --- a/version.downloadMe +++ b/version.downloadMe @@ -1,4 +1,4 @@ -25.01.08.2200; +25.01.10.1455; * Better Psych character support(Still kinda experimental but should be more stable) * Fix some small errors * Fix characters not loading due to using ID instead of folderName