diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index e1c71e21..70597696 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -175,8 +175,10 @@ class Note extends FlxSprite animation.play("scroll"); } - if (PlayState.instance != null) + if (PlayState.instance != null) { + PlayState.instance.splashHandler.getSplashGroup(splash); PlayState.instance.scripts.event("onPostNoteCreation", event); + } } public var lastScrollSpeed:Null = null; diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 9e63de6a..dd5b26fe 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -552,13 +552,8 @@ class PlayState extends MusicBeatState // PRECACHING #if REGION - for(content in Paths.getFolderContent('images/game/score/', true, true)) { - var graph = FlxG.bitmap.add(content); - if (graph != null) { - __cachedGraphics.push(graph); - graph.useCount++; - } - } + for(content in Paths.getFolderContent('images/game/score/', true, true)) + graphicCache.cache(content); for(i in 1...4) { FlxG.sound.load(Paths.sound('missnote' + Std.string(i))); diff --git a/source/funkin/game/SplashGroup.hx b/source/funkin/game/SplashGroup.hx index 32a4a63f..81c04b38 100644 --- a/source/funkin/game/SplashGroup.hx +++ b/source/funkin/game/SplashGroup.hx @@ -83,7 +83,7 @@ class SplashGroup extends FlxTypedGroup { } // immediatly draw once and put image in GPU to prevent freezes - splashSprite.draw(); + splashSprite.drawComplex(FlxG.camera); } catch(e) { Logs.trace('Couldn\'t parse splash data for "${path}": ${e.toString()}', ERROR); valid = false; diff --git a/source/funkin/system/GraphicCacheSprite.hx b/source/funkin/system/GraphicCacheSprite.hx new file mode 100644 index 00000000..b8d39f38 --- /dev/null +++ b/source/funkin/system/GraphicCacheSprite.hx @@ -0,0 +1,52 @@ +package funkin.system; + +import flixel.graphics.FlxGraphic; + +/** + * Dummy FlxSprite that allows you to cache FlxGraphics, and immediatly send them to GPU memory. + */ +class GraphicCacheSprite extends FlxSprite { + /** + * Array containing all of the graphics cached by this sprite. + */ + public var cachedGraphics:Array = []; + /** + * Array containing all of the non rendered (not sent to GPU) cached graphics. + */ + public var nonRenderedCachedGraphics:Array = []; + + public override function new() { + super(); + alpha = 0.001; + } + + /** + * Caches a graphic at specified path. + * @param path Path to the graphic. + */ + public function cache(path:String) { + var graphic = FlxG.bitmap.add(path); + if (graphic != null) { + // make their useCount one time higher to prevent them from auto being cleared from cache + graphic.useCount++; + cachedGraphics.push(graphic); + nonRenderedCachedGraphics.push(graphic); + } + } + + public override function destroy() { + for(g in cachedGraphics) + // make their usecount 1 time lower so that it can be cleared again + g.useCount--; + graphic = null; + super.destroy(); + } + + public override function draw() { + while (nonRenderedCachedGraphics.length > 0) { + trace("DRAWING GRAPHIC - ", nonRenderedCachedGraphics[0].key); + loadGraphic(nonRenderedCachedGraphics.shift()); + drawComplex(FlxG.camera); + } + } +} \ No newline at end of file diff --git a/source/funkin/system/MusicBeatState.hx b/source/funkin/system/MusicBeatState.hx index a5419388..cd968195 100644 --- a/source/funkin/system/MusicBeatState.hx +++ b/source/funkin/system/MusicBeatState.hx @@ -16,6 +16,10 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver private var lastBeat:Float = 0; private var lastStep:Float = 0; + /** + * Dummy sprite used to cache graphics to GPU. + */ + public var graphicCache:GraphicCacheSprite = new GraphicCacheSprite(); /** * Whenever the Conductor auto update should be enabled or not. */ @@ -219,12 +223,14 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver public override function destroy() { super.destroy(); + graphicCache.destroy(); call("onDestroy"); if (stateScript != null) stateScript.destroy(); } public override function draw() { + graphicCache.draw(); super.draw(); }