Resolved lag issues caused by creating too many notes in the pool.

This commit is contained in:
EliteMasterEric 2023-07-25 23:11:12 -04:00
parent 3c218ec01c
commit a6daf3b0d6
3 changed files with 40 additions and 4 deletions

View file

@ -146,7 +146,7 @@ class ChartEditorEventSprite extends FlxSprite
/** /**
* Return whether this event is currently visible. * 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. // True if the note is above the view area.
var aboveViewArea = (this.y + this.height < viewAreaTop); 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. * 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 noteHeight:Float = ChartEditorState.GRID_SIZE;
var notePosY:Float = eventData.stepTime * ChartEditorState.GRID_SIZE; var notePosY:Float = eventData.stepTime * ChartEditorState.GRID_SIZE;

View file

@ -52,6 +52,7 @@ class ChartEditorHoldNoteSprite extends SustainTrail
strumTime = 999999999; strumTime = 999999999;
missedNote = false; missedNote = false;
hitNote = false; hitNote = false;
active = true;
visible = true; visible = true;
alpha = 1.0; alpha = 1.0;
width = graphic.width / 8 * zoom; // amount of notes * 2 width = graphic.width / 8 * zoom; // amount of notes * 2
@ -64,6 +65,19 @@ class ChartEditorHoldNoteSprite extends SustainTrail
setup(); 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. * Return whether this note is currently visible.
*/ */

View file

@ -2329,8 +2329,11 @@ class ChartEditorState extends HaxeUIState
if (!ChartEditorHoldNoteSprite.wouldHoldNoteBeVisible(viewAreaBottomPixels, viewAreaTopPixels, noteData, renderedHoldNotes)) continue; if (!ChartEditorHoldNoteSprite.wouldHoldNoteBeVisible(viewAreaBottomPixels, viewAreaTopPixels, noteData, renderedHoldNotes)) continue;
// Hold note should be rendered. // Hold note should be rendered.
var holdNoteSprite:ChartEditorHoldNoteSprite = renderedHoldNotes.recycle(() -> new ChartEditorHoldNoteSprite(this)); var holdNoteFactory = function() {
trace('Creating new HoldNote... (${renderedHoldNotes.members.length})'); // 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; 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. // Sort the events DESCENDING. This keeps the sustain behind the associated note.
renderedEvents.sort(FlxSort.byY, FlxSort.DESCENDING); 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 function buildSelectionSquare():FlxSprite
@ -3095,6 +3104,17 @@ class ChartEditorState extends HaxeUIState
#end #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 public function loadVocalsFromAsset(path:String, charKey:String = null):Bool
{ {
var vocalTrack:FlxSound = FlxG.sound.load(path, 1.0, false); var vocalTrack:FlxSound = FlxG.sound.load(path, 1.0, false);
@ -3156,6 +3176,8 @@ class ChartEditorState extends HaxeUIState
sortChartData(); sortChartData();
clearVocals();
loadInstrumentalFromAsset(Paths.inst(songId)); loadInstrumentalFromAsset(Paths.inst(songId));
var voiceList:Array<String> = song.getDifficulty(selectedDifficulty).buildVoiceList(); var voiceList:Array<String> = song.getDifficulty(selectedDifficulty).buildVoiceList();