From a6daf3b0d6a7d763bc1e12a8092d76da85d1b19c Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Tue, 25 Jul 2023 23:11:12 -0400 Subject: [PATCH] Resolved lag issues caused by creating too many notes in the pool. --- .../debug/charting/ChartEditorEventSprite.hx | 4 +-- .../charting/ChartEditorHoldNoteSprite.hx | 14 ++++++++++ .../ui/debug/charting/ChartEditorState.hx | 26 +++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/source/funkin/ui/debug/charting/ChartEditorEventSprite.hx b/source/funkin/ui/debug/charting/ChartEditorEventSprite.hx index 0abee3715..bc68709c5 100644 --- a/source/funkin/ui/debug/charting/ChartEditorEventSprite.hx +++ b/source/funkin/ui/debug/charting/ChartEditorEventSprite.hx @@ -146,7 +146,7 @@ class ChartEditorEventSprite extends FlxSprite /** * Return whether this event is currently visible. */ - public function isNoteVisible(viewAreaBottom:Float, viewAreaTop:Float):Bool + public function isEventVisible(viewAreaBottom:Float, viewAreaTop:Float):Bool { // True if the note is above the view area. var aboveViewArea = (this.y + this.height < viewAreaTop); @@ -160,7 +160,7 @@ class ChartEditorEventSprite extends FlxSprite /** * Return whether an event, if placed in the scene, would be visible. */ - public static function wouldNoteBeVisible(viewAreaBottom:Float, viewAreaTop:Float, eventData:SongEventData, ?origin:FlxObject):Bool + public static function wouldEventBeVisible(viewAreaBottom:Float, viewAreaTop:Float, eventData:SongEventData, ?origin:FlxObject):Bool { var noteHeight:Float = ChartEditorState.GRID_SIZE; var notePosY:Float = eventData.stepTime * ChartEditorState.GRID_SIZE; diff --git a/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx b/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx index 38cdaffeb..5805874f6 100644 --- a/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx +++ b/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx @@ -52,6 +52,7 @@ class ChartEditorHoldNoteSprite extends SustainTrail strumTime = 999999999; missedNote = false; hitNote = false; + active = true; visible = true; alpha = 1.0; width = graphic.width / 8 * zoom; // amount of notes * 2 @@ -64,6 +65,19 @@ class ChartEditorHoldNoteSprite extends SustainTrail setup(); } + public override function kill():Void + { + super.kill(); + + active = false; + visible = false; + noteData = null; + strumTime = 999999999; + noteDirection = 0; + sustainLength = 0; + fullSustainLength = 0; + } + /** * Return whether this note is currently visible. */ diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index cda2b09df..2238fff3f 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -2329,8 +2329,11 @@ class ChartEditorState extends HaxeUIState if (!ChartEditorHoldNoteSprite.wouldHoldNoteBeVisible(viewAreaBottomPixels, viewAreaTopPixels, noteData, renderedHoldNotes)) continue; // Hold note should be rendered. - var holdNoteSprite:ChartEditorHoldNoteSprite = renderedHoldNotes.recycle(() -> new ChartEditorHoldNoteSprite(this)); - trace('Creating new HoldNote... (${renderedHoldNotes.members.length})'); + var holdNoteFactory = function() { + // TODO: Print some kind of warning if `renderedHoldNotes.members` is too high? + return new ChartEditorHoldNoteSprite(this); + } + var holdNoteSprite:ChartEditorHoldNoteSprite = renderedHoldNotes.recycle(holdNoteFactory); var noteLengthPixels:Float = noteData.stepLength * GRID_SIZE; @@ -2388,6 +2391,12 @@ class ChartEditorState extends HaxeUIState // Sort the events DESCENDING. This keeps the sustain behind the associated note. renderedEvents.sort(FlxSort.byY, FlxSort.DESCENDING); } + + // Add a debug value which displays the current size of the note pool. + // The pool will grow as more notes need to be rendered at once. + // If this gets too big, something needs to be optimized somewhere! -Eric + FlxG.watch.addQuick("tapNotesRendered", renderedNotes.members.length); + FlxG.watch.addQuick("holdNotesRendered", renderedHoldNotes.members.length); } function buildSelectionSquare():FlxSprite @@ -3095,6 +3104,17 @@ class ChartEditorState extends HaxeUIState #end } + /** + * Clear the voices group. + */ + public function clearVocals():Void + { + audioVocalTrackGroup.clear(); + } + + /** + * Load a vocal track for a given song and character and add it to the voices group. + */ public function loadVocalsFromAsset(path:String, charKey:String = null):Bool { var vocalTrack:FlxSound = FlxG.sound.load(path, 1.0, false); @@ -3156,6 +3176,8 @@ class ChartEditorState extends HaxeUIState sortChartData(); + clearVocals(); + loadInstrumentalFromAsset(Paths.inst(songId)); var voiceList:Array = song.getDifficulty(selectedDifficulty).buildVoiceList();