Preload all the graphics of a note style before the song starts, greatly reduces stutters early in the song.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -138,7 +138,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
return noteFrames;
|
||||
}
|
||||
|
||||
function getNoteAssetPath(raw:Bool = false):Null<String>
|
||||
public function getNoteAssetPath(raw:Bool = false):Null<String>
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
@@ -241,7 +241,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
target.antialiasing = !(_data.assets.noteStrumline?.isPixel ?? false);
|
||||
}
|
||||
|
||||
function getStrumlineAssetPath(raw:Bool = false):Null<String>
|
||||
public function getStrumlineAssetPath(raw:Bool = false):Null<String>
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
@@ -384,7 +384,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
return result;
|
||||
}
|
||||
|
||||
function buildCountdownSpritePath(step:Countdown.CountdownStep):Null<String>
|
||||
public function buildCountdownSpritePath(step:Countdown.CountdownStep):Null<String>
|
||||
{
|
||||
var basePath:Null<String> = null;
|
||||
switch (step)
|
||||
@@ -587,9 +587,10 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
}
|
||||
}
|
||||
|
||||
function buildJudgementSpritePath(rating:String):Null<String>
|
||||
public function buildJudgementSpritePath(rating:String):Null<String>
|
||||
{
|
||||
var basePath:Null<String> = null;
|
||||
|
||||
switch (rating)
|
||||
{
|
||||
case "sick":
|
||||
@@ -603,13 +604,11 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
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<NoteStyleData>
|
||||
}
|
||||
}
|
||||
|
||||
function buildComboNumSpritePath(digit:Int):Null<String>
|
||||
public function buildComboNumSpritePath(digit:Int):Null<String>
|
||||
{
|
||||
var basePath:Null<String> = null;
|
||||
switch (digit)
|
||||
@@ -918,7 +917,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
return splashFrames;
|
||||
}
|
||||
|
||||
function getSplashAssetPath(raw:Bool = false):Null<String>
|
||||
public function getSplashAssetPath(raw:Bool = false):Null<String>
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
@@ -1130,7 +1129,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
|
||||
return parts[1];
|
||||
}
|
||||
|
||||
function getHoldCoverDirectionAssetPath(direction:NoteDirection, raw:Bool = false):Null<String>
|
||||
public function getHoldCoverDirectionAssetPath(direction:NoteDirection, raw:Bool = false):Null<String>
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user