Skip to content

Commit

Permalink
Merge pull request #1097 from Gama11/cacheSounds
Browse files Browse the repository at this point in the history
FlxAssets.cacheSounds() -> FlxG.sound.cacheAll(), closes #1055
  • Loading branch information
gamedevsam committed May 17, 2014
2 parents fc2caa3 + 373eb84 commit 5252871
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
30 changes: 0 additions & 30 deletions flixel/system/FlxAssets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,6 @@ class FlxAssets
#end
return Assets.getSound(id + extension);
}

#if (!FLX_NO_SOUND_SYSTEM && !doc)
/**
* Calls FlxG.sound.cache() on all sounds that are embedded.
*/
@:access(openfl.Assets)
@:access(openfl.AssetType)
public static function cacheSounds():Void
{
Assets.initialize();

var defaultLibrary = Assets.libraries.get("default");

if (defaultLibrary == null)
return;

var types:Map<String, Dynamic> = DefaultAssetLibrary.type;

if (types == null)
return;

for (key in types.keys())
{
if (types.get(key) == AssetType.SOUND)
{
FlxG.sound.cache(key);
}
}
}
#end
#end
}

Expand Down
31 changes: 31 additions & 0 deletions flixel/system/frontEnds/SoundFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ class SoundFrontEnd
return Assets.getSound(EmbeddedSound, true);
}

#if !doc
/**
* Calls FlxG.sound.cache() on all sounds that are embedded.
* WARNING: can lead to high memory usage.
*/
@:access(openfl.Assets)
@:access(openfl.AssetType)
public function cacheAll():Void
{
Assets.initialize();

var defaultLibrary = Assets.libraries.get("default");

if (defaultLibrary == null)
return;

var types:Map<String, Dynamic> = DefaultAssetLibrary.type;

if (types == null)
return;

for (key in types.keys())
{
if (types.get(key) == AssetType.SOUND)
{
cache(key);
}
}
}
#end

/**
* Plays a sound from an embedded sound. Tries to recycle a cached sound first.
*
Expand Down

0 comments on commit 5252871

Please sign in to comment.