From 673e4315f28864239b4c235580c6f5a3c8e7cd35 Mon Sep 17 00:00:00 2001 From: JordanSantiagoYT Date: Fri, 27 Dec 2024 20:13:39 -0500 Subject: [PATCH] i tried optimizing something im trying to figure out how to improve the performance of note spawning, hitting and stuff --- source/Character.hx | 27 +++++--------- source/Note.hx | 53 ++++++++++++---------------- source/PlayState.hx | 86 ++++++++++++++++++--------------------------- 3 files changed, 65 insertions(+), 101 deletions(-) diff --git a/source/Character.hx b/source/Character.hx index 836b3aa2b0f..a4f9ed79c5c 100644 --- a/source/Character.hx +++ b/source/Character.hx @@ -291,6 +291,7 @@ class Character extends FlxSprite } } + var anim:String; override function update(elapsed:Float) { if (ClientPrefs.ffmpegMode) elapsed = 1 / ClientPrefs.targetFPS; @@ -307,7 +308,7 @@ class Character extends FlxSprite heyTimer -= elapsed * PlayState.instance.playbackRate; if(heyTimer <= 0) { - var anim:String = getAnimationName(); + anim = getAnimationName(); if(specialAnim && (anim == 'hey' || anim == 'cheer')) { specialAnim = false; @@ -364,9 +365,9 @@ class Character extends FlxSprite } } - var name:String = getAnimationName(); - if(isAnimationFinished() && animOffsets.exists('$name-loop')) - playAnim('$name-loop'); + anim = getAnimationName(); + if(isAnimationFinished() && animOffsets.exists('$anim-loop')) + playAnim('$anim-loop'); super.update(elapsed); } @@ -442,6 +443,7 @@ class Character extends FlxSprite } } + var daOffset = null; public function playAnim(AnimName:String, Force:Bool = false, Reversed:Bool = false, Frame:Int = 0):Void { specialAnim = false; @@ -454,12 +456,11 @@ class Character extends FlxSprite atlas.anim.play(AnimName, Force, Reversed, Frame); atlas.update(0); } - _lastPlayedAnimation = AnimName; - final daOffset = animOffsets.get(AnimName); - if (animOffsets.exists(AnimName)) + if (hasAnimation(AnimName)) { + daOffset = animOffsets.get(AnimName); offset.set(daOffset[0], daOffset[1]); } else @@ -468,18 +469,12 @@ class Character extends FlxSprite if (curCharacter.startsWith('gf')) { if (AnimName == 'singLEFT') - { danced = true; - } else if (AnimName == 'singRIGHT') - { danced = false; - } if (AnimName == 'singUP' || AnimName == 'singDOWN') - { danced = !danced; - } } } @@ -601,21 +596,15 @@ class Boyfriend extends Character if (!debugMode && animation.curAnim != null) { if (animation.curAnim.name.startsWith('sing')) - { holdTimer += elapsed; - } else holdTimer = 0; if (animation.curAnim.name.endsWith('miss') && isAnimationFinished() && !debugMode) - { playAnim('idle', true, false, 10); - } if (animation.curAnim.name == 'firstDeath' && isAnimationFinished() && startedDeath) - { playAnim('deathLoop'); - } } super.update(elapsed); diff --git a/source/Note.hx b/source/Note.hx index 0ec068a363a..6e7ffb2cb14 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -167,18 +167,14 @@ class Note extends FlxSprite var changeSize:Bool = false; private function set_texture(value:String):String { + if (value.length == 0) value = Paths.defaultSkin; if (!pixelNote && texture != value) { changeSize = false; if (!Paths.noteSkinFramesMap.exists(value)) Paths.initNote(4, value); - try { - if (frames != @:privateAccess Paths.noteSkinFramesMap.get(value)) frames = @:privateAccess Paths.noteSkinFramesMap.get(value); - if (animation != @:privateAccess Paths.noteSkinAnimsMap.get(value)) inline animation.copyFrom(@:privateAccess Paths.noteSkinAnimsMap.get(value)); - } - catch (e) { - frames = @:privateAccess Paths.noteSkinFramesMap.get(Paths.defaultSkin); - animation.copyFrom(@:privateAccess Paths.noteSkinAnimsMap.get(Paths.defaultSkin)); - } + if (frames != @:privateAccess Paths.noteSkinFramesMap.get(value)) frames = @:privateAccess Paths.noteSkinFramesMap.get(value); + if (animation != @:privateAccess Paths.noteSkinAnimsMap.get(value)) animation.copyFrom(@:privateAccess Paths.noteSkinAnimsMap.get(value)); + if (!changeSize) { changeSize = true; @@ -195,15 +191,11 @@ class Note extends FlxSprite public function defaultRGB() { - var arr:Array = ClientPrefs.arrowRGB[noteData]; - if(pixelNote) arr = ClientPrefs.arrowRGBPixel[noteData]; + noteColor = inline initializeGlobalRGBShader(noteData); - if (noteData > -1 && noteData <= arr.length) - { - rgbShader.r = arr[0]; - rgbShader.g = arr[1]; - rgbShader.b = arr[2]; - } + rgbShader.r = noteColor.r; + rgbShader.g = noteColor.g; + rgbShader.b = noteColor.b; } private function set_noteType(value:String):String { @@ -229,11 +221,9 @@ class Note extends FlxSprite y -= 2000; antialiasing = ClientPrefs.globalAntialiasing && !pixelNote; - if(noteData > -1) { - if (ClientPrefs.showNotes) - { - texture = Paths.defaultSkin; - } + if(inEditor) { + if (ClientPrefs.showNotes) texture = Paths.defaultSkin; + if (ClientPrefs.enableColorShader) { try{ rgbShader = new RGBShaderReference(this, initializeGlobalRGBShader(noteData, this)); } @@ -521,13 +511,16 @@ class Note extends FlxSprite _lastValidChecked = ''; } + var noteColor:RGBPalette; + var superCoolColor = null; + var arr:Array = [255, 255, 255]; public function updateRGBColors() { if (rgbShader == null && useRGBShader) rgbShader = new RGBShaderReference(this, initializeGlobalRGBShader(noteData, this)); else switch(ClientPrefs.noteColorStyle) { case 'Rainbow': - var superCoolColor = new FlxColor(0xFFFF0000); + superCoolColor = new FlxColor(0xFFFF0000); superCoolColor.hue = (strumTime / 5000 * 360) % 360; rgbShader.r = superCoolColor; rgbShader.g = FlxColor.WHITE; @@ -539,7 +532,7 @@ class Note extends FlxSprite case 'Char-Based': if (PlayState.instance != null) { - var arr:Array = CoolUtil.getHealthColors(doOppStuff ? PlayState.instance.dad : PlayState.instance.boyfriend); + arr = CoolUtil.getHealthColors(doOppStuff ? PlayState.instance.dad : PlayState.instance.boyfriend); if (gfNote) arr = CoolUtil.getHealthColors(PlayState.instance.gf); if (noteData > -1) { @@ -552,7 +545,7 @@ class Note extends FlxSprite else defaultRGB(); default: - + } if (noteType == 'Hurt Note' && rgbShader != null) { @@ -591,7 +584,7 @@ class Note extends FlxSprite texture = chartNoteData.texture; shouldCenterOffsets = false; } - if ((chartNoteData.noteskin.length < 1 && chartNoteData.texture.length < 1) && chartNoteData.texture != Paths.defaultSkin) + if ((chartNoteData.noteskin.length < 1 && chartNoteData.texture.length < 1) && texture != Paths.defaultSkin) { texture = Paths.defaultSkin; useRGBShader = ClientPrefs.enableColorShader; @@ -627,7 +620,7 @@ class Note extends FlxSprite if (ClientPrefs.enableColorShader && useRGBShader) { if (rgbShader == null) rgbShader = new RGBShaderReference(this, initializeGlobalRGBShader(noteData, this)); - else updateRGBColors(); + updateRGBColors(); } if (noteType == 'Hurt Note' && !ClientPrefs.enableColorShader) @@ -646,7 +639,7 @@ class Note extends FlxSprite } } - if (!PlayState.isPixelStage && !changeSize) + if (!changeSize && !PlayState.isPixelStage) { changeSize = true; setGraphicSize(Std.int(width * 0.7)); @@ -663,7 +656,7 @@ class Note extends FlxSprite else { animation.play(colArray[noteData % 4] + 'Scroll'); if (!copyAngle) copyAngle = true; - offsetX = 0; //Juuuust in case we recycle a sustain note to a regular note + offsetX = 0; //Just in case we recycle a sustain note to a regular note if (useRGBShader && shouldCenterOffsets) { centerOffsets(); @@ -676,12 +669,12 @@ class Note extends FlxSprite if (!mustPress) { visible = ClientPrefs.opponentStrums; - alpha = ClientPrefs.middleScroll ? ClientPrefs.oppNoteAlpha : 1; + alpha = multAlpha = ClientPrefs.middleScroll ? ClientPrefs.oppNoteAlpha : 1; } else { if (!visible) visible = true; - if (alpha != 1) alpha = 1; + for (i in [alpha, multAlpha]) if (i != 1) i = 1; } if (flipY) flipY = false; } diff --git a/source/PlayState.hx b/source/PlayState.hx index 33b31ace455..41c94ba4d87 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1610,9 +1610,8 @@ class PlayState extends MusicBeatState Paths.music(Paths.formatToSongPath(ClientPrefs.pauseMusic)); if(cpuControlled && ClientPrefs.randomBotplayText && ClientPrefs.botTxtStyle != 'Hide' && botplayTxt != null && ffmpegInfo != 'Frame Time') - { botplayTxt.text = theListBotplay[FlxG.random.int(0, theListBotplay.length - 1)]; - } + if (botplayTxt != null) ogBotTxt = botplayTxt.text; resetRPC(); @@ -2149,29 +2148,32 @@ class PlayState extends MusicBeatState }); } + var fps:Float = 60; + var bfCanPan:Bool = false; + var dadCanPan:Bool = false; + var clear:Bool = false; function camPanRoutine(anim:String = 'singUP', who:String = 'bf'):Void { if (SONG.notes[curSection] != null) { - var fps:Float = FlxG.updateFramerate; - final bfCanPan:Bool = SONG.notes[curSection].mustHitSection; - final dadCanPan:Bool = !SONG.notes[curSection].mustHitSection; - var clear:Bool = false; - switch (who) { - case 'bf' | 'boyfriend': clear = bfCanPan; - case 'oppt' | 'dad': clear = dadCanPan; - } - //FlxG.elapsed is stinky poo poo for this, it just makes it look jank as fuck - if (clear) { - if (fps == 0) fps = 1; - switch (anim.split('-')[0]) - { - case 'singUP': moveCamTo[1] = -40*ClientPrefs.panIntensity*240*playbackRate/fps; - case 'singDOWN': moveCamTo[1] = 40*ClientPrefs.panIntensity*240*playbackRate/fps; - case 'singLEFT': moveCamTo[0] = -40*ClientPrefs.panIntensity*240*playbackRate/fps; - case 'singRIGHT': moveCamTo[0] = 40*ClientPrefs.panIntensity*240*playbackRate/fps; + fps = FlxG.updateFramerate; + bfCanPan = SONG.notes[curSection].mustHitSection; + dadCanPan = !SONG.notes[curSection].mustHitSection; + switch (who) { + case 'bf' | 'boyfriend': clear = bfCanPan; + case 'oppt' | 'dad': clear = dadCanPan; + } + //FlxG.elapsed is stinky poo poo for this, it just makes it look jank as fuck + if (clear) { + if (fps == 0) fps = 1; + switch (anim.split('-')[0]) + { + case 'singUP': moveCamTo[1] = -40*ClientPrefs.panIntensity*240*playbackRate/fps; + case 'singDOWN': moveCamTo[1] = 40*ClientPrefs.panIntensity*240*playbackRate/fps; + case 'singLEFT': moveCamTo[0] = -40*ClientPrefs.panIntensity*240*playbackRate/fps; + case 'singRIGHT': moveCamTo[0] = 40*ClientPrefs.panIntensity*240*playbackRate/fps; + } } } - } } var startTimer:FlxTimer; @@ -3835,6 +3837,7 @@ class PlayState extends MusicBeatState spawnedNote = (unspawnNotes[notesAddedCount].isSustainNote ? sustainNotes : notes).recycle(Note); spawnedNote.setupNoteData(unspawnNotes[notesAddedCount]); } + if (!ClientPrefs.noSpawnFunc) callOnLuas('onSpawnNote', [(!unspawnNotes[notesAddedCount].isSustainNote ? notes.members.indexOf(notes.members[0]) : sustainNotes.members.indexOf(sustainNotes.members[0])), unspawnNotes[notesAddedCount].noteData, unspawnNotes[notesAddedCount].noteType, unspawnNotes[notesAddedCount].isSustainNote]); notesAddedCount++; } @@ -4027,18 +4030,20 @@ class PlayState extends MusicBeatState iconP2.updateHitbox(); } + var percent:Float = 0; + var center:Float = 0; public dynamic function updateIconsPosition() { if (ClientPrefs.smoothHealth) { - final percent:Float = 1 - (ClientPrefs.smoothHPBug ? (displayedHealth / maxHealth) : (FlxMath.bound(displayedHealth, 0, maxHealth) / maxHealth)); + percent = 1 - (ClientPrefs.smoothHPBug ? (displayedHealth / maxHealth) : (FlxMath.bound(displayedHealth, 0, maxHealth) / maxHealth)); iconP1.x = 0 + healthBar.x + (healthBar.width * percent) + (150 * iconP1.scale.x - 150) / 2 - iconOffset; iconP2.x = 0 + healthBar.x + (healthBar.width * percent) - (150 * iconP2.scale.x) / 2 - iconOffset * 2; } else //mb forgot to include this { - final center:Float = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)); + center = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)); iconP1.x = center + (150 * iconP1.scale.x - 150) / 2 - iconOffset; iconP2.x = center - (150 * iconP2.scale.x) / 2 - iconOffset * 2; } @@ -5033,6 +5038,8 @@ class PlayState extends MusicBeatState if (noteDiff > ClientPrefs.goodWindow && ClientPrefs.shitGivesMiss && ClientPrefs.ratingIntensity == 'Harsh') noteMiss(note); if (noteDiff > ClientPrefs.sickWindow && ClientPrefs.shitGivesMiss && ClientPrefs.ratingIntensity == 'Very Harsh')noteMiss(note); } + + var separatedScore:Array = []; private function popUpScore(note:Note = null, ?miss:Bool = false):Void { popUpsFrame += 1; @@ -5090,7 +5097,7 @@ class PlayState extends MusicBeatState var tempCombo:Float = (combo > 0 ? combo : -combo); var tempComboAlt:Float = tempCombo; - final separatedScore:Array = []; + separatedScore = []; while(tempCombo >= 10) { separatedScore.unshift(Math.ffloor(tempCombo / 10) % 10); @@ -5562,36 +5569,11 @@ class PlayState extends MusicBeatState { //first, process whether or not the note should be hit. this prevents pointless strum following if (!daNote.mustPress && !daNote.hitByOpponent && !daNote.ignoreNote && daNote.strumTime <= Conductor.songPosition) - { - if (!ClientPrefs.showcaseMode || ClientPrefs.charsAndBG) opponentNoteHit(daNote); - if (ClientPrefs.showcaseMode && !ClientPrefs.charsAndBG) - { - if (!daNote.isSustainNote) { - enemyHits += 1 * polyphony; - if (ClientPrefs.showNPS) { - oppNotesHitArray.push(1 * polyphony); - oppNotesHitDateArray.push(Conductor.songPosition); - } - } - invalidateNote(daNote); - } - } + opponentNoteHit(daNote); if(daNote.mustPress) { - if((cpuControlled || usingBotEnergy && strumsHeld[daNote.noteData]) && daNote.strumTime <= Conductor.songPosition && !daNote.ignoreNote) { - if (!ClientPrefs.showcaseMode || ClientPrefs.charsAndBG) goodNoteHit(daNote); - if (ClientPrefs.showcaseMode && !ClientPrefs.charsAndBG) - { - if (!daNote.isSustainNote) { - totalNotesPlayed += 1 * polyphony; - if (ClientPrefs.showNPS) { - notesHitArray.push(1 * polyphony); - notesHitDateArray.push(Conductor.songPosition); - } - } - invalidateNote(daNote); - } - } + if((cpuControlled || usingBotEnergy && strumsHeld[daNote.noteData]) && daNote.strumTime <= Conductor.songPosition && !daNote.ignoreNote) + goodNoteHit(daNote); } if (!daNote.exists) return; @@ -5860,7 +5842,7 @@ class PlayState extends MusicBeatState if (daNote.animSuffix.length > 0 && oppChar.hasAnimation(animToPlay + daNote.animSuffix)) animToPlay = singAnimations[Std.int(Math.abs(daNote.noteData))] + daNote.animSuffix; - if (ClientPrefs.cameraPanning) inline camPanRoutine(animToPlay, (!opponentChart ? 'dad' : 'bf')); + if (ClientPrefs.cameraPanning) camPanRoutine(animToPlay, (!opponentChart ? 'dad' : 'bf')); if (oppChar != null) {