fixed splashes freeze + few other optimizations

This commit is contained in:
Yoshman29
2023-03-28 17:22:14 +02:00
parent 4ebd65a36d
commit f69c509c65
5 changed files with 64 additions and 9 deletions
+3 -1
View File
@@ -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<Float> = null;
+2 -7
View File
@@ -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)));
+1 -1
View File
@@ -83,7 +83,7 @@ class SplashGroup extends FlxTypedGroup<FunkinSprite> {
}
// 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;
@@ -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<FlxGraphic> = [];
/**
* Array containing all of the non rendered (not sent to GPU) cached graphics.
*/
public var nonRenderedCachedGraphics:Array<FlxGraphic> = [];
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);
}
}
}
+6
View File
@@ -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();
}