Created
January 19, 2016 08:25
-
-
Save triplefox/51a34a1223059b68b181 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AssetCacheData { | |
public var anim_aset : LifeVector<AnimationAsset>; | |
public var anim_inst : LifeVector<AnimationRenderable>; | |
public var hscript : Map<String, HScriptModule>; | |
public var blob : Map<String, Blob>; | |
public var image : Map<String, Image>; | |
public var sound : Map<String, Sound>; | |
public var font : Map<String, Font>; | |
public var video : Map<String, Video>; | |
public function new() { | |
resetCache(); | |
} | |
public function resetCache() { | |
blob = new Map(); | |
image = new Map(); | |
sound = new Map(); | |
font = new Map(); | |
video = new Map(); | |
anim_aset = new LifeVector("anim_aset",new Vector(128)); | |
anim_inst = new LifeVector("anim_inst", new Vector(128)); | |
hscript = new Map(); | |
} | |
} | |
class AssetCache { | |
public var static_cache : AssetCacheData; | |
public var dynamic_cache : AssetCacheData; | |
public function new() { | |
resetCache(); | |
} | |
public function getBlob(k : String) { | |
if (dynamic_cache.blob.exists(k)) { | |
return dynamic_cache.blob.get(k); | |
} else if (static_cache.blob.exists(k)) { | |
return static_cache.blob.get(k); | |
} else { | |
var f = (Reflect.field(Assets.blob, k + "Load")) | |
if (f != null) { | |
static_cache.blob.set(k, f()); | |
} | |
else { | |
return null; | |
} | |
} | |
} | |
public function resetCache() { | |
static_cache = new AssetCacheData(); | |
dynamic_cache = new AssetCacheData(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment