|
@@ -3,52 +3,54 @@ package hxd.res;
|
|
|
class Loader {
|
|
|
|
|
|
var fs : FileSystem;
|
|
|
+ var modelCache : Map<String,Model>;
|
|
|
+ var textureCache : Map<String,Texture>;
|
|
|
+ var soundCache : Map<String,Sound>;
|
|
|
|
|
|
public function new(fs) {
|
|
|
this.fs = fs;
|
|
|
+ modelCache = new Map();
|
|
|
+ textureCache = new Map();
|
|
|
+ soundCache = new Map();
|
|
|
}
|
|
|
|
|
|
public function exists( path : String ) : Bool {
|
|
|
return fs.exists(path);
|
|
|
}
|
|
|
|
|
|
- function resolveDynamic( path : String ) : Dynamic {
|
|
|
- var extParts = path.split(".");
|
|
|
- extParts.shift();
|
|
|
- var ext = extParts.join(".").toLowerCase();
|
|
|
- switch( ext ) {
|
|
|
- case "fbx", "xbx": return loadModel(path);
|
|
|
- case "png", "jpg": return loadTexture(path);
|
|
|
- case "ttf": return loadFont(path);
|
|
|
- case "wav", "mp3": return loadSound(path);
|
|
|
- case "":
|
|
|
- var f = fs.get(path);
|
|
|
- if( f.isDirectory )
|
|
|
- return new Directory(f);
|
|
|
- default:
|
|
|
- };
|
|
|
- throw "Unknown extension " + ext;
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
public function load( path : String ) : Any {
|
|
|
- return new Any(fs.get(path));
|
|
|
+ return new Any(this, fs.get(path));
|
|
|
}
|
|
|
|
|
|
function loadModel( path : String ) : Model {
|
|
|
- return new Model(fs.get(path));
|
|
|
+ var m = modelCache.get(path);
|
|
|
+ if( m == null ) {
|
|
|
+ m = new Model(fs.get(path));
|
|
|
+ modelCache.set(path, m);
|
|
|
+ }
|
|
|
+ return m;
|
|
|
}
|
|
|
|
|
|
function loadTexture( path : String ) : Texture {
|
|
|
- return new Texture(fs.get(path));
|
|
|
+ var t = textureCache.get(path);
|
|
|
+ if( t == null ) {
|
|
|
+ t = new Texture(fs.get(path));
|
|
|
+ textureCache.set(path, t);
|
|
|
+ }
|
|
|
+ return t;
|
|
|
}
|
|
|
|
|
|
+ function loadSound( path : String ) : Sound {
|
|
|
+ var s = soundCache.get(path);
|
|
|
+ if( s == null ) {
|
|
|
+ s = new Sound(fs.get(path));
|
|
|
+ soundCache.set(path, s);
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
function loadFont( path : String ) : Font {
|
|
|
return new Font(fs.get(path));
|
|
|
}
|
|
|
|
|
|
- function loadSound( path : String ) : Sound {
|
|
|
- return new Sound(fs.get(path));
|
|
|
- }
|
|
|
-
|
|
|
}
|