From 24d1116debefc066acea9ca55cc78e34a8a6190b Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 12 Jun 2025 18:30:04 -0400 Subject: [PATCH] Preload all the graphics of a note style before the song starts, greatly reduces stutters early in the song. --- source/funkin/FunkinMemory.hx | 43 +++++++++++++++++++ .../funkin/play/notes/notestyle/NoteStyle.hx | 19 ++++---- source/funkin/ui/transition/LoadingState.hx | 11 +++++ 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/source/funkin/FunkinMemory.hx b/source/funkin/FunkinMemory.hx index f5eacef56..025a872b1 100644 --- a/source/funkin/FunkinMemory.hx +++ b/source/funkin/FunkinMemory.hx @@ -2,6 +2,7 @@ package funkin; import flixel.graphics.FlxGraphic; import flixel.FlxG; +import funkin.play.notes.notestyle.NoteStyle; import openfl.utils.AssetType; import openfl.Assets; import openfl.system.System; @@ -240,6 +241,48 @@ class FunkinMemory } } + ///// NOTE STYLE ////// + + public static function cacheNoteStyle(style:NoteStyle):Void + { + // TODO: Texture paths should fall back to the default values. + cacheTexture(Paths.image(style.getNoteAssetPath() ?? "note")); + cacheTexture(Paths.image(style.getHoldNoteAssetPath() ?? "noteHold")); + cacheTexture(Paths.image(style.getStrumlineAssetPath() ?? "strumline")); + cacheTexture(Paths.image(style.getSplashAssetPath() ?? "noteSplash")); + + cacheTexture(Paths.image(style.getHoldCoverDirectionAssetPath(LEFT) ?? "LEFT")); + cacheTexture(Paths.image(style.getHoldCoverDirectionAssetPath(RIGHT) ?? "RIGHT")); + cacheTexture(Paths.image(style.getHoldCoverDirectionAssetPath(UP) ?? "UP")); + cacheTexture(Paths.image(style.getHoldCoverDirectionAssetPath(DOWN) ?? "DOWN")); + + cacheTexture(Paths.image(style.buildCountdownSpritePath(THREE) ?? "THREE")); + cacheTexture(Paths.image(style.buildCountdownSpritePath(TWO) ?? "TWO")); + cacheTexture(Paths.image(style.buildCountdownSpritePath(ONE) ?? "ONE")); + cacheTexture(Paths.image(style.buildCountdownSpritePath(GO) ?? "GO")); + + cacheSound(style.getCountdownSoundPath(THREE) ?? "THREE"); + cacheSound(style.getCountdownSoundPath(TWO) ?? "TWO"); + cacheSound(style.getCountdownSoundPath(ONE) ?? "ONE"); + cacheSound(style.getCountdownSoundPath(GO) ?? "GO"); + + cacheTexture(Paths.image(style.buildJudgementSpritePath("sick") ?? 'sick')); + cacheTexture(Paths.image(style.buildJudgementSpritePath("good") ?? 'good')); + cacheTexture(Paths.image(style.buildJudgementSpritePath("bad") ?? 'bad')); + cacheTexture(Paths.image(style.buildJudgementSpritePath("shit") ?? 'shit')); + + cacheTexture(Paths.image(style.buildComboNumSpritePath(0) ?? '0')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(1) ?? '1')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(2) ?? '2')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(3) ?? '3')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(4) ?? '4')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(5) ?? '5')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(6) ?? '6')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(7) ?? '7')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(8) ?? '8')); + cacheTexture(Paths.image(style.buildComboNumSpritePath(9) ?? '9')); + } + ///// SOUND ////// public static function cacheSound(key:String):Void diff --git a/source/funkin/play/notes/notestyle/NoteStyle.hx b/source/funkin/play/notes/notestyle/NoteStyle.hx index bce2bcd45..6ecc59fad 100644 --- a/source/funkin/play/notes/notestyle/NoteStyle.hx +++ b/source/funkin/play/notes/notestyle/NoteStyle.hx @@ -138,7 +138,7 @@ class NoteStyle implements IRegistryEntry return noteFrames; } - function getNoteAssetPath(raw:Bool = false):Null + public function getNoteAssetPath(raw:Bool = false):Null { if (raw) { @@ -241,7 +241,7 @@ class NoteStyle implements IRegistryEntry target.antialiasing = !(_data.assets.noteStrumline?.isPixel ?? false); } - function getStrumlineAssetPath(raw:Bool = false):Null + public function getStrumlineAssetPath(raw:Bool = false):Null { if (raw) { @@ -384,7 +384,7 @@ class NoteStyle implements IRegistryEntry return result; } - function buildCountdownSpritePath(step:Countdown.CountdownStep):Null + public function buildCountdownSpritePath(step:Countdown.CountdownStep):Null { var basePath:Null = null; switch (step) @@ -587,9 +587,10 @@ class NoteStyle implements IRegistryEntry } } - function buildJudgementSpritePath(rating:String):Null + public function buildJudgementSpritePath(rating:String):Null { var basePath:Null = null; + switch (rating) { case "sick": @@ -603,13 +604,11 @@ class NoteStyle implements IRegistryEntry default: basePath = null; } - if (basePath == null) return fallback?.buildJudgementSpritePath(rating); - var parts = basePath?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length < 1) return null; if (parts.length == 1) return parts[0]; - return parts[1]; } @@ -776,7 +775,7 @@ class NoteStyle implements IRegistryEntry } } - function buildComboNumSpritePath(digit:Int):Null + public function buildComboNumSpritePath(digit:Int):Null { var basePath:Null = null; switch (digit) @@ -918,7 +917,7 @@ class NoteStyle implements IRegistryEntry return splashFrames; } - function getSplashAssetPath(raw:Bool = false):Null + public function getSplashAssetPath(raw:Bool = false):Null { if (raw) { @@ -1130,7 +1129,7 @@ class NoteStyle implements IRegistryEntry return parts[1]; } - function getHoldCoverDirectionAssetPath(direction:NoteDirection, raw:Bool = false):Null + public function getHoldCoverDirectionAssetPath(direction:NoteDirection, raw:Bool = false):Null { if (raw) { diff --git a/source/funkin/ui/transition/LoadingState.hx b/source/funkin/ui/transition/LoadingState.hx index c3fc3877d..fd8579a42 100644 --- a/source/funkin/ui/transition/LoadingState.hx +++ b/source/funkin/ui/transition/LoadingState.hx @@ -1,5 +1,6 @@ package funkin.ui.transition; +import funkin.data.notestyle.NoteStyleRegistry; import flixel.FlxSprite; import flixel.math.FlxMath; import flixel.tweens.FlxEase; @@ -266,6 +267,16 @@ class LoadingState extends MusicBeatSubState if (shouldPreloadLevelAssets) { preloadLevelAssets(); + + // Cache the note style. + var songDifficulty = params.targetSong.getDifficulty(params.targetDifficulty, params.targetVariation); + if (songDifficulty != null) + { + var noteStyle = NoteStyleRegistry.instance.fetchEntry(songDifficulty.noteStyle); + FunkinMemory.cacheNoteStyle(noteStyle); + } + + // TODO: This sucks lol. if (params.targetSong.songName == "2hot") { var spritesToCache = [