fixed memory optimisation

This commit is contained in:
Yoshman29
2022-12-10 12:56:52 +01:00
parent 963e36c274
commit ff7b638c4b
4 changed files with 32 additions and 2 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ class Flx3DView extends FlxSprite {
public static function init() {
__sprite = new Sprite();
FlxG.stage.addChild(__sprite);
FlxG.game.addChild(__sprite);
}
#end
+26
View File
@@ -68,6 +68,32 @@ class AssetsLibraryList extends AssetLibrary {
return null;
}
public function clearCache() {
var libs:Array<AssetLibrary> = [for(lib in libraries) lib];
libs.push(this);
for(l in libs) {
var lib:AssetLibrary = l;
if (lib is openfl.utils.AssetLibrary) {
var openflLib = cast(lib, openfl.utils.AssetLibrary);
@:privateAccess
if (openflLib.__proxy != null) lib = openflLib.__proxy;
}
@:privateAccess var cachedAudioBuffers = lib.cachedAudioBuffers;
@:privateAccess var cachedBytes = lib.cachedBytes;
@:privateAccess var cachedFonts = lib.cachedFonts;
@:privateAccess var cachedText = lib.cachedText;
for(buff in cachedAudioBuffers) buff.dispose();
cachedAudioBuffers.clear();
cachedBytes.clear();
cachedFonts.clear();
cachedText.clear();
}
}
public function new(?base:AssetLibrary) {
super();
if (base == null)
+4
View File
@@ -228,5 +228,9 @@ class Main extends Sprite
cache.removeFont(key);
for (key=>sound in cache.sound)
cache.removeSound(key);
Paths.assetsTree.clearCache();
}
}