diff --git a/src/flashcache/ImageCache.hx b/src/flashcache/ImageCache.hx index d05102d..2095350 100644 --- a/src/flashcache/ImageCache.hx +++ b/src/flashcache/ImageCache.hx @@ -1,6 +1,7 @@ package flashcache; import openfl.display.BitmapData; import flixel.graphics.FlxGraphic; +import openfl.display3D.textures.RectangleTexture; using StringTools; /* @@ -48,7 +49,7 @@ class ImageCache { * @param makeOnlyPathName determines whether or not the image key includes assetPath and the file extension. */ - public function cacheGraphic(path:String, ?makeOnlyPathName:Bool = false):FlxGraphic { + public function cacheGraphic(path:String, ?makeOnlyPathName:Bool = false, ?GPUCache:Bool = false):FlxGraphic { var data:BitmapData; var epicPath:String = assetPath + (assetPath == "" ? "" : "/") + path + '.' + extension; @@ -56,12 +57,21 @@ class ImageCache { return null; // prevents duplicates } - try (data = BitmapData.fromFile(epicPath)) - catch(e) { - trace("Error loading image: " + path); + try (data = BitmapData.fromFile(epicPath)) + catch(e) { + trace("Error loading image: " + path); return null; - } - + } + + if (data != null && GPUCache){ + var texture:RectangleTexture = FlxG.stage.context3D.createRectangleTexture(data.width, data.height, BGRA, true); + texture.uploadFromBitmapData(data); + data.image.data = null; + data.dispose(); + data.disposeImage(); + data = BitmapData.fromTexture(texture); + + } var graphic:FlxGraphic = FlxGraphic.fromBitmapData(data); graphic.persist = true; graphic.destroyOnNoUse = false; diff --git a/src/flashcache/SoundCache.hx b/src/flashcache/SoundCache.hx index 9dd3cfd..c9e141b 100644 --- a/src/flashcache/SoundCache.hx +++ b/src/flashcache/SoundCache.hx @@ -3,6 +3,8 @@ package flashcache; import openfl.Assets; import openfl.media.Sound; import openfl.utils.AssetType; +import lime.media.vorbis.VorbisFile; +import lime.media.AudioBuffer; /* DO NOT USE THIS IT'S STUPID @@ -12,9 +14,15 @@ import openfl.utils.AssetType; */ class SoundCache { public function new() {} - public function cacheSound(path:String):Sound { + public function cacheSound(path:String, ?stream:Bool = false):Sound { if (Assets.exists(path, AssetType.SOUND) || Assets.exists(path, AssetType.MUSIC)) - return Assets.getSound(path, true); + var sound:Sound = null; + #if lime_vorbis + if (stream) + return sound = Sound.fromAudioBuffer(AudioBuffer.fromVorbisFile(VorbisFile.fromFile(path)); + else + #end + return sound = Assets.getSound(path, true); trace('Sound not found at ' + path); return null; } @@ -23,4 +31,4 @@ class SoundCache { cacheSound(i); } } -} \ No newline at end of file +} diff --git a/src/flashcache/TypedCache.hx b/src/flashcache/TypedCache.hx index 36981e4..3f2d0ef 100644 --- a/src/flashcache/TypedCache.hx +++ b/src/flashcache/TypedCache.hx @@ -87,7 +87,8 @@ class TypedCache { for (p in 0...keys.length) { - uncacheFunction(cache.get(keys[p])); + if (uncacheFunction != null) + uncacheFunction(cache.get(keys[p])); cache.exists(keys[p]) ? cache.remove(keys[p]) : null; } } @@ -100,7 +101,8 @@ class TypedCache public inline function uncacheAll(uncacheFunction:T->Void) { for (item in cache) - uncacheFunction(item); + if (uncacheFunction != null) + uncacheFunction(item); cache.clear(); }